openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[INFO] Error! Codegen Property not yet supported in getPydanticType

Open timonrieger opened this issue 8 months ago • 5 comments

In case someone is using FastaAPI as a backend generating a python client. I literally spent hours to resolve this issue:

Exception in thread "main" java.lang.RuntimeException: Error! Codegen Property not yet supported in getPydanticType: CodegenProperty{openApiType='null', baseName='any_of_1', complexType='null', getter='getAnyOf1', setter='setAnyOf1', description='null', dataType='none_type', datatypeWithEnum='none_type', dataFormat='null', name='any_of_1', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.any_of_1;', baseType='none_type', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='null', maxLength=null, minLength=null, pattern='null', example='null', jsonSchema='{ }', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=true, isModel=false, isContainer=false, isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isFile=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isArray=false, isMap=false, isOptional=false, isEnum=false, isInnerEnum=false, isEnumRef=false, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues=null, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='anyOf1', nameInPascalCase='AnyOf1', nameInSnakeCase='ANY_OF1', enumName='null', maxItems=null, minItems=null, maxProperties=null, minProperties=null, uniqueItems=false, uniqueItemsBoolean=null, multipleOf=null, isXmlAttribute=false, xmlPrefix='null', xmlName='null', xmlNamespace='null', isXmlWrapped=false, isNull=true, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, hasSanitizedName=false, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}
        at org.openapitools.codegen.languages.AbstractPythonCodegen$PydanticType.getType(AbstractPythonCodegen.java:2155)
        at org.openapitools.codegen.languages.AbstractPythonCodegen$PydanticType.generatePythonType(AbstractPythonCodegen.java:2104)
        at org.openapitools.codegen.languages.AbstractPythonCodegen.postProcessModelsMap(AbstractPythonCodegen.java:968)
        at org.openapitools.codegen.languages.AbstractPythonCodegen.postProcessAllModels(AbstractPythonCodegen.java:862)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:536)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:453)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:1303)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:535)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)

To resolve, i had to include the routers ABOVE!!! the first endpoint

# up here
app.include_router(now_router)
app.include_router(products_router)
app.include_router(payments_router)


@app.get("/", tags=["Status"], operation_id="ping")
async def ping():
    return HTTPException(status_code=status.HTTP_200_OK)

# not down here

This is very specific but maybe it helps someone out 😄

timonrieger avatar Apr 13 '25 11:04 timonrieger

Hi @timonrieger Thank you for your comment, but it is not clear for me what to write and where. Could you detailed a bit more? Could be very useful for others (including me).

Thanks, Antonio.

plutec avatar May 19 '25 03:05 plutec

@plutec It's just about where to include the routers in your FastApi app

app = FastApi()
+ app.include_router(router1)
+ app.include_router(router2)
+ app.include_router(router3)

@app.get("/", tags=["Status"], operation_id="ping")
async def ping():
    return HTTPException(status_code=status.HTTP_200_OK)

- app.include_router(router1)
- app.include_router(router2)
- app.include_router(router3)

timonrieger avatar May 20 '25 13:05 timonrieger

OOC which version of the generator is this, and how does the openapi json differ when you reorder the include_router lines?

I've been experiencing this issue for some time now and have resorted to downgrading to 7.5.0 which worked for me. I haven't quite figured out how to narrow down to the actual schema object that's causing this issue and I would love to be able to upgrade to the latest stable version.

daniellowtw avatar May 21 '25 09:05 daniellowtw

OOC which version of the generator is this, and how does the openapi json differ when you reorder the include_router lines?

Hey @daniellowtw! Sorry for answering just know…i am using 7.13.0

timonrieger avatar Jun 08 '25 21:06 timonrieger

I also found another issue causing the same error as above when generating client code using fastapi and pydantic v2. Avoid using typing.Any as type hint if your dealing with generic inputs.

from pydantic import BaseModel
- from typing import Any

class Filter(BaseModel):
-  filter_value: Optional[Any] = Field(None, description="The value to filter with")
+  filter_value: Optional[str] = Field(None, description="The value to filter with")

timonrieger avatar Jun 08 '25 21:06 timonrieger

Here's a super-simple model that reproduces the issue:

class TestModel(BaseModel):
    model_config = ConfigDict(extra="allow")

    system_properties: dict | None = Field(
        None, description="Miscellaneous properties"
    )

Getting rid of model_config = ConfigDict(extra="allow"), or making system_properties a required property or a specific nested type causes the problem to go away.

joesavage-silabs avatar Sep 17 '25 13:09 joesavage-silabs

For me changing from model_config = ConfigDict(extra="forbid") to model_config = ConfigDict(extra="ignore") fixed this problem for some reason that is unclear to me.

garyluoex avatar Oct 02 '25 20:10 garyluoex