-
Notifications
You must be signed in to change notification settings - Fork 508
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(spec): allow defining custom media type of responses + fix(koa): dont overwrite content-type of response #1129
Conversation
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.
Hello there mrl5 👋
Thank you and congrats 🎉 for opening your first PR on this project.✨
We will review the following PR soon! 👀
@mrl5 very nice PR! In case that TSOA will support @Get('process')
@Consumes('image/png') // Consumes MediaType
@MediaType('text/plain') // Produces MediaType
public async processImage(@Request() request: ExRequest): Promise<string> {
// code
return '';
} Instead of this @Get('process')
@Consumes('image/png') // Consumes MediaType
@Produces('text/plain') // Produces MediaType
public async processImage(@Request() request: ExRequest): Promise<string> {
// code
return '';
} |
thanks for code review @dderevjanik - I agree that
I was inspired by the code snippets from #968 @WoH is it ok to |
Amending and rebasing is fine |
|
pushed additional commit that:
|
definitions: this.buildDefinitions(), | ||
info: { | ||
title: '', | ||
}, | ||
paths: this.buildPaths(), | ||
produces: ['application/json'], | ||
produces: [DEFAULT_RESPONSE_MEDIA_TYPE], // todo: Tsoa.Response.produces |
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.
A list of MIME types the APIs can produce.
This is global to all APIs but can be overridden on specific API calls.
Value MUST be as described under Mime Types.
Maybe I'm interpreting too much, but we should be able to leave this as is, remove the todo and override on path.method.produces?
problem description: currently `application/json` is hardcoded into generated spec proposed solution: allow specifying custom media type in generated spec on both controller level by: - using new `@Produces` decorator and on method level by: - using new `@Produces` decorator - introducing new optional arg for `@SuccessResponse` decorator - introducing new optional arg for `@Response` decorator - setting `Content-Type` header in `@Res` decorator impact: - cli: controller generator - cli: method generator - cli: parameter generator - cli: spec2 generator - cli: spec3 generator - runtime: response decorators Closes #1126 Related #968
problem description: as described in koajs/koa#1120 currently `koa` always overwrites `Content-Type` for JSON responses. proposed solution: workaround discovered by @brunoabreu is to set headers after setting the body. Closes #1134 Related #1129
thanks @WoH for detailed CR :) I hope we're good to go now |
suggested by @WoH during code review Co-authored-by: Wolfgang Hobmaier <[email protected]>
Thanks for this PR and your patience during the review, much appreciated. Great Work! |
Please, @mrl5 and @WoH, is this working in version 4.0.0-alpha.2? I'm adding the decorator: Should I do any additional thing to see "text/event-stream" in the generate openapi? Thanks and best regards!! |
hi @alberto-rubio - I think that this changes are already included in this version. It's hard to help you w/o seeing any example code that is producing unexpected results if you need example you can study this file that is used in unit tests to ensure that feature introduced in this PR works: tsoa/tests/fixtures/controllers/mediaTypeController.ts Lines 27 to 29 in 6a289a7
|
problem description: currently
application/json
is hardcoded into generated specproposed solution: allow specifying custom media type in generated spec
on both controller level by:
@Produces
decoratorand on method level by:
@Produces
decorator@SuccessResponse
decorator@Response
decoratorContent-Type
header in@Res
decoratorimpact:
Closes #1126
Related #968
All Submissions:
Closing issues
closes #XXXX
(where XXXX is the issue number) in your comment to auto-close the issue that your PR fixes.If this is a new feature submission:
Potential Problems With The Approach
content-type
of actual response (which is not a case). However I don't think it's a problem -> if you check the issues from the past you will see that writing custom methods was encouraged - for example Send file / return raw binary "application/octect-stream" or "image/jpeg" ... #44 Return HTML from controller #224I wasn't able to introduce new arg for setting custom media type for@Res
decoratorTest plan
@Produces
on controller level@Produces
is set on controller level it is possible to set it also for specific method@Response
and@SuccessResponse
decorators@Res
decorator