[BUG] Missing Java Bean Validation annotations when using `allOf` instead of $ref directly
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you search for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using:
components:
schemas:
Name:
type: string
maxLength: 50
minLength: 1
description: "A name"
Cat:
type: object
description: "A cat with a name"
properties:
name:
allOf:
- $ref: '#/components/schemas/Name'
description: "Name of this cat"
example: "Kitty"
The generated code is:
@ApiModelProperty(example = "Kitty", value = "Name of this cat")
public String getName() {
return name;
}
Instead of:
@ApiModelProperty(example = "Kitty", value = "Name of this cat")
@Size(min=1,max=50)
public String getName() {
return name;
}
openapi-generator version
OpenAPI Generator 4.3.1 and 5.0.0-alpha.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: My animal API
version: "1.0"
servers:
- url: https://api.example.com
paths:
/cats/:
post:
operationId: createCat
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
responses:
201:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/Cat'
/dogs/:
post:
operationId: createDog
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Dog'
responses:
201:
description: ""
content:
application/json:
schema:
$ref: '#/components/schemas/Dog'
components:
schemas:
Name:
type: string
maxLength: 50
minLength: 1
description: "A name"
Cat:
type: object
description: "A cat with a name"
properties:
name:
allOf:
- $ref: '#/components/schemas/Name'
description: "Name of this cat"
example: "Kitty"
Dog:
type: object
description: "A dog with a name"
properties:
name:
allOf:
- $ref: '#/components/schemas/Name'
description: "Name of this dog"
example: "Fido"
Generation Details
Plugin configuration:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.1</version>
<executions>
<execution>
<id>code-from-openapi-document</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/spec.yaml</inputSpec>
<generatorName>spring</generatorName>
<library>spring-boot</library>
<apiPackage>com.acme.animals.controller</apiPackage>
<modelPackage>com.acme.animals.dto</modelPackage>
<generateApis>true</generateApis>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<dateLibrary>java8</dateLibrary>
<enableBuilderSupport>true</enableBuilderSupport>
<skipDefaultInterface>true</skipDefaultInterface>
<performBeanValidation>true</performBeanValidation>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
- Run
mvn clean generate-sources
- The generated classes contain:
@ApiModelProperty(example = "Kitty", value = "Name of this cat")
public String getName() {
return name;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:7
Top Results From Across the Web
Annotations from javax.validation.constraints not working
In my case, I was missing @Valid in the API that receives the Object (a POJO in my case) that was annotated with...
Read more >Java Bean Validation Basics - Baeldung
Learn the basics of Java Bean validation, the common annotations and how to trigger the validation process.
Read more >Better error messages with Bean Validation 1.1 in Spring MVC ...
Bean Validation 1.1, among many new features, introduced error message interpolation using Unified Expression Language (EL) expressions.
Read more >Generate Server Code Using OpenAPI Generator
In this blog, you will learn how to generate server code using the OpenAPI Generator based on an OpenAPI specification.
Read more >Validation Loop error occurred when allOf used with ...
I send an invalid basket with an orange ( originCountry is missing), I do not get a proper validation error as I do...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We have just encountered this issue (or a very closely related one) via the Maven plugin,
openapi-generator-maven-plugin
v5.1.1 & 5.2.0 - Spring generator. We are missing the@Pattern
annotation (andexample
attribute in@ApiModelProperty
) on theagreementID
property in our generatedAgreementDetails
class, where pattern is specified on the referenced base simple typeAgreementId
, e.g.Still seeing this issue with OpenAPI Generator 5.2.0