Bug Report Checklist
openapi-generator version
v4.2.2
OpenAPI declaration file content or url
My openapi.json specification:
{
"openapi": "3.0.2",
"info": {
"title": "test",
"version": "v1"
},
"paths": {
"/api/v1/average/height/": {
"post": {
"tags": [
"height",
"average"
],
"summary": "GetAverageHeight",
"description": "Getaverageheightatthespecifiedage.",
"operationId": "get_average_height_api_v1_average_height__post",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Person"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "SuccessfulResponse",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PersonHeight"
}
}
}
},
"422": {
"description": "ValidationError",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"AgeValue": {
"title": "AgeValue",
"required": [
"unit",
"value"
],
"type": "object",
"properties": {
"unit": {
"title": "Unit",
"enum": [
"month"
],
"type": "string"
},
"value": {
"title": "Value",
"maximum": 216.0,
"minimum": 0.0,
"type": "number",
"description": "Ageofperson."
}
}
},
"HTTPValidationError": {
"title": "HTTPValidationError",
"type": "object",
"properties": {
"detail": {
"title": "Detail",
"type": "array",
"items": {
"$ref": "#/components/schemas/ValidationError"
}
}
}
},
"HeightValue": {
"title": "HeightValue",
"required": [
"unit",
"value"
],
"type": "object",
"properties": {
"unit": {
"title": "Unit",
"enum": [
"cm"
],
"type": "string"
},
"value": {
"title": "Value",
"maximum": 300.0,
"minimum": 10.0,
"type": "number",
"description": "Valueoftheheight."
}
}
},
"Person": {
"title": "Person",
"required": [
"age"
],
"type": "object",
"properties": {
"age": {
"$ref": "#/components/schemas/AgeValue"
}
}
},
"PersonHeight": {
"title": "PersonHeight",
"required": [
"person",
"height"
],
"type": "object",
"properties": {
"person": {
"$ref": "#/components/schemas/Person"
},
"height": {
"$ref": "#/components/schemas/HeightValue"
}
}
},
"ValidationError": {
"title": "ValidationError",
"required": [
"loc",
"msg",
"type"
],
"type": "object",
"properties": {
"loc": {
"title": "Location",
"type": "array",
"items": {
"type": "string"
}
},
"msg": {
"title": "Message",
"type": "string"
},
"type": {
"title": "ErrorType",
"type": "string"
}
}
}
}
},
"servers": [
{
"url": "http://10.0.2.2:8000",
"description": "Justatestserver."
}
]
}
My flutterconfig-dart.json file:
{
"browserClient": false,
"useEnumExtension": true
}
Command line used for generation
java -jar .\openapi-generator-cli-4.2.2.jar generate -i .\openapi.json -g dart -o .\openapi-test -c flutterconfig-dart.json
Steps to reproduce
Just generate the code using the command line, and then open any model dart files, such as:
\openapi-test\lib\model\person.dart
There you can see that the constructor of the Person class is Person(); So no instantiation of the field age takes place.
So in order to use the Person class you would need to do:
Person person = new Person();
person.age = new AgeValue(); // This would be totally unnecessary, with the fix I suggest below.
Imagine how big this problem is, if you wanted to instantiate a class with deeply nested field of other classes.
Suggest a fix
Extend all generated constructors to instantiate all fields.
Bug Report Checklist
openapi-generator version
v4.2.2
OpenAPI declaration file content or url
My openapi.json specification:
{ "openapi": "3.0.2", "info": { "title": "test", "version": "v1" }, "paths": { "/api/v1/average/height/": { "post": { "tags": [ "height", "average" ], "summary": "GetAverageHeight", "description": "Getaverageheightatthespecifiedage.", "operationId": "get_average_height_api_v1_average_height__post", "requestBody": { "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Person" } } }, "required": true }, "responses": { "200": { "description": "SuccessfulResponse", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/PersonHeight" } } } }, "422": { "description": "ValidationError", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/HTTPValidationError" } } } } } } } }, "components": { "schemas": { "AgeValue": { "title": "AgeValue", "required": [ "unit", "value" ], "type": "object", "properties": { "unit": { "title": "Unit", "enum": [ "month" ], "type": "string" }, "value": { "title": "Value", "maximum": 216.0, "minimum": 0.0, "type": "number", "description": "Ageofperson." } } }, "HTTPValidationError": { "title": "HTTPValidationError", "type": "object", "properties": { "detail": { "title": "Detail", "type": "array", "items": { "$ref": "#/components/schemas/ValidationError" } } } }, "HeightValue": { "title": "HeightValue", "required": [ "unit", "value" ], "type": "object", "properties": { "unit": { "title": "Unit", "enum": [ "cm" ], "type": "string" }, "value": { "title": "Value", "maximum": 300.0, "minimum": 10.0, "type": "number", "description": "Valueoftheheight." } } }, "Person": { "title": "Person", "required": [ "age" ], "type": "object", "properties": { "age": { "$ref": "#/components/schemas/AgeValue" } } }, "PersonHeight": { "title": "PersonHeight", "required": [ "person", "height" ], "type": "object", "properties": { "person": { "$ref": "#/components/schemas/Person" }, "height": { "$ref": "#/components/schemas/HeightValue" } } }, "ValidationError": { "title": "ValidationError", "required": [ "loc", "msg", "type" ], "type": "object", "properties": { "loc": { "title": "Location", "type": "array", "items": { "type": "string" } }, "msg": { "title": "Message", "type": "string" }, "type": { "title": "ErrorType", "type": "string" } } } } }, "servers": [ { "url": "http://10.0.2.2:8000", "description": "Justatestserver." } ] }My flutterconfig-dart.json file:
{ "browserClient": false, "useEnumExtension": true }Command line used for generation
Steps to reproduce
Just generate the code using the command line, and then open any model dart files, such as:
\openapi-test\lib\model\person.dart
There you can see that the constructor of the
Personclass isPerson();So no instantiation of the fieldagetakes place.So in order to use the Person class you would need to do:
Imagine how big this problem is, if you wanted to instantiate a class with deeply nested field of other classes.
Suggest a fix
Extend all generated constructors to instantiate all fields.