Invalid code generated for missing discriminator property, but validation passes
Created by: wheezil
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.