Closed
Description
Bug 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 searched 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 allOf to combine a string type with additional metadata in an OpenAPI 3.0.3 spec, the openapi-generator-maven-plugin generates an empty class for the combined schema instead of applying the expected validations and attributes.
openapi-generator version
latest 7.11.0
7.12.0-SNAMPSHOT (the issue is still reproducible on master)
OpenAPI declaration file content or url
this is the a spec to reproduce it
openapi: 3.0.3
info:
version: 1.0.0
title: Test
paths:
/api/productRef:
get:
operationId: getProductRef
summary: Retrieve product reference
description: Returns a product reference based on a given product.
responses:
'200':
description: Successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/ProductType'
components:
schemas:
ProductType:
type: object
required:
- referenceNumber
properties:
referenceNumber:
$ref: "#/components/schemas/ReferenceNumber"
ReferenceNumber:
allOf:
- $ref: "#/components/schemas/IEAN8"
- description: Product Ref
- example: IEAN1234
IEAN8:
type: string
minLength: 8
maxLength: 8
example: "IEAN1234"
the plugin configuration
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>7.11.0</version>
<executions>
<execution>
<id>Test_v1</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<library>resttemplate</library>
<inputSpec>${project.basedir}/src/main/resources/openapi.yml</inputSpec>
<configOptions>
<dateLibrary>java8</dateLibrary>
<useBeanValidation>true</useBeanValidation>
<performBeanValidation>true</performBeanValidation>
<useJakartaEe>true</useJakartaEe>
</configOptions>
<generatorName>java</generatorName>
<modelPackage>com.test.model</modelPackage>
<apiPackage>com.test.api</apiPackage>
<invokerPackage>com.test.invoker</invokerPackage>
<generateModels>true</generateModels>
<generateApis>true</generateApis>
<generateModelDocumentation>false</generateModelDocumentation>
<generateApiDocumentation>false</generateApiDocumentation>
<generateModelTests>false</generateModelTests>
<generateApiTests>false</generateApiTests>
<generateAliasAsModel>false</generateAliasAsModel>
<generateSupportingFiles>true</generateSupportingFiles>
</configuration>
</execution>
</executions>
</plugin>
Generation Details
the generated class are
ProductType:
public class ProductType {
@jakarta.annotation.Nonnull
private ReferenceNumber referenceNumber;
//getter, setter ...
}
public class ReferenceNumber {
//no class attribute
public ReferenceNumber() {
}
}
While the expected result is
public class ProductType {
@jakarta.annotation.Nonnull
private String referenceNumber;
@jakarta.annotation.Nonnull
@NotNull
@Size(min=8,max=8)
@JsonProperty(JSON_PROPERTY_REFERENCE_NUMBER)
@JsonInclude(value = JsonInclude.Include.ALWAYS)
public String getReferenceNumber() {
return referenceNumber;
}
//setter
}