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][Python] UUID properties with default values trigger ClassCastException #3516

Open
5 of 6 tasks
alexras opened this issue Jul 31, 2019 · 5 comments
Open
5 of 6 tasks

Comments

@alexras
Copy link

alexras commented Jul 31, 2019

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

If I define a schema that has a UUID property, and that property has a default value, the Python code generator throws a ClassCastException.

openapi-generator version

4.0.3

OpenAPI declaration file content or url
---
components:
  schemas:
    MyModel:
      properties:
        id:
          default: "00000000-0000-4000-8000-000000000000"
          format: uuid
          type: string
      title: MyModel
      type: object

info:
  title: 'My API'
  version: 0.1.0dev

openapi: 3.0.2

paths: {}
Command line used for generation

docker run --rm -v ${PWD}:/local --env 'PYTHON_POST_PROCESS_FILE="/usr/local/bin/yapf -i"' openapitools/openapi-generator-cli:v4.0.3 generate -i /local/swagger.yml -g python -o /local/build

Steps to reproduce

Run the generator with the above declaration file; it will throw an exception that looks like this:

Exception in thread "main" java.lang.RuntimeException: Could not process model 'MyModel'.Please make sure that your schema is correct!
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:470)
        at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:920)
        at org.openapitools.codegen.cmd.Generate.run(Generate.java:396)
        at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
Caused by: java.lang.ClassCastException: java.util.UUID cannot be cast to java.lang.String
        at org.openapitools.codegen.languages.PythonClientCodegen.toDefaultValue(PythonClientCodegen.java:643)
        at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:1981)
        at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:3627)
        at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:3575)
        at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1845)
        at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1197)
        at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:465)
        ... 3 more

If you remove the default and run the generator again, code generation will succeed.

Related issues/PRs

#2209 - similar exception, with a different cause.

Suggest a fix

Rather than just casting to a string, perhaps just calling p.getDefault().toString() would work.

@auto-labeler
Copy link

auto-labeler bot commented Jul 31, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@Briggybros
Copy link

This is not specific to the python generator. I'm seeing the same problem in java, typescript-fetch, and typescript-axios.

@black-snow
Copy link

black-snow commented Sep 16, 2020

I second this. Trying to generate code for java. Models are being created but then it breaks with

Cause: 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')

/edit: runs fine when I comment all the format: uuid lines

@ccampanale
Copy link

This is still an issue with typescript and typescript-axios generators.

@spacether
Copy link
Contributor

We welcome a PR to fix this issue if anyone wants to file it

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

No branches or pull requests

5 participants