-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[BUG][Python] Wrong generated Type tree for Inline response schema #8743
Comments
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
Hi there. Thank you for reporting this issue.
I see the endpoint defined as:
In that model I see id defined as int:
Can you try using my provided yaml file in your spec? |
So there are two issues at play here:
|
The provided OAS schema is a shortened schema. The original OAS file is attached: We are focussing on path fields/{field} because we are using it (only). Regreteably, it does not use refered components, that seems to have solved the issue for the most part. The OAS file is not ours, we have to make do with it. Thank you for your time. |
So when I generate your client with my above v2 yaml spec it generates 2 models WITHOUT using a ref. Does that work for you? Can this ticket be closed? |
We have tried PHP, and that went without a hitch on the full OAS. We have not tried creating a working implementation with the PHP client, but surfacially it looks good (better and cleaner than python really). PHP still has the same inlineobject123 files, and it seems that the type checking is a simple 'map[string,object]' or a reference to a class '\OpenAPI\Client\Model\InlineResponse2004[]'. In your above generated model:
It seems that in our generated python client code, wherever it is using classes for
It does not work, and should be fixed (apparently or in the direction of my issue description suggestions) in the java generation code. With your 'above v2 yaml spec', what are you suggesting? That I use your process of generating yaml first, before generating the python client? This MAY work (have not tried this yet), but it occurs to me as not the ideal solution for anyone (the ideal solution being to fix the java generator for python code for inline type trees). Adding refs to the extended original OAS file using a preprocessing script is also a potential solution we have thought of, but it requires constant monitoring that correct interpreteable names for the components are used. Again, if it's not ideal for us, it hardly could be ideal for someone else. At the moment, we are resolving our problem by manually editing the generated python client code, with the correct inline type tree, as I described in the issue description. I prefer this ticket to remain open until the issue is resolved (the generator not outputting correct inline type trees). |
Please use the |
I am facing this issue still... I get the type to be the union for generic Object kind of value, but get an error saying failed as below ApiTypeError("Invalid type for variable 'name'. Required value type is dict and passed type was str at ['properties']['payload']['name']"), <traceback object at 0x1023d6c00> |
@uncleflo your spec is very old as it uses swagger 2.0 which was released on 2014-09-08
When I generate client using the v6.2.0 python client generator I get this response class for the route
And the body is deserialized using the schema SchemaFor200ResponseBody
Which is consistent with your defined response schema:
You are requiring that the response body is a dict, which the python code enforces with the SchemaFor200ResponseBody inheriting schemas.DictSchema. Your schema has no properties defined, so every value in your key value pair that is ingested must be what is defined in additionalProperties. additionalProperties defines values as type object (which is a dict in python). |
@polavishnu4444 please us the 6.2.0 openapi-generator with the python client. If you are still having this issue please post your spec here and point out which schema and payload are not working as expected. |
Bug Report Checklist
Description
I am trying to retrieve the data from a path using the Python-generated code from an openapi spec file. The python code generated returns a ApiTypeError. When investigating deeper, it seems the openapi spec file is not read correctly, or is missing some types in the inline type checking. Separately, the _check_return_type=False does not seem to work to skip this step.
openapi-generator version
Both 5.0.0 and 5.0.1 have been tried
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli.jar generate
-i oas.json
-o quickbase-openapi-client
-g python
Steps to reproduce
As above
Related issues/PRs
Checked, not found
Suggest a fix
In file:
https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonClientCodegen.java
In function:
private String getTypeString(Schema p, String prefix, String suffix, List referencedModelNames)
This seems to result with the above oas and generation into: fields_api.py
...But this returns a ApiTypeError: Invalid type for variable 'id'. Required value type is dict and passed type was int at ['received_data']['id']
However, when the above is changed to:
Then the code runs fine.
It seems as if the Response Types Tree does not resemble the json response schema very well.
Further (though this may be a seperate issue), passing _check_return_type=False, into kwargs, does not prevent Type checking to be conducted, this would otherwise have (to some degree) resolved this issue.
The text was updated successfully, but these errors were encountered: