-
Notifications
You must be signed in to change notification settings - Fork 474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properties declared throught "constructor shorthand" do not appear in Swagger UI #2056
Closed
2 of 4 tasks
Labels
Comments
This happens with extending classes as well:
This produces the same result as above even though the generics are passed in and Entity is a class, not a interface.
|
Same on Windows and Ubuntu. export class Product {
id: string;
name: string;
constructor(
id: string,
name: string,
) {
this.id = id;
this.name = name;
}
} Desired export class Product {
constructor(
public id: string,
public name: string,
) { }
} Replacing |
devoto13
added a commit
to devoto13/swagger
that referenced
this issue
Nov 2, 2023
The feature is controlled by the `parameterProperties` option, which is disabled by default. As the feature is opt-in, it should be possible to release it as a minor version. Worth noting, that using parameter properties has some limitations compared to the regular properties, but it can still be useful for some basic scenarios. 1. Can't use validation annotations as it is not supported by the class-validator - typestack/class-validator#1669. 2. Can't use JSDoc tags, e.g. `@example` or `@deprecated`. Parsing description from the comment is not implemented in this PR, but can potentially be added from the `@param` JSDoc tag. 3. Can't use `@ApiProperty` and `@ApiHideProperty` decorators. This can be supported by introducing a dedicated decorators which works on parameters, e.g. `@ApiParameterProperty` and `@ApiHideParameterProperty()` with the same signatures. It shouldn't be hard to add, but just wanted to hear if you're interested in adding this feature and collect feedback before I put more work into it. Features which are supported and work the same way as for regular properties: 1. `required` and `nullable` 2. `type` 3. `enum` 4. `default` Fixes nestjs#2056
devoto13
added a commit
to devoto13/swagger
that referenced
this issue
Nov 2, 2023
The feature is controlled by the `parameterProperties` option, which is disabled by default. As the feature is opt-in, it should be possible to release it as a minor version. Worth noting, that using parameter properties has some limitations compared to the regular properties, but it can still be useful for some basic scenarios. 1. Can't use validation annotations as it is not supported by the class-validator - typestack/class-validator#1669. 2. Can't use JSDoc tags, e.g. `@example` or `@deprecated`. Parsing description from the comment is not implemented in this PR, but can potentially be added from the `@param` JSDoc tag. 3. Can't use `@ApiProperty` and `@ApiHideProperty` decorators. This can be supported by introducing a dedicated decorators which works on parameters, e.g. `@ApiParameterProperty` and `@ApiHideParameterProperty()` with the same signatures. It shouldn't be hard to add, but just wanted to hear if you're interested in adding this feature and collect feedback before I put more work into it. Features which are supported and work the same way as for regular properties: 1. `required` and `nullable` 2. `type` 3. `enum` 4. `default` Fixes nestjs#2056
12 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there an existing issue for this?
Current behavior
When using the
@nestjs/swagger
plugin, with classes that use "constructor shorthand" (i.e. properties declared inline with the constructor cf https://dev.to/satansdeer/typescript-constructor-shorthand-3ibd ), in the generated OpenAPI doc, properties declared in constructor are missing.Minimum reproduction code
https://github.com/tsimbalar/nest-constructor-shorthand-repro
Steps to reproduce
npm install
npm run start:dev
open http://localhost:3000/api
Expected behavior
Under the
/example/shorthand
endpoint, the example value should contain a propertyitems
, like for the/example
endpoint.i.e. currently
shorthand
looks like this :but we expect it to look like this (the one without shorthand behaves ok):
Package version
6.1.0
NestJS version
9.0.0 (but also happened with 8)
Node.js version
16.13.0
In which operating systems have you tested?
Other
No response
The text was updated successfully, but these errors were encountered: