feathersjs-ecosystem / feathers-swagger

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

remove field from specific operation call #161

Closed bwgjoseph closed 5 years ago

bwgjoseph commented 5 years ago

Hi,

I am wondering if it is possible to override the default schema generation, and at the service.docs remove certain fields to display in the example portion?

My schema is as such.

image

And the example in POST ops will be as such.

image

I would like to remove _id, createdAt, updatedAt, and _v from the example as those are values generated by database. If it is showing there, user may be mistaken that those values are required to be submitted during the POST ops.

So it would be as such.

image

Thanks.


Also wondering if it is a common practice to expose all these fields at all? Assuming that all these are for internal consumption only. So that it only show as such.

image

Mairu commented 5 years ago

What fields you want to be shown on the page is completely up to you. You define the schema.

You can define as many different schemas as you want. And use the different schemas for the different methods. You can specify that in the refs option of the service.

bwgjoseph commented 5 years ago

Thanks, refs was the key to it.

I was initially thinking if I could just define somewhere to exclude some fields. But looks like defining another definitions and passing to refs is the way to go.

Mairu commented 5 years ago

As a side note if you need an object only once you don't have to create a reference for it but could directly define it in docs.operations wherever you need it.

bwgjoseph commented 5 years ago

Sorry, I don't quite get it. Any simple example to go along with it?

Thanks.

Mairu commented 5 years ago

Nothing special, I just meant you could set the request/response etc. directly in the operations option of the service without using references.

e.g.

service.docs = {
   operations: {
     create: {
       'requestBody.content': {
         type: 'object',
         properties: { ... }
       }
     }
   }
}
bwgjoseph commented 5 years ago

I was trying that initially, but couldn't quite get it format right.

So it was in requestBody.content.

Thanks for the tip!