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

* Correct allOf with only one child schema (no discriminator

* fix tests
This commit is contained in:
William Cheng 2020-11-23 17:16:36 +08:00 committed by GitHub
parent 14ff8e0ffd
commit 4984f9c3d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 16 deletions

View File

@ -1316,14 +1316,12 @@ public class ModelUtils {
}
}
// 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;

View File

@ -1387,9 +1387,9 @@ public class DefaultCodegenTest {
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 {
@ -1400,7 +1400,6 @@ public class DefaultCodegenTest {
}
}
@Test
public void testAllOfParent() {
final OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/allOf-required-parent.yaml");

View File

@ -957,10 +957,10 @@ public class JavaClientCodegenTest {
validateJavaSourceFiles(files);
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/org/openapitools/client/model/RealCommand.java"),
"class RealCommand extends Command");
"class RealCommand {");
TestUtils.assertFileContains(Paths.get(output + "/src/main/java/org/openapitools/client/model/Command.java"),
"class Command");
"class Command {");
output.deleteOnExit();
}

View File

@ -25,6 +25,7 @@ import io.swagger.v3.oas.models.media.Discriminator;
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;
@ -57,8 +58,8 @@ public class 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")