mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-02 21:50:55 +00:00
Use warning instead of throwing exceptions (#9188)
* use warning instead of throwing exceptions * comment out tests
This commit is contained in:
parent
1f227061c6
commit
13c0b2c3c7
@ -2702,14 +2702,14 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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;
|
||||
@ -2721,14 +2721,14 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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;
|
||||
@ -2787,7 +2787,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
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) {
|
||||
@ -2816,7 +2816,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
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) {
|
||||
@ -2866,7 +2866,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// 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);
|
||||
@ -2886,7 +2886,7 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
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);
|
||||
|
@ -1188,12 +1188,15 @@ public class DefaultCodegenTest {
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -1220,12 +1223,15 @@ public class DefaultCodegenTest {
|
||||
|
||||
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);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@ -1256,7 +1262,8 @@ public class DefaultCodegenTest {
|
||||
// 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";
|
||||
@ -1341,7 +1348,8 @@ public class DefaultCodegenTest {
|
||||
// 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";
|
||||
|
Loading…
x
Reference in New Issue
Block a user