openapi-generator
openapi-generator copied to clipboard
[BUG] Python: When using a openapi specification only containing components and no apis, the setup.py is not generated correctly
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator (example)?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] What's the actual output vs expected output?
- [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I use a openapi specification similar to this:
When I generate the python code using the OpenAPI generator to create data objects (then used with RabbitMQ), the generated setup looks like this: actual
# coding: utf-8
"""
comments blabla
""" # noqa: E501
from setuptools import setup, find_packages # noqa: H301
# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
NAME = "openapi-client"
VERSION = "0.1.0"
PYTHON_REQUIRES = ">=3.7"
expected
# coding: utf-8
"""
comments blabla
""" # noqa: E501
from setuptools import setup, find_packages # noqa: H301
# To install the library, run the following
#
# python setup.py install
#
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
NAME = "openapi-client"
VERSION = "0.1.0"
PYTHON_REQUIRES = ">=3.7"
setup(
name=NAME,
version=VERSION,
description="Test API",
author="OpenAPI Generator community",
author_email="[email protected]",
url="",
keywords=["OpenAPI", "OpenAPI-Generator", "Test API"],
install_requires=REQUIRES,
packages=find_packages(exclude=["test", "tests"]),
include_package_data=True,
long_description_content_type='text/markdown',
long_description="""\
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
""", # noqa: E501
package_data={"openapi_client": ["py.typed"]},
)
openapi-generator version
All generators >= 7.0.0
, worked with earlier versions
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: 'Test API'
version: '0.1.0'
paths: {}
components:
schemas:
TestRequest:
type: object
properties:
requestId:
type: string
pageSize:
type: integer
description: ...
pageNumber:
type: integer
description: ...
required:
- requestId
Generation Details
Generation is then done in Docker
# Stage 1: Use openapi-generator to generate code
FROM openapitools/openapi-generator-cli:latest AS generator # any >v7.0.0 is the same behavior
COPY test-api-v1/ /local/test-api-v1/
# Generate openapi client
RUN bash /usr/local/bin/docker-entrypoint.sh generate -i /local/test-api-v1/openapi-specification.yml -g python -o local/openapi
Steps to reproduce
Just generate the code with the Generation Details and the OpenAPI declaration.
Related issues/PRs
I did not find any related issues. I was searching for ~ 10 hours to identify this issue.
Suggest a fix
I have already identified the problem. It is because the mustache
file requires an API definition to generate the setup contents (see here)
Removing this filter for apis
or/and latest
should fix the problem. A current workaround is to add a dummy API, which is then not used.
I have no knowledge of mustache
and its templating. So I can not help very much here
I don't know if my suggested fix can be implemented this way. Are there any reasons why an API is required to generate the setup()
function?
@florianbaer I had a similar issue and upgrading wheel was enough for me to solve it