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] Regression on UUID types #2209

Closed
5 of 6 tasks
dojeda opened this issue Feb 21, 2019 · 10 comments · Fixed by #2213
Closed
5 of 6 tasks

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

dojeda opened this issue Feb 21, 2019 · 10 comments · Fixed by #2213

Comments

@dojeda
Copy link

dojeda commented Feb 21, 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

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
@auto-labeler
Copy link

auto-labeler bot commented Feb 21, 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.

@dojeda
Copy link
Author

dojeda commented Feb 21, 2019

After a git bisect, I pinned down this regression to 539ec23 by @spacether and its associated PR: #1776

@wing328
Copy link
Member

wing328 commented Feb 22, 2019

@dojeda thanks for reporting the issue and doing a "git bisect" to identify the associated PR, I'll take a look later today.

@wing328
Copy link
Member

wing328 commented Feb 22, 2019

@dojeda I've filed #2213 to fix the issue. Tested with your spec and no NPE was thrown.

➜  openapi-generator git:(fix_example) java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g python -i /tmp/example.yaml -o /tmp/example/
[main] WARN  o.o.c.ignore.CodegenIgnoreProcessor - Output directory does not exist, or is inaccessible. No file (.openapi-generator-ignore) will be evaluated.
[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/]
[main] INFO  o.o.codegen.DefaultGenerator - Model inline_object (marked as unused due to form parameters) is generated due to skipFormModel=false (default)
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/models/base_metadata.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/test/test_base_metadata.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/docs/BaseMetadata.md
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/models/inline_object.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/test/test_inline_object.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/docs/InlineObject.md
[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] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/api/default_api.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/test/test_default_api.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/docs/DefaultApi.md
[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] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/README.md
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/tox.ini
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/test-requirements.txt
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/requirements.txt
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/git_push.sh
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/.gitignore
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/.travis.yml
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/setup.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/configuration.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/__init__.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/models/__init__.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/api/__init__.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/test/__init__.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/api_client.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/openapi_client/rest.py
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/.openapi-generator-ignore
[main] INFO  o.o.codegen.AbstractGenerator - writing file /tmp/example/.openapi-generator/VERSION

Btw, there're some warnings that you may want to take a look.

@dojeda
Copy link
Author

dojeda commented Feb 22, 2019

Excellent! Thanks a lot for your help. I've tried #1776 and it did work great.

Thanks for the warning on the warnings; I stripped down most of my specification to keep it as small as possible, but by doing so I removed some general info.

@wing328 wing328 added this to the 4.0.0 milestone Feb 22, 2019
@wing328
Copy link
Member

wing328 commented Feb 22, 2019

The fix has been merged into master. Please pull the latest to give it a try.

@karismann
Copy link
Contributor

@wing328 We still have the issue in the last 4.0.0-SNAPSHOT (63eb929)
That must explain the shippable error on build

java -jar ./modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g r -o /tmp/openap i-generator-test-fake-petstore/2.0/r

Exception in thread "main" java.lang.RuntimeException: Could not process model 'format_test'.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.RClientCodegen.toDefaultValue(RClientCodegen.java:598) at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:1907) at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:3503) at org.openapitools.codegen.DefaultCodegen.addVars(DefaultCodegen.java:3451) at org.openapitools.codegen.DefaultCodegen.fromModel(DefaultCodegen.java:1777) at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1138) at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:449)

@wing328
Copy link
Member

wing328 commented Feb 25, 2019

Checking...

@wing328
Copy link
Member

wing328 commented Feb 25, 2019

@karismann I've filed #2231 to fix it.

@wing328
Copy link
Member

wing328 commented Feb 25, 2019

UPDATE: issue with the R generator has been fixed via #2231

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.

3 participants