OpenAPITools / OpenAPITools/openapi-generator

[BUG] Python: When using a openapi specification only containing components and no apis, the setup.py is not generated correctly

Open
#18,100 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • 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="team@openapitools.org",
    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

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

Read modules/openapi-generator/src/main/resources/python/setup.mustache, especially the filter around line 17, and compare it with generation from the provided components-only OpenAPI specification. Run the Docker generation command from the issue and confirm that setup.py includes the complete setup(...) contents without requiring a dummy API.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.