Skip to content

[BUG] [Python] Regression on UUID types #2209

@dojeda

Description

@dojeda

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

A regression on v4.0.0-beta2 or latest fails during code generation when a

openapi-generator version

v4.0.0-beta2

OpenAPI declaration file content or url
---
openapi: 3.0.2

info:
  title: My API
  version: 0.1.0
  description: Some description

paths:
  /files/:
    post:
      summary: Upload file.
      operationId: upload_file
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file_content:
                  type: string
                  format: binary
      responses:
        '201':
          $ref: '#/components/responses/FileDetails'
components:
  schemas:
    BaseMetadata:
      type: object
      required:
        - id
        - url
      properties:
        id:
          description: File identifier.
          type: string
          format: uuid
          example: d06861a5-a14c-449c-bc9a-8f547186286a
        url:
          description: File URL
          type: string
          format: url
          example: gs://data-bucket/d06861a5-a14c-449c-bc9a-8f547186286a

  responses:
    FileDetails:
      description: File details.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/BaseMetadata'
Command line used for generation

The following command fails:

$ docker run --rm -v $PWD/tmp:/local openapitools/openapi-generator-cli:v4.0.0-beta2 generate -i /local/bug.yaml -g python -o /tmp/

[main] INFO  o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found.
[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] WARN  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.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/]
Exception in thread "main" java.lang.RuntimeException: Could not process model 'BaseMetadata'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:454)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:897)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:354)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
Caused by: java.lang.ClassCastException: java.util.UUID cannot be cast to java.lang.String
        at org.openapitools.codegen.languages.PythonClientCodegen.toDefaultValue(PythonClientCodegen.java:657)
        at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:1878)
        at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:3449)
        at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:3397)
        at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1748)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1138)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:449)

However, the previous version succeeds:

docker run --rm -v $PWD/tmp:/local openapitools/openapi-generator-cli:v4.0.0-beta generate -i /local/bug.yaml -g python -o /tmp/
... no errors ...
Steps to reproduce
  1. Download minimum working example
  2. Run docker image to generate code with v4.0.0-beta2 tag or latest as shown on the example above.
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions