Skip to content
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] "sub-module" definition in packageName does not work #1658

Closed
tomghyselinck opened this issue Dec 10, 2018 · 4 comments
Closed

Comments

@tomghyselinck
Copy link
Contributor

tomghyselinck commented Dec 10, 2018

Description

We define "packageName": "myapi.rest.client" in the config file for the python generator.
This is because we want our REST API to de a submodule of the myapi.

The generated code does not give us the expected code layout.

openapi-generator version

I used OpenAPI generator CLI version 4.0.0-SNAPSHOT:
https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/4.0.0-SNAPSHOT/openapi-generator-cli-4.0.0-20181210.103357-85.jar

OpenAPI declaration file content or url

python-sub-module.yaml:

openapi: '3.0.1'
info:
        title: Test REST API
        version: "1.0"
servers:
- url: /
paths:
        /data:
                get:
                        summary: Get the Remote Data
                        responses:
                                '200':
                                        description: Remote Object
                                        content:
                                                application/json:
                                                        schema:
                                                                properties:
                                                                        data:
                                                                                type: string
Command line used for generation
java -jar openapi-generator-cli-4.x.jar generate -i ./python-sub-module.yaml -g python -o ./client/python/ -c ./config/python.json
Steps to reproduce

python-sub-module.sh:

#!/bin/sh
mkdir -p config
cat >config/python.json <<-CONFIG
{
        "packageName": "myapi.rest.client",
        "projectName": "myapi-rest-client"
}
CONFIG

rm -rf client/python/
java -jar openapi-generator-cli-4.x.jar generate -i ./python-sub-module.yaml -g python -o ./client/python/ -c ./config/python.json
tom@localhost:~/issues$ ./python-sub-module.sh
tom@localhost:~/issues$ tree -aAC client/python/
client/python/
├── docs
│   └── DefaultApi.md
├── .gitignore
├── git_push.sh
├── myapi
│   └── rest
│       └── client
│           └── api
│               └── default_api.py
├── myapi.rest.client
│   ├── api
│   │   └── __init__.py
│   ├── api_client.py
│   ├── configuration.py
│   ├── __init__.py
│   ├── models
│   │   └── __init__.py
│   └── rest.py
├── .openapi-generator
│   └── VERSION
├── .openapi-generator-ignore
├── README.md
├── requirements.txt
├── setup.py
├── test
│   ├── __init__.py
│   └── test_default_api.py
├── test-requirements.txt
├── tox.ini
└── .travis.yml

10 directories, 20 files
Related issues/PRs
Suggest a fix

Fixes in progress:

@auto-labeler
Copy link

auto-labeler bot commented Dec 10, 2018

Thanks for opening this issue! I have applied any relevant labels.

@wing328 wing328 removed bug labels Dec 13, 2018
@adrpp
Copy link

adrpp commented Jan 16, 2019

Hello,

btw this affects actual stable as well.

generator version: openapi-generator-cli-3.3.4
generator: python-flask
after generation, it looks like @tomghyselinck reported.

wrong placed files / dirs:

  • "base_model_.py" is placed wrong
  • "openapi/openapi.yaml"
  • "encoder.py"
  • "util.py"

Rgds,
Adrian

@tomghyselinck
Copy link
Contributor Author

A similar issue has been reported in #1899

dojeda added a commit to quetz-al/quetzal-client that referenced this issue Feb 15, 2019
Massive refactoring to put the autogenerated code outside the quetzal.client
module, which breaks the weird module organization that did not permit to create
meaningful synonyms/shortcuts on the quetzal/client/__init__.py file. One
pending thought to keep in mind: should the autogenerated client live in a
separate repo? For the moment, let's keep things together to avoid
fragmentation.

A fortunate side-effect of this refactoring is that the issue concerning the
dots on the generated
files (OpenAPITools/openapi-generator#1658) has been
fixed; there is no need to manually rename files.

Finally, a namespace package distribution strategy was chosen and implemented
for the quetzal namespace. There are three strategies possible; the one used for
quetzal will be "pkgutil-style namespace packages". See:
https://packaging.python.org/guides/packaging-namespace-packages/#pkgutil-style-namespace-packages
@tomghyselinck
Copy link
Contributor Author

This seems to work fine with the latest SNAPSHOT versions (with #2016 and #2041 integrated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants