[Python] Support for package hierarchy
Created by: mmunz-nextdoor
Description
I am trying to generate a service client for a project that uses a particular package hierarchy by convention. I have tried the following but am yet to generate a client that I can successfully import, due to mis-matching/incorrect import statements, and files that are placed in the wrong folders.
For example #1 (below) I get code like import api
where import foo.bar.baz.api
is desired. With example #2, I get directories like foo.bar.baz.my_client.model
when foo/bar/baz/my_client/model
is desired.
ex.1)
openapi-generator generate -g python -l python -c my_config.json \
--api-package api --model-package model \
--http-user-agent 'my_agent' \
--log-to-stderr \
-i ./api/my_spec.yaml -o $CLIENT_DIR
ex.2)
openapi-generator generate -g python -l python -c my_config.json \
--api-package foo.bar.baz.my_client.api --model-package foo.bar.baz.my_client.model \
--http-user-agent 'my_agent' \
--log-to-stderr \
-i ./api/my_spec.yaml -o $CLIENT_DIR
my_config.json:
"packageName":"foo.bar.baz.my_client",
"projectName":"my_project",
"packageVersion": "1.0.0",
"sortParamsByRequiredFlag": "true",
"hideGenerationTimestamp": "true",
"generateSourceCodeOnly": "false",
"library": "urllib3"
}
openapi-generator version
3.3.1
OpenAPI declaration file content or url
I don't believe this is relevant. If needed I can provide a version of the spec.
Command line used for generation
See above.
Steps to reproduce
Run either of the commands above.
Related issues/PRs
I didn't find any.
Suggest a fix/enhancement
It seems like there is some code that is parsing the "foo.bar.baz" syntax into a file path since some of the files are correctly placed with the right import statements. Presumably some of the generator code (the part that handles --api-package api --model-package model
) is not correctly handling these package names.
Thanks for reviewing this. Any pointers/suggestions would be really appreciated!