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.94k stars 6.59k forks source link

[BUG][Python] python-fastapi 7.9.0 generates wrong imports #20153

Open al3ad opened 1 day ago

al3ad commented 1 day ago

Bug Report Checklist

Description

An import is generated that does not exist.

openapi-generator version

7.9.0

OpenAPI declaration file content or url

The code for the yaml spec can be found here: https://github.com/bbc/tams/tree/main/api

Generation Details

This is a snippet of the file it generates with the relevant to the issue imports:

from pydantic import ConfigDict, Field
from openapi_server.models.object import object
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class MediaBucketObjectStore(object):
    ...

The issue is the imported object, which doesn't exist.

I believe the generated file should be this:

from pydantic import ConfigDict, Field, BaseModel
try:
    from typing import Self
except ImportError:
    from typing_extensions import Self

class MediaBucketObjectStore(BaseModel):
    ...
Steps to reproduce
build-server-local-fastapi:
    docker run --user ${USER}:${GROUP} --rm \
                   -v ${PWD}:/local openapitools/openapi-generator-cli:v${GEN_VER} generate \
                   --additional-properties=apiNameSuffix=controller_impl \
                   -t /local/.templates/7.9.0/python_fastapi/.openapi-generator-server/ \
                   -i /local/openapi.yaml \
                   -g python-fastapi \
                   -o /local/python_fastapi/