swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.98k stars 6.03k forks source link

[python-flask] ImportError: No module named byte_array #7255

Open turkenh opened 6 years ago

turkenh commented 6 years ago
Description

Getting the following error while trying to run generated server stub for kubernetes apiserver with python flask:

python -m swagger_server
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/Cellar/python/2.7.14/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/i312386/Workspace/apiserver_stub/apiserver-stub/swagger_server/__main__.py", line 5, in <module>
    from swagger_server import encoder
  File "swagger_server/encoder.py", line 4, in <module>
    from swagger_server.models.base_model_ import Model
  File "swagger_server/models/__init__.py", line 28, in <module>
    from swagger_server.models.io_k8s_apimachinery_pkg_apis_meta_v1_watch_event import IoK8sApimachineryPkgApisMetaV1WatchEvent
  File "swagger_server/models/io_k8s_apimachinery_pkg_apis_meta_v1_watch_event.py", line 9, in <module>
    from swagger_server.models.io_k8s_apimachinery_pkg_runtime_raw_extension import IoK8sApimachineryPkgRuntimeRawExtension  # noqa: F401,E501
  File "swagger_server/models/io_k8s_apimachinery_pkg_runtime_raw_extension.py", line 9, in <module>
    from swagger_server.models.byte_array import ByteArray  # noqa: F401,E501
ImportError: No module named byte_array
Swagger-codegen version

2.3.0

Swagger declaration file content or url

https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json

Command line used for generation
java -jar swagger-codegen-cli.jar generate \
-i https://raw.githubusercontent.com/kubernetes/kubernetes/master/api/openapi-spec/swagger.json \
-l python-flask \
-o apiserver-stub \
-D supportPython2=true
Steps to reproduce
  1. Generate server stub for python-flask
  2. Follow the steps in readme to run the server
Related issues/PRs
Suggest a fix/enhancement

What I understand is there should be a file named byte_array.py under swagger_server/models/ defining ByteArray type. But there is no such a file.

iobleed commented 6 years ago

Yaml element responsible for this error:

type: string
format: byte
mnagel commented 6 years ago

Is there any known workaround?

jakecobb commented 5 years ago

I opened a PR to fix this but a work-around is to include --type-mappings ByteArray=str in the command line arguments when using the CLI.