Skip to content
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 @@ -2702,14 +2702,14 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
String modelName = ModelUtils.getSimpleRef(oneOf.get$ref());
CodegenProperty thisCp = discriminatorFound(composedSchemaName, oneOf, discPropName, openAPI);
if (thisCp == null) {
throw new RuntimeException("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the referenced OneOf schema '" + modelName + "' is missing " + discPropName);
LOGGER.warn("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the referenced OneOf schema '" + modelName + "' is missing " + discPropName);
}
if (cp.dataType == null) {
cp = thisCp;
continue;
}
if (cp != thisCp) {
throw new RuntimeException("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the OneOf schema '" + modelName + "' has a different " + discPropName + " definition than the prior OneOf schema's. Make sure the " + discPropName + " type and required values are the same");
LOGGER.warn("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the OneOf schema '" + modelName + "' has a different " + discPropName + " definition than the prior OneOf schema's. Make sure the " + discPropName + " type and required values are the same");
}
}
return cp;
Expand All @@ -2721,14 +2721,14 @@ private CodegenProperty discriminatorFound(String composedSchemaName, Schema sc,
String modelName = ModelUtils.getSimpleRef(anyOf.get$ref());
CodegenProperty thisCp = discriminatorFound(composedSchemaName, anyOf, discPropName, openAPI);
if (thisCp == null) {
throw new RuntimeException("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the referenced AnyOf schema '" + modelName + "' is missing " + discPropName);
LOGGER.warn("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the referenced AnyOf schema '" + modelName + "' is missing " + discPropName);
}
if (cp.dataType == null) {
cp = thisCp;
continue;
}
if (cp != thisCp) {
throw new RuntimeException("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the AnyOf schema '" + modelName + "' has a different " + discPropName + " definition than the prior AnyOf schema's. Make sure the " + discPropName + " type and required values are the same");
LOGGER.warn("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the AnyOf schema '" + modelName + "' has a different " + discPropName + " definition than the prior AnyOf schema's. Make sure the " + discPropName + " type and required values are the same");
}
}
return cp;
Expand Down Expand Up @@ -2787,7 +2787,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
}
}
if (discriminatorsPropNames.size() > 1) {
throw new RuntimeException("The oneOf schemas have conflicting discriminator property names. " +
LOGGER.warn("The oneOf schemas have conflicting discriminator property names. " +
"oneOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
}
if (foundDisc != null && (hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getOneOf().size() && discriminatorsPropNames.size() == 1) {
Expand Down Expand Up @@ -2816,7 +2816,7 @@ private Discriminator recursiveGetDiscriminator(Schema sc, OpenAPI openAPI) {
}
}
if (discriminatorsPropNames.size() > 1) {
throw new RuntimeException("The anyOf schemas have conflicting discriminator property names. " +
LOGGER.warn("The anyOf schemas have conflicting discriminator property names. " +
"anyOf schemas must have the same property name, but found " + String.join(", ", discriminatorsPropNames));
}
if (foundDisc != null && (hasDiscriminatorCnt + hasNullTypeCnt) == composedSchema.getAnyOf().size() && discriminatorsPropNames.size() == 1) {
Expand Down Expand Up @@ -2866,7 +2866,7 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
// schemas also has inline composed schemas
// Note: if it is only inline one level, then the inline model resolver will move it into its own
// schema and make it a $ref schema in the oneOf/anyOf location
throw new RuntimeException("Invalid inline schema defined in oneOf/anyOf in '" + composedSchemaName + "'. Per the OpenApi spec, for this case when a composed schema defines a discriminator, the oneOf/anyOf schemas must use $ref. Change this inline definition to a $ref definition");
LOGGER.warn("Invalid inline schema defined in oneOf/anyOf in '" + composedSchemaName + "'. Per the OpenApi spec, for this case when a composed schema defines a discriminator, the oneOf/anyOf schemas must use $ref. Change this inline definition to a $ref definition");
}
CodegenProperty df = discriminatorFound(composedSchemaName, sc, discPropName, openAPI);
String modelName = ModelUtils.getSimpleRef(ref);
Expand All @@ -2886,7 +2886,7 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
msgSuffix += spacer + "invalid optional definition of " + discPropName + ", include it in required";
}
}
throw new RuntimeException("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the referenced schema '" + modelName + "' is incorrect. " + msgSuffix);
LOGGER.warn("'" + composedSchemaName + "' defines discriminator '" + discPropName + "', but the referenced schema '" + modelName + "' is incorrect. " + msgSuffix);
}
MappedModel mm = new MappedModel(modelName, toModelName(modelName));
descendentSchemas.add(mm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,12 +1188,15 @@ public void testComposedSchemaOneOfDiscriminatorsInvalid() {

Schema sc = openAPI.getComponents().getSchemas().get(modelName);

/*
// comment out below as we're now showing warnings instead of throwing exceptions
try {
codegen.fromModel(modelName, sc);
Assert.assertTrue(false, "A RuntimeException should have been thrown when processing "+modelName+ " but it was not");
} catch (RuntimeException re) {
Assert.assertEquals(re.getMessage(), errorMessageExpected);
}
*/
}
}

Expand All @@ -1220,12 +1223,15 @@ public void testComposedSchemaAnyOfDiscriminatorsInvalid() {

Schema sc = openAPI.getComponents().getSchemas().get(modelName);

/*
// comment out below as we're now showing warnings instead of throwing exceptions
try {
codegen.fromModel(modelName, sc);
Assert.assertTrue(false, "A RuntimeException should have been thrown when processing "+modelName+ " but it was not");
} catch (RuntimeException re) {
Assert.assertEquals(re.getMessage(), errorMessageExpected);
}
*/
}
}

Expand Down Expand Up @@ -1256,7 +1262,8 @@ public void testComposedSchemaAnyOfDiscriminatorMap() {
// inline anyOf with inline anyOf model doesn't work because we have null $refs and we throw an exception
final String fmodelName = "FruitInlineInlineDisc";
final Schema fsc = openAPI.getComponents().getSchemas().get(fmodelName);
Assert.assertThrows(() -> codegen.fromModel(fmodelName, fsc));
// comment out below as we're now showing warnings instead of throwing exceptions
//Assert.assertThrows(() -> codegen.fromModel(fmodelName, fsc));

// ref anyOf models with discriminator in properties in those models
modelName = "FruitReqDisc";
Expand Down Expand Up @@ -1341,7 +1348,8 @@ public void testComposedSchemaOneOfDiscriminatorMap() {
// inline oneOf with inline oneOf model doesn't work because we have null $refs and we throw an exception
final String fmodelName = "FruitInlineInlineDisc";
final Schema fsc = openAPI.getComponents().getSchemas().get(fmodelName);
Assert.assertThrows(() -> codegen.fromModel(fmodelName, fsc));
// comment out below as we're now showing warnings instead of throwing exceptions
//Assert.assertThrows(() -> codegen.fromModel(fmodelName, fsc));

// ref oneOf models with discriminator in properties in those models
modelName = "FruitReqDisc";
Expand Down