Skip to content

Commit 53c6f01

Browse files
committed
Fix building of allOf
1 parent 8319043 commit 53c6f01

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/OpenAPINormalizer.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ private Schema findProperty(Schema schema, String propertyName, boolean toDelete
16901690
Schema property = properties.get(propertyName);
16911691
if (property != null) {
16921692
if (toDelete) {
1693-
if (schema.getProperties().remove(propertyName) != null) {
1693+
if (schema.getProperties().remove(propertyName) != null && schema.getProperties().isEmpty()) {
16941694
schema.setProperties(null);
16951695
}
16961696
}
@@ -1752,10 +1752,11 @@ protected void ensureInheritanceForDiscriminatorMappings(Schema parent, Schema c
17521752
child.setAllOf(allOf);
17531753
Schema refToParent = new Schema<>().$ref(reference);
17541754
allOf.add(refToParent);
1755-
if (child.getProperties() != null) {
1755+
Map<String, Schema> childProperties = child.getProperties();
1756+
if (childProperties != null) {
17561757
// move the properties inside the new allOf.
1757-
Schema childProperties = new Schema<>().properties(child.getProperties());
1758-
allOf.add(childProperties);
1758+
Schema newChildProperties = new Schema<>().properties(childProperties);
1759+
allOf.add(newChildProperties);
17591760
child.setProperties(null);
17601761
child.setType(null);
17611762
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/OpenAPINormalizerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package org.openapitools.codegen;
1818

19-
import com.fasterxml.jackson.core.JsonProcessingException;
20-
import com.fasterxml.jackson.databind.ObjectMapper;
21-
import io.swagger.util.Yaml;
2219
import io.swagger.v3.oas.models.OpenAPI;
2320
import io.swagger.v3.oas.models.Operation;
2421
import io.swagger.v3.oas.models.PathItem;
@@ -29,7 +26,6 @@
2926
import org.openapitools.codegen.utils.ModelUtils;
3027
import org.testng.annotations.Test;
3128

32-
import java.lang.reflect.Array;
3329
import java.math.BigDecimal;
3430
import java.util.*;
3531

@@ -1529,7 +1525,11 @@ public void issue_14769() {
15291525
Map<String, String> mapping = vehicle.getDiscriminator().getMapping();
15301526
assertEquals(mapping, Map.of("car", "#/components/schemas/Car", "plane", "#/components/schemas/Plane" ));
15311527
Schema car = openAPI.getComponents().getSchemas().get("Car");
1532-
assertFalse(car.getProperties().containsKey("type"));
1528+
assertNull(car.getProperties());
1529+
assertEquals(car.getAllOf().size(), 2);
1530+
assertEquals(((Schema)car.getAllOf().get(0)).get$ref(), "#/components/schemas/Vehicle");
1531+
assertEquals(((Schema)car.getAllOf().get(1)).getProperties().size(), 1);
1532+
assertEquals(((Schema)car.getAllOf().get(1)).getProperties().keySet(), Set.of("has_4_wheel_drive"));
15331533
}
15341534

15351535
@Test

0 commit comments

Comments
 (0)