Search code examples
javaopenapi-generatoropenapi-generator-cli

ClassCastException When Generating Python Client with OpenAPI Generator


I'm currently working on a project where I need to generate a Python client for the Allegro API. However, I'm encountering a ClassCastException when the generator tries to handle a UUID. It seems like the generator is trying to cast a UUID to a string, but it's failing. I've tried looking for solutions online, but haven't found anything that works yet.

The command I'm using to generate the client (7.0.0 version):

openapi-generator-cli generate -g python -i https://developer.allegro.pl/swagger.yaml -o /home/user/client

Error message:

Exception in thread "main" java.lang.RuntimeException: Could not process operation:
  Tag: class Tag {
    name: Advance Ship Notices
    description: null
    externalDocs: null
}
  Operation: deleteAdvanceShipNotice
  Resource: delete /fulfillment/advance-ship-notices/{id}
  Schemas: {BillingEntries=class ObjectSchema {
    class Schema {
(...)

}}
  Exception: class java.util.UUID cannot be cast to class java.lang.String (java.util.UUID and java.lang.String are in module java.base of loader 'bootstrap')
    at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1225)
    at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1120)
    at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:590)
    at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:953)
    at org.openapitools.codegen.cmd.Generate.execute(Generate.java:511)
    at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32)
    at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66)
Caused by: java.lang.ClassCastException: class java.util.UUID cannot be cast to class java.lang.String (java.util.UUID and java.lang.String are in module java.base of loader 'bootstrap')
    at org.openapitools.codegen.languages.AbstractPythonCodegen.toDefaultValue(AbstractPythonCodegen.java:185)
    at org.openapitools.codegen.DefaultCodegen.toDefaultValue(DefaultCodegen.java:2261)
    at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:4129)
    at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:3841)
    at org.openapitools.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:5116)
    at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:4636)
    at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1193)
    ... 6 more

And here's the relevant part of swagger:

/fulfillment/advance-ship-notices/{id}/labels:
  get:
    summary: 'Get labels for Advance Ship Notice'
    description: 'Use this resource to get labels for Advance Ship Notice after being created with "create labels command".'
    tags:
      - Advance Ship Notices
    operationId: getAdvanceShipNoticeLabels
    parameters:
      - name: id
        in: path
        description: An identifier of the Advance Ship Notice.
        required: true
        schema:
          type: string
          format: uuid
        example: 84529ad2-2265-4e15-b76b-c17025d848f6
      - name: accept
        in: header
        description: Content-type of generated labels
        required: true
        schema:
          type: string
          enum:
            - application/pdf
            - x-application/zpl

Any ideas what can be the issue? The mentioned specification goes through OpenAPI validatiors without errors.


Solution

  • The issue has been fixed in the latest master via https://github.com/OpenAPITools/openapi-generator/pull/16432.

    You can give it a try using the SNAPSHOT version: https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.0.1-SNAPSHOT/