Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct allOf with only one child schema (no discriminator) #6901

Merged
merged 5 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1260,14 +1260,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