We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
If I define a schema that has a UUID property, and that property has a default value, the csharp code generator throws a ClassCastException.
6.0.0
https://gist.github.com/alekskuc/ebd082d005b735caf7d018c779beb1ae
java -jar openapi-generator-cli.jar generate -i swagger.yaml -g csharp -o Api_2022-06-15-130401 [main] INFO o.o.codegen.DefaultGenerator - Generating with dryRun=false [main] INFO o.o.c.ignore.CodegenIgnoreProcessor - No .openapi-generator-ignore file found. [main] INFO o.o.codegen.DefaultGenerator - OpenAPI Generator: csharp (client) [main] INFO o.o.codegen.DefaultGenerator - Generator 'csharp' is considered stable. [main] INFO o.o.c.l.AbstractCSharpCodegen - Environment variable CSHARP_POST_PROCESS_FILE not defined so the C# code may not be properly formatted by uncrustify (0.66 or later) or other code formatter. To define it, try `export CSHARP_POST_PROCESS_FILE="/usr/local/bin/uncrustify --no-backup" && export UNCRUSTIFY_CONFIG=/path/to/uncrustify-rules.cfg` (Linux/Mac). Note: replace /path/to with the location of uncrustify-rules.cfg [main] INFO o.o.c.l.AbstractCSharpCodegen - NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` (--enable-post-process-file for CLI). [main] INFO o.o.c.languages.CSharpClientCodegen - Generating code for .NET Framework v4.5 [main] INFO o.o.codegen.TemplateManager - writing file \Api_2022-06-15-130401\src\Org.OpenAPITools\Model\Pet.cs [main] INFO o.o.codegen.TemplateManager - writing file \Api_2022-06-15-130401\src\Org.OpenAPITools.Test\Model\PetTests.cs [main] INFO o.o.codegen.TemplateManager - writing file \Api_2022-06-15-130401\docs\Pet.md Exception in thread "main" java.lang.RuntimeException: Could not process operation: Tag: class Tag { name: default description: null externalDocs: null } Operation: find pet by id Resource: get /pets/{id} Schemas: {Pet=class ObjectSchema { class Schema { type: object format: null $ref: null description: null title: null multipleOf: null maximum: null exclusiveMaximum: null minimum: null exclusiveMinimum: null maxLength: null minLength: null pattern: null maxItems: null minItems: null uniqueItems: null maxProperties: null minProperties: null required: [id] not: null properties: {id=class UUIDSchema { class Schema { type: string format: uuid $ref: null description: null title: null multipleOf: null maximum: null exclusiveMaximum: null minimum: null exclusiveMinimum: null maxLength: null minLength: null pattern: null maxItems: null minItems: null uniqueItems: null maxProperties: null minProperties: null required: null not: null properties: null additionalProperties: null nullable: null readOnly: null writeOnly: null example: null externalDocs: null deprecated: null discriminator: null xml: null } }} additionalProperties: null nullable: null readOnly: null writeOnly: null example: {id=046b6c7f-0b8a-43b9-b35d-6489e6daee91} externalDocs: null deprecated: null discriminator: null xml: null } }} Exception: java.util.UUID cannot be cast to java.lang.String at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1167) at org.openapitools.codegen.DefaultGenerator.processPaths(DefaultGenerator.java:1058) at org.openapitools.codegen.DefaultGenerator.generateApis(DefaultGenerator.java:553) at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:895) at org.openapitools.codegen.cmd.Generate.execute(Generate.java:449) at org.openapitools.codegen.cmd.OpenApiGeneratorCommand.run(OpenApiGeneratorCommand.java:32) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:66) Caused by: java.lang.ClassCastException: java.util.UUID cannot be cast to java.lang.String at org.openapitools.codegen.languages.AbstractCSharpCodegen.toDefaultValue(AbstractCSharpCodegen.java:983) at org.openapitools.codegen.DefaultCodegen.fromProperty(DefaultCodegen.java:3507) at org.openapitools.codegen.DefaultCodegen.fromParameter(DefaultCodegen.java:4626) at org.openapitools.codegen.DefaultCodegen.fromOperation(DefaultCodegen.java:4162) at org.openapitools.codegen.DefaultGenerator.processOperation(DefaultGenerator.java:1135) ... 6 more
Try to generate csharp code
java -jar openapi-generator-cli.jar generate -i swagger.yaml -g csharp
using spec in file https://gist.github.com/alekskuc/ebd082d005b735caf7d018c779beb1ae
#3516
Replace line 983 in AbstractCSharpCodegen.java
String _default = (String) p.getDefault();
With
String _default = p.getDefault().toString();
The text was updated successfully, but these errors were encountered:
@alekskuc thanks for reporting the issue. Can you please file a PR with the suggested fix?
Sorry, something went wrong.
@wing328 I've tried to file a PR but it turns out currently I can't do it.
Please delete this PR #12640 branch and file changes only in the AbstractCSharpCodegen.java file.
Successfully merging a pull request may close this issue.
Bug Report Checklist
Description
If I define a schema that has a UUID property, and that property has a default value, the csharp code generator throws a ClassCastException.
openapi-generator version
6.0.0
OpenAPI declaration file content or url
https://gist.github.com/alekskuc/ebd082d005b735caf7d018c779beb1ae
Generation Details
Steps to reproduce
Try to generate csharp code
java -jar openapi-generator-cli.jar generate -i swagger.yaml -g csharp
using spec in file
https://gist.github.com/alekskuc/ebd082d005b735caf7d018c779beb1ae
Related issues/PRs
#3516
Suggest a fix
Replace line 983 in AbstractCSharpCodegen.java
With
The text was updated successfully, but these errors were encountered: