OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
When using oneOf for request of response schema, and the specialization contains oneOf as its property, the @JsonIgnoreProperties annotation is added but its import is not. Because of this, the source code cannot be compiled.
Generation was performed on the master branch of the openapi-generator project, pulled directly from this GitHub repository.
Steps to reproduce
Copy the yaml described above into modules/openapi-generator/src/test/resources/3_0/spring/oneof-within-oneof.yaml,
Add the following failing test to org.openapitools.codegen.java.spring.SpringCodegenTest, verifying the import is not added.
@Test
public void shouldAddJsonIgnorePropertiesAnnotationWhenUsingOneOfWithinOneOf() throws IOException {
final SpringCodegen codegen = new SpringCodegen();
final Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/spring/oneof-within-oneof.yaml");
JavaFileAssert.assertThat(files.get("RequestTwoSchemaNestedOneOf.java"))
.hasImports("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
}
Suggest a fix
The problem is within the following method: org.openapitools.codegen.languages.AbstractJavaCodegen#addImportsToOneOfInterface, where the import request for JsonIgnoreProperties is missing.
Incorrect:
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo")) {
Fixed version:
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
Description
When using oneOf for request of response schema, and the specialization contains oneOf as its property, the
@JsonIgnoreProperties
annotation is added but its import is not. Because of this, the source code cannot be compiled.openapi-generator version
7.7.0-SNAPSHOT
OpenAPI declaration file content or url
Generation Details
Generation was performed on the
master
branch of the openapi-generator project, pulled directly from this GitHub repository.Steps to reproduce
modules/openapi-generator/src/test/resources/3_0/spring/oneof-within-oneof.yaml
,org.openapitools.codegen.java.spring.SpringCodegenTest
, verifying the import is not added.Suggest a fix
The problem is within the following method:
org.openapitools.codegen.languages.AbstractJavaCodegen#addImportsToOneOfInterface
, where the import request forJsonIgnoreProperties
is missing.Incorrect:
Fixed version: