Skip to content

Commit

Permalink
Correct allOf with only one child schema (no discriminator) (#6901)
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 authored Sep 1, 2020
1 parent ab5b0fa commit 972120c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1274,14 +1274,12 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
}
}

// parent name only makes sense when there is a single obvious parent
if (refedWithoutDiscriminator.size() == 1) {
if (hasAmbiguousParents) {
LOGGER.warn("[deprecated] inheritance without use of 'discriminator.propertyName' is deprecated " +
"and will be removed in a future release. Generating model for composed schema name: {}. Title: {}",
composedSchema.getName(), composedSchema.getTitle());
}
return refedWithoutDiscriminator.get(0);
if (refedWithoutDiscriminator.size() == 1 && hasAmbiguousParents) {
// allOf with a single $ref (no discriminator)
// TODO to be removed in 5.x or 6.x release
LOGGER.info("[deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated" +
" in the 5.x release. Composed schema name: {}. Title: {}",
composedSchema.getName(), composedSchema.getTitle());
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1363,7 +1363,6 @@ public void verifyXDiscriminatorValue() {
assertEquals(cm.discriminator, discriminator);
}


@Test
public void testAllOfSingleRefNoOwnProps() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/2_0/composed-allof.yaml");
Expand All @@ -1372,9 +1371,9 @@ public void testAllOfSingleRefNoOwnProps() {
Schema schema = openAPI.getComponents().getSchemas().get("NewMessageEventCoreNoOwnProps");
codegen.setOpenAPI(openAPI);
CodegenModel model = codegen.fromModel("NewMessageEventCoreNoOwnProps", schema);
Assert.assertEquals(getNames(model.getVars()), Collections.emptyList());
Assert.assertEquals(model.parent, "MessageEventCore");
Assert.assertEquals(model.allParents, Collections.singletonList("MessageEventCore"));
Assert.assertEquals(getNames(model.getVars()), Arrays.asList("id","message"));
Assert.assertNull(model.parent);
Assert.assertNull(model.allParents);
}

class CodegenWithMultipleInheritance extends DefaultCodegen {
Expand All @@ -1385,7 +1384,6 @@ public CodegenWithMultipleInheritance() {
}
}


@Test
public void testAllOfParent() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf-required-parent.yaml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.media.StringSchema;
import java.util.Collections;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenProperty;
Expand Down Expand Up @@ -57,8 +58,8 @@ public void javaInheritanceTest() {

Assert.assertEquals(cm.name, "sample");
Assert.assertEquals(cm.classname, "Sample");
Assert.assertEquals(cm.parent, "Base");
Assert.assertEquals(cm.imports, Sets.newHashSet("Base"));
Assert.assertNull(cm.parent);
Assert.assertEquals(cm.imports, Collections.emptySet());
}

@Test(description = "convert a composed model with discriminator")
Expand Down

0 comments on commit 972120c

Please sign in to comment.