swagger icon indicating copy to clipboard operation
swagger copied to clipboard

[discussion]: add decorator for setting the description for a schema

Open gerriet opened this issue 2 years ago • 4 comments

Is there an existing issue that is already proposing this?

  • [X] I have searched the existing issues

Is your feature request related to a problem? Please describe it

OpenAPI allows a description not only for single properties but also for a complete schema. This can be optionally validated via no_schema_description in OpenAPI validator. Currently I see no way to set this description via a decorator.

Describe the solution you'd like

In correspondence with (PR 983)[https://github.com/nestjs/swagger/pull/983], where ApiSchema would be used with property name, this could work with a decorator named ApiSchema and a property named description, e.g.

@ApiSchema({ description: "Describing my schema" })
class MyDto {}

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

Richer OpenAPI documentation with descriptions for schemata

gerriet avatar Oct 08 '21 09:10 gerriet

Would you like to create a PR to #983 with this feature?

kamilmysliwiec avatar Oct 08 '21 12:10 kamilmysliwiec

Yes, I would. How should I go about it? Wait for #983 to be merged? Copy the current PR changes into a new PR that covers both name and description?

gerriet avatar Oct 08 '21 12:10 gerriet

Use #983 as a base branch and create a PR to that branch

kamilmysliwiec avatar Oct 18 '21 10:10 kamilmysliwiec

Could the "title" be included as well ?

raplemie avatar Nov 01 '21 17:11 raplemie

The related PR has actually been locked for one year, anything new about it ?

corentinguilloux avatar Nov 02 '22 16:11 corentinguilloux

Any news? Using this library I cannot get the API to pass the internal linting requirements of my client.

gwesterman avatar Dec 09 '22 05:12 gwesterman

As a workaround you can do this:

class Example {
}

export { Example as ExampleDto }

This will leave your code the same but will cause the schemas to be with a different name

SBD580 avatar Jan 03 '23 09:01 SBD580

Just want to chime in here -- I cherry-picked the original author's commits into a new PR (#2427), happy to take ownership of any requested changes to the OG PR, I could really use this feature 😅

mothershipper avatar May 12 '23 22:05 mothershipper

Let's track this here https://github.com/nestjs/swagger/pull/2427

kamilmysliwiec avatar May 15 '23 08:05 kamilmysliwiec