Adding endpoint documentation from 'programmatic usage' in plumber

I am switching my APIs to a more organized and scalable structure and I'd like to change some annotated endpoints to a "programmatic usage" in order to use routes.

How can I add the same endpoint documentation via pr that I would via annotations? Is there a way to add it manually in the endpoints function and somehow "generate" a swagger file in the end?

Just for clarity, what I want is to transform this:

#* Say hello
#* @get /hello
#* @param name Name
#* @tag silly
function(name){
  paste("Hello", name)
}

Into something like (with annotations):

pr$handle("GET", "/hello", function(req, res, name) {
  ....
})

Thanks!

PS: As a bonus, how can I add the global API documentation when using pr?

#* @apiTitle My API
#* @apiVersion 0.0.1
#* @apiDescription No Description

There is a lot of work going on right now that will solve these situations...

Check out:

This version of plumber has not been released as of writing this comment.

1 Like

Thanks @barret! I saw some issues regarding documentation in general on GH and it will be very helpful! :slight_smile:

1 Like

From: Rename Swagger to OpenAPI Specification by meztez · Pull Request #560 · rstudio/plumber · GitHub

pr$apiSpec()

This can then be saved to a JSON or YAML file.

1 Like

Yes! I hope we can properly tackle Document plumber decoration syntax / programmatic syntax · Issue #572 · rstudio/plumber · GitHub

Issue made:

For everything endpoint you can use the ... to alter the behavior of PlumberEndpoint$new when you call pr$handle. In your case it would probably be params, comments, responses and tags.

As @barret said, this needs more documentation and examples.

PlumberEndpoint$new(
  verbs,
  path,
  expr,
  envir,
  serializer,
  lines,
  params,
  comments,
  responses,
  tags
)
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.