-
-
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
[BUG][PYTHON] Generated models and optional parameters #15567
Comments
Also is anyone kind enough to point me to these new changes to the Python generator? I cannot really see the model change in the pull requests, but I might be wrong of course. Edit: Found it, the Python generator changed #15486 On another note, does 7.0.0 treat the naming of components in a different way? I am asking this because for me the stable version 6.6.0 does not work, while 7.0.0 works just fine. Version 6.6.0 returns the error "ValueError: Invalid name, name may not be one of" {'Accept', 'Content-Type', 'Authorization'}". I suspect this is due to the naming of the parameter called "Authorization" used in my API as the bearer token auth. |
Per the openapi spec:
If you need a header with the name Authorization, use
Or use
read all about it in the spec here One can see this working in the new repo for the v6.6.0
|
Hi, thank you for answering. I already use bearerAuth and get the error. I do not get it with version 7.0.0. In any case, should it not just ignore my "Authorization" parameter, as suggested by the spec "If in is "header" and the name field is "Accept", "Content-Type" or "Authorization", the parameter definition SHALL be ignored." securitySchemes:
bearerAuth:
type: http
scheme: bearer
bearerFormat: JWT and parameters:
auth:
in: header
name: Authorization
required: true
schema:
type: string
description: "Bearer JWT token verified to ensure request is from valid consumer. Format \"Bearer <jwt-token>\"\
.\nExample, \"Bearer eyJ0eXAiOiJKV1QiLCJhbGc....\"" |
I encountered the same issue after generating a Python client for https://demo.openremote.app/api/master/openapi.json I previously used the Docker image |
I am coming back with some remarks, which I can open various "issues" on a bit later when I have time. I tested various versions and found out that:
I also found out that:
This configuration for host and access_token is fixed by putting them into one |
Concerning the main topic of this thread, I have found that using stable version 5.4.0 has the readonly and optional flags from the spec file correctly generated and present in the model files. This is also present in version 7.0.0 release 20220526. I also found that the documentation is correctly rendered using stable version 5.4.0 and 7.0.0 release 20220526 and pylint that comes with VSCode. This means that I get the correct description while hovering over assigned object models, with their types. Otherwise:
|
Based on the initial bug report, I may be having the same issue, but the rest of the thread doesn't jive... Example schema fragment:
then in the provided example Python code in the generated README.md:
The autogenerated 'modified_time_example' string doesn't mean anything to the API and it breaks if it's run without replacing it with a valid string. Seems to me that if the schema has the param as optional and no example is provided, it shouldn't be used in the example code... |
Bug Report Checklist
Description
I am using the version 7.0.0 dated 2023/05/16 to generate Python code and the models do not take into account the readonly and optional flags from the spec file. As an example, my API includes a component called DataCollectionPlan, and a POST for the same component schema.
In order to use the example code, I must declare the Python object with all the optional and readonly parameters, such as id or description. The id is not necessary when using POST, while the optionals can be set to None, but this is not the correct way to treat optional object parameters.
openapi-generator version
7.0.0 dated 2023/05/16
OpenAPI declaration file content or url
The YAML section of the component.
The YAML section of the POST.
Generation Details
I tried both with Java version 8 and using the Docker container from openapitools/openapi-generator-cli:latest.
Steps to reproduce
Just generated code as normal.
Related issues/PRs
None.
Suggest a fix
This was not an issue in the version 7.0.0 dated 2022/05/26. It seems like the model files had a different structure, and they took into account when model is used for POST or for results from PUT.
The text was updated successfully, but these errors were encountered: