Bug Report Checklist
Description
If the body parameter is required: true and nullable: true the generated code throws an error if one passes null
openapi-generator version
7.22-SNAPSHOT
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "RSD Test",
"version": "1.0.0"
},
"paths": {
"/sample": {
"post": {
"tags": [
"BodyParameterTypes"
],
"description": "",
"parameters": [],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "boolean",
"nullable": true
}
}
},
"required": true
},
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "boolean"
}
}
}
}
}
}
}
}
}
Generation Details
docker run --rm \
-v $PWD:/local openapitools/openapi-generator-cli:latest generate \
-i /local/openapi.json \
-g typescript-fetch --additional-properties=importFileExtension=.js \
-o /local/src
Steps to reproduce
- run the generator
- inspect the generated source / try to run it and invoke the method with
null and you get a RequiredError thrown
If you inspect the source code you see
async samplePostRequestOpts(requestParameters: SamplePostRequest): Promise<runtime.RequestOpts> {
if (requestParameters['body'] == null) {
throw new runtime.RequiredError(
'body',
'Required parameter "body" was null or undefined when calling samplePost().'
);
}
...
which is obviously wrong as body can be null according to the spec above.
Related issues/PRs
Not that I'm aware of
Suggest a fix
The generator needs to check if the value in body can be null and then although it is required omit generating the above code.
Bug Report Checklist
Description
If the body parameter is
required: trueandnullable: truethe generated code throws an error if one passesnullopenapi-generator version
7.22-SNAPSHOT
OpenAPI declaration file content or url
{ "openapi": "3.0.1", "info": { "title": "RSD Test", "version": "1.0.0" }, "paths": { "/sample": { "post": { "tags": [ "BodyParameterTypes" ], "description": "", "parameters": [], "requestBody": { "content": { "application/json": { "schema": { "type": "boolean", "nullable": true } } }, "required": true }, "responses": { "200": { "description": "", "content": { "application/json": { "schema": { "type": "boolean" } } } } } } } } }Generation Details
Steps to reproduce
nulland you get a RequiredError thrownIf you inspect the source code you see
which is obviously wrong as body can be
nullaccording to the spec above.Related issues/PRs
Not that I'm aware of
Suggest a fix
The generator needs to check if the value in body can be
nulland then although it isrequiredomit generating the above code.