Invalid code generated for missing discriminator property, but validation passes
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the issue with test2.json and rpdmcpp.config by running the shown validate and generate commands, then inspect the generated Base.java. Trace the validation path for the discriminator property; done means validation reports the missing property instead of accepting the spec that produces non-compiling Java code.
Written by the indexing model from the issue text.
Description
Description
A spec with missing discriminator property passes validation, but generates invalid (Java) code.
openapi-generator version
3.3.0-SNAPSHOT
OpenAPI declaration file content or url
{
"openapi": "3.0.0",
"info": {
"description": "blah",
"version": "1.0.0",
"title": "blah"
},
"paths": {
"/test": {
"post": {
"tags": [
"test"
],
"operationId": "testOp",
"responses": {
"405": {
"description": "Invalid input"
}
},
"requestBody": {
"$ref": "#/components/requestBodies/Test"
}
}
}
},
"components": {
"requestBodies": {
"Test": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Test"
}
}
}
}
},
"schemas": {
"Base": {
"properties": {
"status": {
"type": "string"
}
},
"discriminator":{
"propertyName": "type"
}
},
"Test": {
"allOf":[
{ "$ref": "#/components/schemas/Base" },
{
"type":"object",
"properties": {
"name": {
"type": "string"
}
}
}
]
}
}
}
}
rpdmcpp.config is
{
"declspec" : "DL_GLOBAL_CLASS",
"appName" : "RPDM",
"appDescription" : "RedPoint Data Management services"
}
Command line used for generation
Validate succeeds
java -cp openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator validate -i test2.json
Validating spec (test2.json)
No validation issues detected.
But java code generation:
java -cp openapi-generator-cli.jar org.openapitools.codegen.OpenAPIGenerator generate -v -o genjava -g java -i test2.json -c rpdmcpp.config
produces non-compiling code. The problem is that the type field is not defined. In Base.java:
public Base() {
this.type = this.getClass().getSimpleName();
}
Suggest a fix/enhancement
Validation should flag the spec as being in error.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 100
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.
More from OpenAPITools/openapi-generator
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenAPITools/openapi-generator#24859 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24852 · 1 comment ·
-
[BUG][KOTLIN] Fails to compile after updating to 7.25.0 with useJackson3=false useSpringBoot4=true OpenIssue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
OpenAPITools/openapi-generator#24842 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
OpenAPITools/openapi-generator#24830 ·
-
Issue: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
OpenAPITools/openapi-generator#24816 · 1 comment ·
All issues in OpenAPITools/openapi-generator
Similar issues
-
Bug Java Platform: Java
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
getsentry/sentry-java#6138 · 1 comment ·
-
bug needs triage p2
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100