Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] $reffed enum in request body causing error on codegening a Python client #17171

Closed
ggininla opened this issue Nov 23, 2023 · 0 comments · Fixed by #17438
Closed

[BUG] $reffed enum in request body causing error on codegening a Python client #17171

ggininla opened this issue Nov 23, 2023 · 0 comments · Fixed by #17438

Comments

@ggininla
Copy link

ggininla commented Nov 23, 2023

Bug Report Checklist

Description

A simple spec to re-produce the issue:

openapi: 3.0.0
info:
  title: MyAPI
  version: 1.0.0
paths:
  '/bar':
    get:
      requestBody:
        content:
          plain/text:
            schema:
              $ref: '#/components/schemas/foo'
      responses:
        '200':
          description: OK
components:
  schemas:
    foo:
      type: string
      enum:
        - One
        - Two
        - Three

Run:

openapi-generator-cli generate -g python -i sample.yaml -o ./python_client

Error:

[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/repo/scripts/../source/api_client) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python' is considered stable.
[main] INFO  o.o.c.l.AbstractPythonCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractPythonCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.c.languages.PythonClientCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.languages.PythonClientCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/models/foo.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/test/test_foo.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/docs/Foo.md
[main] WARN  o.o.codegen.DefaultCodegen - Empty operationId found for path: get /bar. Renamed to auto-generated operationId: barGet
Exception in thread "main" java.lang.RuntimeException: Could not generate api file for 'default'
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:756)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:994)
        at org.openapitools.codegen.cmd.Generate.execute(Generate.java:519)
        at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.RuntimeException: Error! Failed to process getPydanticType when getting the content: CodegenParameter{isFormParam=false, isQueryParam=false, isPathParam=false, isHeaderParam=false, isCookieParam=false, isBodyParam=true, isContainer=false, isCollectionFormatMulti=false, isPrimitiveType=true, isModel=false, isExplode=false, baseName='body', paramName='body', dataType='str', datatypeWithEnum='null', dataFormat='null', collectionFormat='null', description='null', unescapedDescription='null', baseType='str', containerType='null', containerTypeMapped='null', defaultValue='null', enumDefaultValue='null', enumName='null', style='null', deepObject='false', isMatrix='false', allowEmptyValue='false', example=''body_example'', examples='null', jsonSchema='{
  "content" : {
    "plain/text" : {
      "schema" : {
        "$ref" : "#/components/schemas/foo"
      }
    }
  }
}', isString=false, isNumeric=false, isInteger=false, isShort=false, isLong=false, isUnboundedInteger=false, isNumber=false, isFloat=false, isDouble=false, isDecimal=false, isByteArray=false, isBinary=false, isBoolean=false, isDate=false, isDateTime=false, isUuid=false, isUri=false, isEmail=false, isPassword=false, isFreeFormObject=false, isAnyType=false, isArray=false, isMap=false, isFile=false, isEnum=false, isEnumRef=false, _enum=null, allowableValues=null, items=null, mostInnerItems=null, additionalProperties=null, vars=[], requiredVars=[], vendorExtensions={}, hasValidation=false, maxProperties=null, minProperties=null, isNullable=false, isDeprecated=false, required=false, maximum='null', exclusiveMaximum=false, minimum='null', exclusiveMinimum=false, maxLength=null, minLength=null, pattern='null', maxItems=null, minItems=null, uniqueItems=false, uniqueItemsBoolean=null, contentType=null, multipleOf=null, isNull=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, schema=null, content={plain/text=CodegenMediaType{schema=CodegenProperty{openApiType='Foo', baseName='SchemaForRequestBodyPlainText', complexType='Foo', getter='getSchemaForRequestBodyPlainText', setter='setSchemaForRequestBodyPlainText', description='null', dataType='Foo', datatypeWithEnum='Foo', dataFormat='null', name='schema_for_request_body_plain_text', min='null', max='null', defaultValue='null', defaultValueWithParam=' = data.SchemaForRequestBodyPlainText;', baseType='Foo', containerType='null', containerTypeMapped='null', title='null', unescapedDescription='null', maxLength=null, minLength=null, pattern='null', example=''One'', jsonSchema='{
  "$ref" : "#/components/schemas/foo"
}', minimum='null', maximum='null', exclusiveMinimum=false, exclusiveMaximum=false, required=false, deprecated=false, hasMoreNonReadOnly=false, isPrimitiveType=false, 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, isEnum=false, isInnerEnum=false, isEnumRef=true, isAnyType=false, isReadOnly=false, isWriteOnly=false, isNullable=false, isSelfReference=false, isCircularReference=false, isDiscriminator=false, isNew=false, isOverridden=null, _enum=null, allowableValues={values=[One, Two, Three]}, items=null, additionalProperties=null, vars=[], requiredVars=[], mostInnerItems=null, vendorExtensions={}, hasValidation=false, isInherited=false, discriminatorValue='null', nameInCamelCase='SchemaForRequestBodyPlainText', nameInSnakeCase='SCHEMA_FOR_REQUEST_BODY_PLAIN_TEXT', 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=false, isVoid=false, getAdditionalPropertiesIsAnyType=false, getHasVars=false, getHasRequired=false, getHasDiscriminatorWithNonEmptyMapping=false, composedSchemas=null, hasMultipleTypes=false, requiredVarsMap=null, ref=#/components/schemas/foo, schemaIsFromAdditionalProperties=false, isBooleanSchemaTrue=false, isBooleanSchemaFalse=false, format=null, dependentRequired=null, contains=null}, encoding=null, vendorExtensions={}}}, requiredVarsMap=null, ref=null, schemaIsFromAdditionalProperties=false}
        at org.openapitools.codegen.languages.AbstractPythonCodegen$PydanticType.getType(AbstractPythonCodegen.java:2217)
        at org.openapitools.codegen.languages.AbstractPythonCodegen$PydanticType.generatePythonType(AbstractPythonCodegen.java:2193)
        at org.openapitools.codegen.languages.AbstractPythonCodegen.postProcessOperationsWithModels(AbstractPythonCodegen.java:1256)
        at org.openapitools.codegen.DefaultGenerator.processOperations(DefaultGenerator.java:1319)
        at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:628)
        ... 4 more
