-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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: adds @oas.response decorator #4550
feat: adds @oas.response decorator #4550
Conversation
Note: I'd love to figure out some way to use these decorators as response code hints in the future, but I'm not entirely sure how to go about doing that in a way that fits the current patterns. e.g.
If the invoked method returns or throws |
@mschnee Can you rebase your PR against latest master branch with |
a3c1284
to
9651fe2
Compare
Rebased from upstream and squashed! |
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.
I love the user experience of the proposed API 👍
I'll leave the detailed review and approval to @raymondfeng.
c72441a
to
f34a97e
Compare
f34a97e
to
9d38188
Compare
9d38188
to
22eb691
Compare
22eb691
to
bdf5d59
Compare
@@ -20,6 +20,7 @@ | |||
"@loopback/repository": "^1.19.1", | |||
"@loopback/testlab": "^1.10.3", | |||
"@types/debug": "^4.1.5", | |||
"@types/http-status": "^1.1.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.
I don't see http-status
as a dev dependency.
} | ||
|
||
const successSchema: ResponseObject = { | ||
description: httpStatus['200'], |
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.
This should require http-status
to be a dev dependency. The build is passing because the module is transitively added as follows:
rest
└─┬ [email protected]
└── [email protected]
responseCode: number, | ||
...responseModelOrSpec: ResponseModelOrSpec[] | ||
) { | ||
const messageKey = String(responseCode) as keyof httpStatus.HttpStatus; |
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.
This makes http-status
a regular dependency (instead of dev). Please add it to package.json.
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
import {MethodMultiDecoratorFactory} from '@loopback/core'; | ||
import * as httpStatus from 'http-status'; |
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.
It should be import httpStatus from 'http-status'
now.
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.
I'll make these changes today
88c6492
to
84d2827
Compare
Partially implements: #4300
See: #4406
Adds
This PR adds the
@oas.response(code: number, ...modelOrSpec: ModelOrSpec[])
decorator.Note
The decorator only affects the OpenAPI specification object that is created, and anything that uses it to verify and validate responses. This decorator has no impact on the actual response code. It also doesn't add any typings or lint configuration that could force response compliance at compile/lint time (if that's even possible).
Example
Checklist
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated