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 imports of UNKNOWN_BASE_TYPE #20154

Open al3ad opened 1 day ago

al3ad commented 1 day ago

Bug Report Checklist

Description

Generated files have an unknown_base_type import.

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 tests/test_default_controller_impl:

# coding: utf-8

from fastapi.testclient import TestClient

from openapi_server.models.collection_item import CollectionItem  # noqa: F401
#from openapi_server.models.one_of_video_flow_audio_flow_data_flow_multi_essence_flow import OneOfVideoFlowAudioFlowDataFlowMultiEssenceFlow  # noqa: F401
from openapi_server.models.unknownbasetype import UNKNOWN_BASE_TYPE  # noqa: F401

def test_flows_created_post(client: TestClient):
    """Test case for flows_created_post

    """
    unknown_base_type = openapi_server.UNKNOWN_BASE_TYPE()
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/
wing328 commented 1 day ago

thanks for reporting the issue.

can you please test it with the python client generator as well to see if there are similar import issues?

please also use v7.10.0 which is the latest stable version released a few days ago.

al3ad commented 7 hours ago

Hi, can confirm that this issue still persists with the difference of if in 7.9.0 the generated file is:

# coding: utf-8

from fastapi.testclient import TestClient

from openapi_server.models.collection_item import CollectionItem  # noqa: F401
#from openapi_server.models.one_of_video_flow_audio_flow_data_flow_multi_essence_flow import OneOfVideoFlowAudioFlowDataFlowMultiEssenceFlow  # noqa: F401
from openapi_server.models.unknownbasetype import UNKNOWN_BASE_TYPE  # noqa: F401

def test_flows_created_post(client: TestClient):
    """Test case for flows_created_post

    """
    unknown_base_type = openapi_server.UNKNOWN_BASE_TYPE()

then in 7.10.0 it's:

# coding: utf-8

from typing import ClassVar, Dict, List, Tuple  # noqa: F401

from openapi_server.models.collection_item import CollectionItem
from openapi_server.models.one_of_video_flow_audio_flow_data_flow_multi_essence_flow import OneOfVideoFlowAudioFlowDataFlowMultiEssenceFlow
from openapi_server.models.unknownbasetype import UNKNOWN_BASE_TYPE

class BaseDefaultControllerImpl:
    subclasses: ClassVar[Tuple] = ()

    def __init_subclass__(cls, **kwargs):
        super().__init_subclass__(**kwargs)
        BaseDefaultControllerImpl.subclasses = BaseDefaultControllerImpl.subclasses + (cls,)
    async def flows_created_post(
        self,
        unknown_base_type: ,
    ) -> None:
        ...

Thanks for the reply, @wing328