Description
In my operation definition, I have a requestBody with required: true. However, the generated code makes the parameter in the controller and subsequent service optional.
openapi-generator version
I tried 3.3.4 and current master
OpenAPI declaration file content or url
Spec:
paths:
/sysmails/{key}:
parameters:
- name: keyin: pathrequired: trueschema:
$ref: "#/components/parameters/SysMailKey"put:
operationId: updateSysMailAtKeydescription: Update SysMail templaterequestBody:
description: Template datarequired: truecontent:
application/json:
schema:
title: SysMailFormDatadescription: Data to update a SysMail template.type: objectrequired:
- subject
- bodyproperties:
subject:
$ref: "#/components/schemas/SysMailSubject"body:
$ref: "#/components/schemas/SysMailBody"Generated code:
@RequestMapping(
value = ["/sysmails/{key}"],
produces = ["application/json"], consumes = ["application/json"],
method = [RequestMethod.PUT])
funupdateSysMailAtKey( @PathVariable("key") key:String, @Valid @RequestBody sysMailFormData:SysMailFormData?): ResponseEntity<SysMail> {
returnResponseEntity(service.updateSysMailAtKey(key, sysMailFormData), HttpStatus.OK)
}Parameter SysMailFormData is optional, which it shouldn't.
Command line used for generation
java -jar openapi-generator-cli.jar \
generate \
--input-spec ./sysmails-1.x.yml \
--output ../ \
--generator-name kotlin-spring \
--config config.kotlin.json \
--enable-post-process-file \
--model-name-suffix Dto
config.kotlin.json
{
"serviceInterface": true,
"swaggerAnnotations": false,
"serviceImplementation": true,
"gradleBuildFile": false
}Steps to reproduce
Run generator with configuration above
Related issues/PRs
Here someone reported the other way round: required:false resulted in non-optional parameters.
#1106
Suggest a fix/enhancement
The code template should be adjusted.
Description
In my operation definition, I have a requestBody with
required: true. However, the generated code makes the parameter in the controller and subsequent service optional.openapi-generator version
I tried 3.3.4 and current master
OpenAPI declaration file content or url
Spec:
Generated code:
Parameter SysMailFormData is optional, which it shouldn't.
Command line used for generation
config.kotlin.json
{ "serviceInterface": true, "swaggerAnnotations": false, "serviceImplementation": true, "gradleBuildFile": false }Steps to reproduce
Run generator with configuration above
Related issues/PRs
Here someone reported the other way round: required:false resulted in non-optional parameters.
#1106
Suggest a fix/enhancement
The code template should be adjusted.