Description
Description
I'm trying to generate some javax.validation annotations in my generated Spring API files. Most of the cases are working fine, but when I try to add a size validation on a request body which is a list of primitive type elements, by adding minItems
or maxItems
for example, the generated method does not contain the expected javax.validation @Size
annotation. Plus, I would also like to validate the length of each element inside my list
Actual:
ResponseEntity<Void> syncCars(@ApiParam(value = "" )
@Valid
@RequestBody List<String> requestBody);
Expected:
ResponseEntity<Void> syncCars(@Size(min=1,max=100)
@ApiParam(value = "" )
@Valid
@RequestBody List<@Size(min=5,max=100) String> requestBody);
or at least
ResponseEntity<Void> syncCars(@Size(min=1,max=100)
@ApiParam(value = "" )
@Valid
@RequestBody List<String> requestBody);
When I try this by manually modifying the generated interface, the validation works great and throw errors when I send an empty list or a list with string which is too short.
Additionally, I would like to know if OAS uniqueItems
property could, or should, generate anything else?
openapi-generator version
3.3.4 (maven plugin). I also tried the latest version, the result is the same
OpenAPI declaration file content or url
openapi: 3.0.0
servers:
- url: 'http://localhost:8080/'
info:
version: '1.0'
title: My Project
paths:
/cars/sync:
post:
tags:
- Cars
summary: test
operationId: syncCars
requestBody:
content:
application/json:
schema:
type: array
items:
type: string
minLength: 5
maxLength: 100
minItems: 1
maxItems: 100
uniqueItems: true
responses:
'200':
description: success
Command line used for generation
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>3.3.4</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api.yaml</inputSpec>
<generatorName>spring</generatorName>
<output>target/generated-sources</output>
<modelNameSuffix>Dto</modelNameSuffix>
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>my.api</apiPackage>
<modelPackage>my.api.dto</modelPackage>
<configOptions>
<sourceFolder>src/main/java/</sourceFolder>
<java8>false</java8>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>