feathersjs-ecosystem / feathers-swagger

Add documentation to your FeatherJS services and feed them to Swagger UI.
MIT License
226 stars 63 forks source link

Different response / request for each method #221

Closed RickEyre closed 3 years ago

RickEyre commented 3 years ago

Is there an easy way / recommended way for modifying the request / response schemas for each method in a service? Out of the box it seems to support only two definitions - singular and array.

Mairu commented 3 years ago

Hi, there are many approaches, the simplest would be to use the refs option of a service(.docs) to set refs for the different request and responses (check the readme for the available options) that you could have defined in the schemas/definitions section before.

https://github.com/feathersjs-ecosystem/feathers-swagger/blob/6dff498d35d0e8d1c2dc7187efa78fa94ecfbc7c/types/index.d.ts#L25-L41

In this example the sortParameter (which is currently missing from the docs and types) is set, https://github.com/feathersjs-ecosystem/feathers-swagger/blob/179fa50856c785e9984ae02847bae3d083fc3ca0/example/openapi-v3/multi.js

Alternatively you could directly set the schema (or ref) of a specific method using the property path setting functionality like here: https://github.com/feathersjs-ecosystem/feathers-swagger/blob/179fa50856c785e9984ae02847bae3d083fc3ca0/example/openapi-v3/definitions.js#L44-L54

For a get response that would be

operations: {
   get: {
      'responses.200.content.application/json.schema': {
        type: 'object',
        properties: { ... }
      }
   }
}

For more complex cases you have to know how the target openapi specification should look like.

RickEyre commented 3 years ago

Awesome, thank you!