(app-root) bash-5.1# 

It works fine with the de-reffed version of the same spec.

openapi: 3.0.0
info:
  title: MyAPI
  version: 1.0.0
paths:
  '/bar':
    get:
      requestBody:
        content:
          plain/text:
            schema:
              $ref: '#/components/schemas/foo'
      responses:
        '200':
          description: OK
components:
  schemas:
    foo:
      type: string
      enum:
        - One
        - Two
        - Three
[main] INFO  o.o.codegen.DefaultGenerator - Generating with dryRun=false
[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - Output directory (/repo/scripts/../source/api_client) does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[main] INFO  o.o.codegen.DefaultGenerator - OpenAPI Generator: python (client)
[main] INFO  o.o.codegen.DefaultGenerator - Generator 'python' is considered stable.
[main] INFO  o.o.c.l.AbstractPythonCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.l.AbstractPythonCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.c.languages.PythonClientCodegen - Environment variable PYTHON_POST_PROCESS_FILE not defined so the Python code may not be properly formatted. To define it, try 'export PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' (Linux/Mac)
[main] INFO  o.o.c.languages.PythonClientCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI).
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] WARN  o.o.codegen.DefaultCodegen - Empty operationId found for path: get /bar. Renamed to auto-generated operationId: barGet
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/api/default_api.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/test/test_default_api.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/docs/DefaultApi.md
[main] INFO  o.o.codegen.utils.URLPathUtils - 'host' (OAS 2.0) or 'servers' (OAS 3.0) not defined in the spec. Default to [http://localhost] for server URL [http://localhost/]
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/README.md
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/tox.ini
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/test-requirements.txt
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/requirements.txt
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/setup.cfg
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/git_push.sh
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.gitignore
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.travis.yml
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.github/workflows/python.yml
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.gitlab-ci.yml
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/setup.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/pyproject.toml
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/py.typed
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/configuration.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/models/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/api/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/exceptions.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/test/__init__.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/api_client.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/api_response.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/openapi_client/rest.py
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.openapi-generator-ignore
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.openapi-generator/VERSION
[main] INFO  o.o.codegen.TemplateManager - writing file /repo/scripts/../source/api_client/.openapi-generator/FILES
################################################################################
# Thanks for using OpenAPI Generator.                                          #
# Please consider donation to help us maintain this project 🙏                 #
# https://opencollective.com/openapi_generator/donate                          #
################################################################################
openapi-generator version

7.1.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: MyAPI
  version: 1.0.0
paths:
  '/bar':
    get:
      requestBody:
        content:
          plain/text:
            schema:
              $ref: '#/components/schemas/foo'
      responses:
        '200':
          description: OK
components:
  schemas:
    foo:
      type: string
      enum:
        - One
        - Two
        - Three
Generation Details
openapi-generator-cli generate -g python -i sample.yaml -o ./python_client
Steps to reproduce

Run the command above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant