OpenAPITools / OpenAPITools/openapi-generator
[protobuf-schema] Error trying to generate schema with an Enum list of integers
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
we try to generate a protobuf-schema but we have this error:
Exception in thread "main" java.lang.RuntimeException: Could not process model 'Event'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:518)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:912)
at org.openapitools.codegen.cmd.Generate.execute(Generate.java:465)
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.lang.Integer incompatible with java.lang.String
at org.openapitools.codegen.languages.ProtobufSchemaCodegen.addEnumValuesPrefix(ProtobufSchemaCodegen.java:239)
at org.openapitools.codegen.languages.ProtobufSchemaCodegen.postProcessModels(ProtobufSchemaCodegen.java:321)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1322)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:513)
I think it is because in our model we have something like this:
severity:
description: >
Indicates the event severity level
type: integer
enum:
- 1
- 2
- 3
- 4
- 5
- 6
This is probably because the code implies this is a string and not an int here:
Note that java and others ( javascript, python) do not fail with the same schema
openapi-generator version
Version 2.5.2
OpenAPI declaration file content or url
See description
Command line used for generation
${ROOT_DIR}/node_modules/.bin/openapi-generator-cli generate \
-g "$target" \
-i "${ROOT_DIR}/models/all.schema.yaml" \
-p library=native \
-o ${ROOT_DIR}/dist/$target \
$config
with $target = protobuf-schema
Steps to reproduce
Run the command to generate a schema that has a enum list of integers
Related issues/PRs
Same area as #7168
Suggest a fix/enhancement
This is probably because the code implies this is a string and not an int here:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ProtobufSchemaCodegen.java at addEnumValuesPrefix, then reproduce the failure with the provided protobuf-schema generation command and integer enum. Check how postProcessModels passes enum values, and consider the issue done when a schema with enum values 1 through 6 generates without the ClassCastException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100