-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
typescript-node: Add options to specify a form data file #3967
Conversation
*/ | ||
public async addPet (body: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { | ||
public async addPet (pet: Pet, options: {headers: {[name: string]: string}} = {headers: {}}) : Promise<{ response: http.ClientResponse; body?: any; }> { |
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.
please run the bin/typescript-node-petstore-all.sh script only, not the openapi3
version
@@ -70,13 +71,13 @@ public String getHelp() { | |||
|
|||
@Override | |||
public boolean isDataTypeFile(final String dataType) { | |||
return "Buffer".equals(dataType); | |||
return dataType != null && (dataType.equals("Buffer") || dataType.equals("FormDataFile")); |
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 guess dataType
should be split by |
, right?
thanks for the PR |
@@ -15,5 +15,14 @@ export class HttpError extends Error { | |||
this.name = 'HttpError'; | |||
} | |||
} | |||
|
|||
export interface FormDataFile { |
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.
} | ||
|
||
@Override | ||
public String getTypeDeclaration(Schema p) { | ||
if (ModelUtils.isFileSchema(p)) { | ||
return "Buffer"; | ||
return "Buffer|FormDataFile"; |
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 think this also affects the api response type, so it would be a breaking change, right?
I moved the type details to the Typescript mustache definitions. I hope I handle the java part correctly now. This made it also possible to add What do you mean with |
what is the result if you have something like openapi: '3.0.0'
info:
version: 1.0.0
title: Petstore
paths:
/download:
get:
responses:
'200':
description: 'An array of pets'
content:
application/octet-stream:
schema:
type: file |
Ok see what you mean. For OpenApi 3 this shouldn't be a problem (https://swagger.io/docs/specification/describing-responses/#response-that-returns-a-file) However, how to handle it for swagger? Is there a way to find out if a Schema comes from a parameter or a return value? i.e. if it is a parameter then use |
@wing328 any idea? |
@clemens-smartparking maybe you could add the decision logic here: openapi-generator/modules/openapi-generator/src/main/resources/typescript-node/api-single.mustache Line 132 in c136b83
and set Buffer if the response type is a file.Or find the method that returns the API Response type and override it there. |
I think I can't do it in the mustache file (no ifs). However, this pointed me in the right direction. I now overwrite the returnType in handleMethodResponse(). This seems to work and I hope it is the right way to do it. However, there is no example in the samples for returning a file. Should, and if yes, how can I add a sample for that? |
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.
LGTM
@clemens-smartparking can you please merge the latest master into your branch? |
Be able to specify file options as described on https://github.com/request/request in the 'multipart/form-data (Multipart Form Uploads)' section). Related to #3944 Fix file return type
Previous call to applyLocalTypeMapping didn't had any effect.
I rebased on the current master |
@clemens-smartparking thanks for the PR, which has been included in the v4.1.3 release: https://twitter.com/oas_generator/status/1180123829626003456 |
* master: (35 commits) [haskell-http-client] update samples (#4073) [haskell-http-client] Bump deps to LTS 14.7 (#4068) update release for 4.2.0 [typescript-axios] Fix api generating incorrect seralization type check (#4051) prepare 4.1.3 release (#4052) typescript-node: form data file (#3967) Add a link to blog post on vertx and openapi (#4048) better wording for apiNameSuffix option description (#4045) [Ruby] fix ruby test, update error message (#4041) [PHP] Correctly format JSON in headers (#4024) [haskell-http-client] add dateTimeParseFormat cli option - overrides the format string used to parse a datetime (#4037) Add frankyjuang to the C# technical committee (#4036) Feature/api name suffix (#3918) [F#] minor improvements to the generators (#3968) Repaired Checkstyle (#4029) mockito 3.1.0 (#4035) typescript-fetch: fix return type of primitive value (#4028) [typescript][node]: Add accept header if produces is not empty (#3966) [haskell-http-client] disable unused import warning in Core.hs (#4020) Add a link to the tutorial in http4k (#4019) ...
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first.master
,4.1.x
,5.0.x
. Default:master
.@akehir @macjohnny
Description of the PR
Add options to specify a form data file
Be able to specify file options as described on
https://github.com/request/request in the 'multipart/form-data
(Multipart Form Uploads)' section).
Related to #3944
I am new to the OpenApiGenerator and unsure if I did the java part correctly...