Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 4 additions & 4 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
- restore_cache:
keys:
# Default branch if not
- source-v1-{{ .Branch }}-{{ .Revision }}
- source-v1-{{ .Branch }}-
- source-v1-
- source-v2-{{ .Branch }}-{{ .Revision }}
- source-v2-{{ .Branch }}-
- source-v2-
# Machine Setup
# If you break your build into multiple jobs with workflows, you will probably want to do the parts of this that are relevant in each
# The following `checkout` command checks out your code to your working directory. In 1.0 we did this implicitly. In 2.0 you can choose where in the course of a job your code should be checked out.
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- run: ./CI/circle_parallel.sh
# Save dependency cache
- save_cache:
key: source-v1-{{ .Branch }}-{{ .Revision }}
key: source-v2-{{ .Branch }}-{{ .Revision }}
paths:
# This is a broad list of cache paths to include many possible development environments
# You can probably delete some of these entries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,6 @@ public static List<Schema> getInterfaces(ComposedSchema composed) {
public static String getParentName(ComposedSchema composedSchema, Map<String, Schema> allSchemas) {
List<Schema> interfaces = getInterfaces(composedSchema);
int nullSchemaChildrenCount = 0;
boolean hasAmbiguousParents = false;
List<String> refedWithoutDiscriminator = new ArrayList<>();

if (interfaces != null && !interfaces.isEmpty()) {
for (Schema schema : interfaces) {
Expand All @@ -1239,8 +1237,10 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
return parentName;
} else {
// not a parent since discriminator.propertyName is not set
hasAmbiguousParents = true;
refedWithoutDiscriminator.add(parentName);
// TOOD to be removed in 6.x release

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:-) Misspelling: TOOD --> TODO

This case indicates composition, not inheritance right? Especially in the edge case of an allOf reference to a model with no properties nor additionalProperties So why is it being deprecated? This seems like a valid use case for composition.

The log warning message seems to indicate that I will not be able to do composition in this way. Is that what is intended?

LOGGER.warn("[deprecated] inheritance without use of 'discriminator.propertyName' has been deprecated" +
" in the 5.x release. Composed schema name: {}. Title: {}",
composedSchema.getName(), composedSchema.getTitle());
}
} else {
// not a ref, doing nothing, except counting the number of times the 'null' type

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is no longer needed at all right? It only increments an unused variable nullSchemaChildrenCount

Expand All @@ -1253,21 +1253,6 @@ public static String getParentName(ComposedSchema composedSchema, Map<String, Sc
}
}
}
if (refedWithoutDiscriminator.size() == 1 && nullSchemaChildrenCount == 1) {
// One schema is a $ref and the other is the 'null' type, so the parent is obvious.
// In this particular case there is no need to specify a discriminator.
hasAmbiguousParents = false;
}
}

// 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);
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,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 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