rstudio / plumber

Turn your R code into a web API.
https://www.rplumber.io
Other
1.4k stars 258 forks source link

Schema Definitions #819

Open kempspo opened 3 years ago

kempspo commented 3 years ago

Would be useful to be able to define the schema of our objects, like so. Found it particularly hard to communicate POST body request formats without having to talk to other devs directly and figure out how it was built.

Definitely doable by manually appending to the API spec via pr_set_api_spec, but having function to abstract this away from people would be great.

components:
  schemas:
    User:
      type: object
      properties:
        id:
          type: integer
        name:
          type: string
meztez commented 3 years ago

yes it would be great.

@kempspo What kind of abstraction would make sense to you? Do you have an interface example you would prefer?

kempspo commented 3 years ago

To be honest, I don't have a specific opinion on how it should go, but I would think maybe some function like pr_add_schema that takes a Plumber API object, a name and a list that holds the schema object definition (I honestly don't know how to make this simpler for people to use).

I think a way to refer to the schema from the pr_handle set of functions would also be helpful?

requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Pet'