Skip to content
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

feat: Add basic support for parameter properties #2687

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

devoto13
Copy link
Contributor

@devoto13 devoto13 commented Nov 2, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • 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?

Parameter properties are not supported.

Issue Number: #2056

What is the new behavior?

Basic support for parameter properties is added.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

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 - feat: support validating parameter properties and TypeScript constructor shorthands 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

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
@kamilmysliwiec kamilmysliwiec merged commit 91d2035 into nestjs:master Jan 15, 2024
1 check passed
@kamilmysliwiec
Copy link
Member

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants