Skip to content

Commit

Permalink
[18929] fix missing JsonIgnorePropertiesimport in oneOf interface file
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrej-simon committed Jul 1, 2024
1 parent 21d3cfe commit 69867ac
Show file tree
Hide file tree
Showing 185 changed files with 12,453 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ private boolean shouldBeImplicitHeader(CodegenParameter parameter) {
@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
if (jackson) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo")) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
Map<String, String> oneImport = new HashMap<>();
oneImport.put("import", importMapping.get(i));
if (!imports.contains(oneImport)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1155,17 +1155,6 @@ public String toApiVarName(String name) {
return apiVarName;
}

@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
Map<String, String> oneImport = new HashMap<>();
oneImport.put("import", importMapping.get(i));
if (!imports.contains(oneImport)) {
imports.add(oneImport);
}
}
}

@Override
public List<VendorExtension> getSupportedVendorExtensions() {
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -488,17 +487,6 @@ public String toApiVarName(String name) {
return apiVarName;
}

@Override
public void addImportsToOneOfInterface(List<Map<String, String>> imports) {
for (String i : Arrays.asList("JsonSubTypes", "JsonTypeInfo", "JsonIgnoreProperties")) {
Map<String, String> oneImport = new HashMap<>();
oneImport.put("import", importMapping.get(i));
if (!imports.contains(oneImport)) {
imports.add(oneImport);
}
}
}

@Override
public List<VendorExtension> getSupportedVendorExtensions() {
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5103,4 +5103,14 @@ public void testEnumUnknownDefaultCaseDeserializationNotSet_issue13241() throws
.assertMethod("build")
.doesNotHaveAnnotation("Deprecated");
}

@Test
public void shouldAddJsonIgnorePropertiesImportWhenUsingOneOfWithinOneOf_issue18929() throws IOException {
final SpringCodegen codegen = new SpringCodegen();

final Map<String, File> files = generateFiles(codegen, "src/test/resources/3_0/spring/issue_18929.yaml");

JavaFileAssert.assertThat(files.get("RequestTwoSchemaNestedOneOf.java"))
.hasImports("com.fasterxml.jackson.annotation.JsonIgnoreProperties");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
openapi: 3.0.3
info:
title: oneOf within oneOf
version: 7.7.0-SNAPSHOT
paths:
/oneOf-within-oneOf-test:
post:
operationId: 'oneOfWithinOneOfTest'
requestBody:
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/RequestTwoSchema'
- $ref: '#/components/schemas/RequestOneSchema'
responses:
'201':
description: The request was successful and the resource has been created.
content:
application/json:
schema:
type: string
components:
schemas:
AbstractNestedSchema:
type: object
discriminator:
propertyName: type
mapping:
NESTED_ONE: '#/components/schemas/NestedOneSchema'
NESTED_TWO: '#/components/schemas/NestedTwoSchema'
required:
- type
properties:
type:
type: string
NestedOneSchema:
type: object
allOf:
- $ref: '#/components/schemas/AbstractNestedSchema'
AbstractRequestSchema:
type: object
discriminator:
propertyName: type
mapping:
REQUEST_ONE: '#/components/schemas/RequestOneSchema'
REQUEST_TWO: '#/components/schemas/RequestTwoSchema'
required:
- type
properties:
type:
type: string
RequestTwoSchema:
type: object
allOf:
- $ref: '#/components/schemas/AbstractRequestSchema'
required:
- nested
properties:
nested:
oneOf:
- $ref: '#/components/schemas/NestedTwoSchema'
- $ref: '#/components/schemas/NestedOneSchema'
RequestOneSchema:
type: object
allOf:
- $ref: '#/components/schemas/AbstractRequestSchema'
NestedTwoSchema:
type: object
allOf:
- $ref: '#/components/schemas/AbstractNestedSchema'
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,27 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/ResponseObjectWithDifferentFieldNames"
/fake/one-of-within-one-of-park-persons:
post:
tags:
- PerkPerson
summary: Create a Park Person
operationId: createParkPerson
requestBody:
required: true
content:
'application/json':
schema:
oneOf:
- $ref: '#/components/schemas/CreateParkAnimalCarerPerson'
- $ref: '#/components/schemas/CreateParkVisitorPerson'
responses:
201:
description: Park Person created
content:
'application/json':
schema:
type: string
servers:
- url: http://petstore.swagger.io:80/v2
components:
Expand Down Expand Up @@ -2096,3 +2117,50 @@ components:
type: object
additionalProperties:
type: string
OneOfWithinOneOfAbstractAnimal:
type: object
discriminator:
propertyName: type
mapping:
CAT: '#/components/schemas/Cat'
NESTED_TWO: '#/components/schemas/Dog'
required:
- type
properties:
type:
type: string
OneOfWithinOneOfCat:
type: object
allOf:
- $ref: '#/components/schemas/OneOfWithinOneOfAbstractAnimal'
AbstractCreateParkPerson:
type: object
discriminator:
propertyName: type
mapping:
VISITOR: '#/components/schemas/CreateParkVisitorPerson'
ANIMAL_CARER: '#/components/schemas/CreateParkAnimalCarerPerson'
required:
- type
properties:
type:
type: string
CreateParkAnimalCarerPerson:
type: object
allOf:
- $ref: '#/components/schemas/AbstractCreateParkPerson'
required:
- responsibleFor
properties:
responsibleFor:
oneOf:
- $ref: '#/components/schemas/OneOfWithinOneOfDog'
- $ref: '#/components/schemas/OneOfWithinOneOfCat'
CreateParkVisitorPerson:
type: object
allOf:
- $ref: '#/components/schemas/AbstractCreateParkPerson'
OneOfWithinOneOfDog:
type: object
allOf:
- $ref: '#/components/schemas/OneOfWithinOneOfAbstractAnimal'
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ pom.xml
src/main/java/org/openapitools/api/AnotherFakeApi.java
src/main/java/org/openapitools/api/FakeApi.java
src/main/java/org/openapitools/api/FakeClassnameTags123Api.java
src/main/java/org/openapitools/api/PerkPersonApi.java
src/main/java/org/openapitools/api/PetApi.java
src/main/java/org/openapitools/api/StoreApi.java
src/main/java/org/openapitools/api/UserApi.java
src/main/java/org/openapitools/configuration/HttpInterfacesAbstractConfigurator.java
src/main/java/org/openapitools/model/AbstractCreateParkPerson.java
src/main/java/org/openapitools/model/AdditionalPropertiesAnyType.java
src/main/java/org/openapitools/model/AdditionalPropertiesArray.java
src/main/java/org/openapitools/model/AdditionalPropertiesBoolean.java
Expand All @@ -27,6 +29,10 @@ src/main/java/org/openapitools/model/ChildWithNullable.java
src/main/java/org/openapitools/model/ClassModel.java
src/main/java/org/openapitools/model/Client.java
src/main/java/org/openapitools/model/ContainerDefaultValue.java
src/main/java/org/openapitools/model/CreateParkAnimalCarerPerson.java
src/main/java/org/openapitools/model/CreateParkAnimalCarerPersonResponsibleForOneOf.java
src/main/java/org/openapitools/model/CreateParkPersonRequest.java
src/main/java/org/openapitools/model/CreateParkVisitorPerson.java
src/main/java/org/openapitools/model/Dog.java
src/main/java/org/openapitools/model/EnumArrays.java
src/main/java/org/openapitools/model/EnumClass.java
Expand All @@ -44,6 +50,9 @@ src/main/java/org/openapitools/model/ModelReturn.java
src/main/java/org/openapitools/model/Name.java
src/main/java/org/openapitools/model/NullableMapProperty.java
src/main/java/org/openapitools/model/NumberOnly.java
src/main/java/org/openapitools/model/OneOfWithinOneOfAbstractAnimal.java
src/main/java/org/openapitools/model/OneOfWithinOneOfCat.java
src/main/java/org/openapitools/model/OneOfWithinOneOfDog.java
src/main/java/org/openapitools/model/Order.java
src/main/java/org/openapitools/model/OuterComposite.java
src/main/java/org/openapitools/model/OuterEnum.java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech) (7.7.0-SNAPSHOT).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package org.openapitools.api;

import org.openapitools.model.CreateParkPersonRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.service.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import org.springframework.http.codec.multipart.Part;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.annotation.Generated;


@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.7.0-SNAPSHOT")
public interface PerkPersonApi {

/**
* POST /fake/one-of-within-one-of-park-persons : Create a Park Person
*
* @param createParkPersonRequest (required)
* @return Park Person created (status code 201)
*/
@HttpExchange(
method = "POST",
value = "/fake/one-of-within-one-of-park-persons",
accept = { "application/json" },
contentType = "application/json"
)
Mono<ResponseEntity<String>> createParkPerson(
@RequestBody Mono<CreateParkPersonRequest> createParkPersonRequest
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.openapitools.api.AnotherFakeApi;
import org.openapitools.api.FakeApi;
import org.openapitools.api.FakeClassnameTags123Api;
import org.openapitools.api.PerkPersonApi;
import org.openapitools.api.PetApi;
import org.openapitools.api.StoreApi;
import org.openapitools.api.UserApi;
Expand Down Expand Up @@ -43,6 +44,12 @@ FakeClassnameTags123Api fakeClassnameTags123HttpProxy() {
return factory.createClient(FakeClassnameTags123Api.class);
}

@Bean(name = "org.openapitools.configuration.HttpInterfacesAbstractConfigurator.perkPerson")
PerkPersonApi perkPersonHttpProxy() {
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build();
return factory.createClient(PerkPersonApi.class);
}

@Bean(name = "org.openapitools.configuration.HttpInterfacesAbstractConfigurator.pet")
PetApi petHttpProxy() {
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builder(WebClientAdapter.forClient(webClient)).build();
Expand Down
Loading

0 comments on commit 69867ac

Please sign in to comment.