[core][Python] rest client: handle multiple response types#2134
[core][Python] rest client: handle multiple response types#2134rienafairefr wants to merge 12 commits intoOpenAPITools:masterfrom
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 |
There was a problem hiding this comment.
@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?
There was a problem hiding this comment.
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
….mustache Co-Authored-By: rienafairefr <rienafairefr@gmail.com>
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.shand./bin/openapi3/security/{LANG}-petstore.shif 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.xmaster.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
returnTypefield 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_typesparameter dictionary. TheAcceptheader 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
filetype), 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.