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: Response header(Fix #770) #857
Conversation
Add SuccessResponse & Response decorator's overloading. Add headers field in tsoa#Response interface. Add Header type in swagger for both OA2.0 & 3.0.
Add statements to support headers field. Add controller for tests and test cases.
@WoH I've done the support for TsoaResponse, |
Add missing common response header with header object instead of header class. Edit some HeaderClass's description more readable. Replace all exsitence examine with content examine in test cases.
Add optional field in all header class / object at test controllers. FIx incorrect statement with undefined result at schemaDetail#L197 & shcmeaDetail3#L444. Add field exsitence examine at OAI2.0 & required field in OAI3.0.
Add else statement to throw error with invalid header type. Add incorrect response header controller for test cases. Add test case in both OAI2.0 & 3.0.
Remove optional overrloading for SuccessResponse & Response type. Edit SuccessResponse & Response type's generic type more readable.
02ad51a
to
a57a4d7
Compare
3 more general thoughts:
|
@jackey8616 I'd love to add some commits that address some of the things I laid out myself if you don't mind. Would you like to give me commit access to the PR or should I send you diffs? |
@WoH I turned it on! |
Remaining TODOs:
|
This ensures we never try to generate a spec based on invalid metadata. This enables us to point out the issue more precisely and link the offending node.
0aa3162
to
edafcc0
Compare
IMHO, header must be used along with a response in swagger, thus, they should be good if we let it be optional parameter at Since |
I don't think I can follow. Can you give me an example? |
If we want to let success status code to be 204, @SuccessResponse(204, 'some descriptions doesn\'t want be omit.')
@SuccessHeader<HeaderClass>(204, {
linkA: 'http://google.com',
})
public async handler(): Promise<void> {
return;
} |
But do we? What's the problem with @SuccessResponse(204, 'some descriptions doesn\'t want be omit.')
@SuccessHeader<Header>({
linkA: 'http://google.com',
})
public async handler(): Promise<void> {
return;
} |
I think its no problem expect it runs different logic compares with SuccessResponse, which requires pre-check exists response defined by it, further more, it also effect by existence of SuccessResponse decorator, which may cause complex logic of SuccessHeader IMHO. I've surveyed #723, and I don't see any actual reason to introduce SuccessHeader. |
I hope I get where you're coming from now. For this PR, the goal is only to document the headers on the default / success response. Admittedly, you can do that both with the API you implemented and I'm looking specifically at this: @SuccessHeader<Header>({
linkA: 'http://google.com',
})
public async handler(): Promise<void> {
return;
} Here, @SuccessResponse<Header>(undefined, undefined, {
linkA: 'http://google.com',
})
public async handler(): Promise<void> {
return;
} However, we can obviously do type/arg checks so we can do: @SuccessResponse<Header>({
linkA: 'http://google.com',
})
public async handler(): Promise<void> {
return;
} So it seems to come down to preference. For my personal taste setting the headers as a separate annotation feels more intuitive, but if I can't really point a finger as to why, your approach is probably equally fine. |
Should the solution for success headers generalise to headers with dynamic values? |
2f6c7ce
to
9637443
Compare
9637443
to
b4c261e
Compare
@jackey8616 I rebased and this lgtm now. Can you take a look and confirm? |
You'd still have to set them using |
All Submissions:
Closing issues
Closes #770 .
If this is a new feature submission:
Potential Problems With The Approach
This RP introduce
SuccessResponse
andResponse
decorator with a generic type to define header struture.SuccessResponse
wasn't follow with any generic type, so in this PR, is not a big deal.but
Response
is already provide a generic type T which specify the example structure,usage of
Response
before this PR is@Response<ExampleClass>
:In some situation like
need header class but not example class
, the decorator define will be@Response<null, HeaderClass>
.Test plan
Test spec is coming out at path.[status code].headers field.