-
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
Sugar response
decorators for easier controller config
#1672
Comments
response
decorators for easier controller config
Can we perhaps use status names from |
For sure! I think the only thing would be that I would be is should the response name be capitalized as that is how it is in |
It can be as simple as For example:
|
That certainly works ... I think we can go further and just let the user pass in the type directly instead of wrapping it in an Object with the |
Yes please! We can always add support for arbitrary schema later, because it's easy to distinguish between as schema object (
How about the following: @response.json(200, Customer);
// later we can add
@response.xml(200, Customer);
@response.custom('application/custom-type', 200, Customer);
In the future, we may want to allow users to pass arbitrary extra properties besides |
Another option I was pondering recently was to use a Builder pattern. @response(200).json().model(Customer).description('lorem ipsum')
@response(404).contentType('application/custom-type').schema(MySchema) I think this can be particularly useful for parameter decorators, where we already have M times N functions, where M is the number of The builder pattern has two challenges:
|
I find the style |
I like the
|
I love that form ☝️
Maybe put the code first and the content-type second? That's how the information is mapped in the spec IIRC and send down the TCP/IP socket in the HTTP response. @response(200, 'application/custom-type', 'description', Customer) |
That makes sense to me. +1 for the the |
|
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the |
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the |
I think this has been (partially?) implemented by #4550 Example @model()
class SuccessModel extends Model {
constructor(err: Partial<SuccessModel>) {
super(err);
}
@property({default: 'Hi there!'})
message: string;
}
class FooNotFound extends Model {
@property()
message: string;
}
class BarNotFound extends Model {
@property()
message: string;
}
class BazNotFound extends Model {
@property()
message: string;
}
class MyController {
@oas.get('/greet/{foo}/{bar}',
@oas.response(200, SuccessModel)
@oas.response(404, FooNotFound, BarNotFound)
@oas.response(404, BazNotFound)
greet() {
return new SuccessModel({message: 'Hello, world!'});
}
} |
Description / Steps to reproduce / Feature proposal
Currently an OpenAPI
response
can only be set by providing the complete controller spec OR by passing it in theoperation
decorator. Describing a spec is very tedious and time consuming and we should provide an easier way to automagically assemble the spec.Proposed Design
A few alternatives for the decorator:
Acceptance Criteria
The text was updated successfully, but these errors were encountered: