-
Notifications
You must be signed in to change notification settings - Fork 506
feat(@ApiExtension): When used on a controller it applies to all methods #3485
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
base: master
Are you sure you want to change the base?
Conversation
Docs are a separate repo right? I'm happy to update those if this looks like something that will accepted. |
2ab32e8
to
a906676
Compare
a906676
to
218c820
Compare
"x-schema-extension": { | ||
"test": "test" | ||
}, | ||
"x-schema-extension-multiple": { | ||
"test": "test*2" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order of these extensions changed but I modified the values to make it clear they aren't affected.
.map((propertyKey) => | ||
Object.getOwnPropertyDescriptor(target.prototype, propertyKey) | ||
) | ||
.filter((methodDescriptor) => methodDescriptor !== undefined) | ||
.filter((methodDescriptor) => | ||
Reflect.hasMetadata(METHOD_METADATA, methodDescriptor.value) | ||
) | ||
.map((methodDescriptor) => methodDescriptor.value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking back at this i'm realizing we could consolidate this down a bit.
.map((propertyKey) => | |
Object.getOwnPropertyDescriptor(target.prototype, propertyKey) | |
) | |
.filter((methodDescriptor) => methodDescriptor !== undefined) | |
.filter((methodDescriptor) => | |
Reflect.hasMetadata(METHOD_METADATA, methodDescriptor.value) | |
) | |
.map((methodDescriptor) => methodDescriptor.value); | |
.map((propertyKey) => | |
Object.getOwnPropertyDescriptor(target.prototype, propertyKey)?.value | |
) | |
.filter((methodDescriptor) => | |
methodDescriptor !== undefined && Reflect.hasMetadata(METHOD_METADATA, methodDescriptor) | |
); |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
If you try to use the
@ApiExtension()
decorator at the controller level it has no effect on the OpenAPI file. It only has an effect on methods.So using it at the controller level like this would have no effect on the create operation.
Issue Number: N/A
What is the new behavior?
Now when
@ApiParam()
decorator is used on a controller the extension property is added to all the operations implemented by the controller.The above example would apply the extension to the operation:
If you apply the same extension decorator at the method level it will override the controller level value. I spent a little time trying to merge the values but it added quite a bit of complexity and seemed like It could give some surprising results.
Does this PR introduce a breaking change?
Other information