OpenAPITools / OpenAPITools/openapi-generator

[BUG] [python-flask] Trying to run installed module NotADirectory error for yaml file

Open
#4,433 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug Server: Python
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Using petstore swagger yaml I have created python-flask server. and then I have created dist and installed it.

python setup.py sdist
sudo python3 setup.py install
sudo python3 -m openapi_server

Trying to run the module and get the following error

sudo python3 -m openapi_server
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.5/dist-packages/openapi_server-1.0.0-py3.5.egg/openapi_server/__main__.py", line 18, in <module>
  File "/usr/local/lib/python3.5/dist-packages/openapi_server-1.0.0-py3.5.egg/openapi_server/__main__.py", line 13, in main
  File "/usr/local/lib/python3.5/dist-packages/connexion-2.4.0-py3.5.egg/connexion/apps/flask_app.py", line 54, in add_api
    api = super(FlaskApp, self).add_api(specification, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/connexion-2.4.0-py3.5.egg/connexion/apps/abstract.py", line 155, in add_api
    options=api_options.as_dict())
  File "/usr/local/lib/python3.5/dist-packages/connexion-2.4.0-py3.5.egg/connexion/apis/abstract.py", line 73, in __init__
    self.specification = Specification.load(specification, arguments=arguments)
  File "/usr/local/lib/python3.5/dist-packages/connexion-2.4.0-py3.5.egg/connexion/spec.py", line 151, in load
    return cls.from_file(spec, arguments=arguments)
  File "/usr/local/lib/python3.5/dist-packages/connexion-2.4.0-py3.5.egg/connexion/spec.py", line 107, in from_file
    spec = cls._load_spec_from_file(arguments, specification_path)
  File "/usr/local/lib/python3.5/dist-packages/connexion-2.4.0-py3.5.egg/connexion/spec.py", line 91, in _load_spec_from_file
    with specification.open(mode='rb') as openapi_yaml:
  File "/usr/lib/python3.5/pathlib.py", line 1151, in open
    opener=self._opener)
  File "/usr/lib/python3.5/pathlib.py", line 1005, in _opener
    return self._accessor.open(self, flags, mode)
  File "/usr/lib/python3.5/pathlib.py", line 371, in wrapped
    return strfunc(str(pathobj), *args)
NotADirectoryError: [Errno 20] Not a directory: '/usr/local/lib/python3.5/dist-packages/openapi_server-1.0.0-py3.5.egg/openapi_server/openapi/openapi.yaml'
openapi-generator version

openapi-generator-cli-4.2.0.jar

OpenAPI declaration file content or url

https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v2.0/yaml/petstore.yaml

Command line used for generation

java -jar openapi-generator-cli-4.2.0.jar generate -i ./swagger.yaml -g python-flask -o generated/server/python/flask -c python-config.json

{
    "packageName": "openapi_server",
    "controllerPackage": "controllers",
    "defaultController": "default_controller",
    "sortParamsByRequiredFlag": true,
    "ensureUniqueParams": true,
    "allowUnicodeIdentifiers": false,
    "prependFormOrBodyParameters": false,
    "packageVersion": "1.0.0",
    "supportPython2": true,
    "serverPort": 9898
}
Steps to reproduce
python setup.py sdist
sudo python3 setup.py install
sudo python3 -m openapi_server
Related issues/PRs
Suggest a fix

I am new to python but maybe instead of trying to open yaml file as a file use ziputils to open a file inside an archive?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the installation and module invocation with the generated python-flask server, then inspect openapi_server/main.py and the package produced by setup.py. Compare the installed path in the traceback with the generated distribution layout. Done means the installed openapi_server module starts without the NotADirectoryError when loading openapi.yaml.

Written by the indexing model from the issue text.

Assessment

Tech stack
flask, openapi, python
Domain
api, backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.