Skip to content

Commit 6d54799

Browse files
committed
fixed generation of oneOf models with descriminator
1 parent d864831 commit 6d54799

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5769,28 +5769,30 @@ public void addOneOfNameExtension(ComposedSchema s, String name) {
57695769
}
57705770

57715771
/**
5772-
* Add a given ComposedSchema as an interface model to be generated
5772+
* Add a given ComposedSchema as an interface model to be generated, assuming it has `oneOf` defined
57735773
* @param cs ComposedSchema object to create as interface model
57745774
* @param type name to use for the generated interface model
57755775
*/
57765776
public void addOneOfInterfaceModel(ComposedSchema cs, String type) {
5777+
if (cs.getOneOf() == null) {
5778+
return;
5779+
}
57775780
CodegenModel cm = new CodegenModel();
57785781

57795782
cm.discriminator = createDiscriminator("", (Schema) cs);
5780-
if (cs.getOneOf() != null){
5781-
for (Schema o : cs.getOneOf()) {
5782-
if (o.get$ref() == null) {
5783-
if (cm.discriminator != null && o.get$ref() == null) {
5784-
// OpenAPI spec states that inline objects should not be considered when discriminator is used
5785-
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#discriminatorObject
5786-
LOGGER.warn("Ignoring inline object in oneOf definition of {}, since discriminator is used", type);
5787-
} else {
5788-
LOGGER.warn("Inline models are not supported in oneOf definition right now");
5789-
}
5790-
continue;
5783+
5784+
for (Schema o : cs.getOneOf()) {
5785+
if (o.get$ref() == null) {
5786+
if (cm.discriminator != null && o.get$ref() == null) {
5787+
// OpenAPI spec states that inline objects should not be considered when discriminator is used
5788+
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#discriminatorObject
5789+
LOGGER.warn("Ignoring inline object in oneOf definition of {}, since discriminator is used", type);
5790+
} else {
5791+
LOGGER.warn("Inline models are not supported in oneOf definition right now");
57915792
}
5792-
cm.oneOf.add(toModelName(ModelUtils.getSimpleRef(o.get$ref())));
5793+
continue;
57935794
}
5795+
cm.oneOf.add(toModelName(ModelUtils.getSimpleRef(o.get$ref())));
57945796
}
57955797
cm.name = type;
57965798
cm.classname = type;

0 commit comments

Comments
 (0)