swagger icon indicating copy to clipboard operation
swagger copied to clipboard

Add decorator to allow specification of the schema type name

Open radacovsky opened this issue 5 years ago • 11 comments

You can use @ApiSchema to set a custom schema name. Custom schema names are not inherited.

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://github.com/nestjs/nest/blob/master/CONTRIBUTING.md
  • [x] Tests for the changes have been added (for bug fixes / features)
  • [x] Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Currently when creating schema for a class the class name is taken as the schema name.

Issue Number: N/A

What is the new behavior?

A new decorator has been introduced: @ApiSchema. Using this decorator you can define custom schema name different from the class name.

e.g. @ApiSchema({name: 'User'}) class UserDto {}

will produce a schema with name User, not UserDto.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

radacovsky avatar Oct 02 '20 22:10 radacovsky

Thanks! Could you create a PR to the docs as well? https://github.com/nestjs/docs.nestjs.com

kamilmysliwiec avatar Nov 06 '20 10:11 kamilmysliwiec

Ok, will do!

radacovsky avatar Nov 06 '20 10:11 radacovsky

@kamilmysliwiec here is the PR for documentation update https://github.com/nestjs/docs.nestjs.com/pull/1533

radacovsky avatar Nov 06 '20 12:11 radacovsky

@nartc I haven't noticed any question there. Can you link it here, please?

radacovsky avatar Nov 06 '20 14:11 radacovsky

When do you plan to merge and release it ?

andrew-itscript avatar Feb 27 '21 14:02 andrew-itscript

I can't wait for merge and release it!

anchan828 avatar Apr 19 '21 07:04 anchan828

This PR is very helpful. When you guys are plan to merge and release it?

Dhiraj-JC avatar May 19 '21 06:05 Dhiraj-JC

Can we release this soon please? It's been ready for quite a while now. There are other useful features that can be built on top of the ApiSchema decorator once this is merged (documentation at the type level).

zroadhouse-rigup avatar Jun 02 '21 13:06 zroadhouse-rigup

It looks like this branch has merge conflicts - is this all that remains to be fixed? I'm willing to assist to help get this merged.

adworacz avatar Oct 26 '21 22:10 adworacz

@adworacz I doubt the maintainer of this project wants to merge this PR/functionality. If he wanted he would have merged it when it was all green.

radacovsky avatar Oct 27 '21 22:10 radacovsky

Ignore merge conflicts, I'll resolve them when I get to this PR.

kamilmysliwiec avatar Oct 28 '21 06:10 kamilmysliwiec

https://github.com/nestjs/swagger/pull/2427

kamilmysliwiec avatar May 15 '23 08:05 kamilmysliwiec