-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
[core][Python] rest client: handle multiple response types #2134
[core][Python] rest client: handle multiple response types #2134
Conversation
7a10be9
to
901e130
Compare
modules/openapi-generator/src/main/resources/python/api_client.mustache
Outdated
Show resolved
Hide resolved
a62af3d
to
01959ec
Compare
1b40d87
to
0d03737
Compare
Hi @rienafairefr, can you fix the Travis-CI errors? It looks like your |
@rienafairefr why not remove the response_type variable and instead pass your response_types dict only? |
@spacether thanks I pushed the missing |
Schema thisResponseSchema = (Schema) response.schema; | ||
if (thisResponseSchema != null) { | ||
CodegenProperty cm = fromProperty("response", thisResponseSchema); | ||
response.dataType = cm.dataType; |
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.
@rienafairefr why are you setting the response's dataType equal to the CodegenProperty dataType here? What is incorrect about how fromResponse is setting response.dataType higher up?
# multiple potential response types | ||
response_types = { | ||
{{#responses}} | ||
{{code}}: {{#dataType}}'{{dataType}}'{{/dataType}}{{^dataType}}None{{/dataType}}{{#hasMore}},{{/hasMore}} |
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.
Can we use baseType here instead of dataType?
It looks like dataType is used for primitive types. It looks like baseType is used for model names per here:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L2678
Then the baseType is used to import the model name here:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L2382
6241e8f
to
538c1ae
Compare
538c1ae
to
c5f40ce
Compare
c5f40ce
to
6610f45
Compare
@rienafairefr what's the status of this PR? |
@rienafairefr thank you for this PR. |
I had need for that at some point but not anymore so I guess the PR staled. The feature is still useful IMO, I'll try to look at it |
This PR has been closed due to inactivity |
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
,./bin/security/{LANG}-petstore.sh
and./bin/openapi3/security/{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\
.master
,. Default:3.4.x
,4.0.x
master
.Description of the PR
In OAS 3 it's possible to return multiple content-type, and for now the rest clients in the different languages don't support that, e.g. problems or related PRs: #206 #1367 #440
I've added returnType
returnType
field to the CodegenResponse class, this way we can get a mapping between the response code and the expected return type of that response, and I've implemented that logic in the Python client, through aresponse_types
parameter dictionary. TheAccept
header is modified to include all the cases that the client expects, not justapplication/json
.The REST response is UTF-8 decoded if needed (not decoded in case of a
file
type), and deserialized according to the response type expected for the HTTP status code that is encountered.Tested working on a API endpoint that returns a binary file on HTTP 200, and can also send a JSON with an error message for HTTP 401/403/500.