OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.85k stars 6.59k forks source link

[BUG] setup.py incorrect using python or python-pydantic-v1 generators when no paths are specified #20090

Open loic-seguin opened 1 day ago

loic-seguin commented 1 day ago

Bug Report Checklist

Description

I generate a python client based on my really simple openapi.yaml. But the setup.py that is generated does not contain the setup() method. So it is not possible to import this library with poetry or pip.

openapi-generator version

7.9.0 but it seems to have the same issue on 7.0.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: RepositoryActions
  version: '1.0'
servers:
  - url: 'http://localhost:3000'
paths: {}
components:
  schemas:
    RepositoryActions:
      type: object
      properties:
        repository_url:
          type: string
        actions:
          type: array
          items:
            $ref: '#/components/schemas/CreateCommentAction'
    CreateCommentAction:
      type: object
      properties:
        text:
          type: string
Generation Details

openapi-generator-cli generate -i openapi.yaml -g python -o ./generated-python-client

Steps to reproduce

openapi-generator-cli generate -i openapi.yaml -g python -o ./generated-python-client

[tool.poetry.dependencies] python = "^3.10" openapi-client = {path="../generated-python-client/"}

[build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"

Run the command 'poetry install'

You will get this error 

poetry install Updating dependencies Resolving dependencies... (0.5s)

Package operations: 1 install, 0 updates, 0 removals

Note: This error originates from the build backend, and is likely not a problem with poetry but with openapi-client (1.0.0 /home/lseguin/Documents/github_describe_issue/generated-python-client) not supporting PEP 517 builds. You can verify this by running 'pip wheel --no-cache-dir --use-pep517 "openapi-client @ file:///home/lseguin/Documents/github_describe_issue/generated-python-client"'.


##### Suggest a fix
The generation of the setup.py is incorrect, as it should call the setup method for me : 

from setuptools import setup, find_packages

NAME = "openapi-client" VERSION = "1.0.0" PYTHON_REQUIRES = ">=3.7" setup(name=NAME,version=VERSION,python_requires=PYTHON_REQUIRES)


This file does not seem to be used properly -> https://github.com/OpenAPITools/openapi-generator/blob/a95ea1f519c79ac23ca1315a796b5821b05800c8/modules/openapi-generator/src/main/resources/python/setup.mustache#L9
loic-seguin commented 1 day ago

I have found the problem I think, the paths property is not present in my openapi.yaml because I don't need any APIs for now. I just need the models to be generated. It should also work without paths property in the yaml. Trying to fix the problem in a PR.