show error when schema in discriminator mapping is undefined (#11127)

This commit is contained in:
William Cheng 2021-12-15 22:18:39 +08:00 committed by GitHub
parent b2daa5a836
commit c27ddc67fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3170,10 +3170,16 @@ public class DefaultCodegen implements CodegenConfig {
List<MappedModel> uniqueDescendants = new ArrayList();
if (sourceDiscriminator.getMapping() != null && !sourceDiscriminator.getMapping().isEmpty()) {
for (Entry<String, String> e : sourceDiscriminator.getMapping().entrySet()) {
String nameOrRef = e.getValue();
String name = nameOrRef.indexOf('/') >= 0 ? ModelUtils.getSimpleRef(nameOrRef) : nameOrRef;
String modelName = toModelName(name);
uniqueDescendants.add(new MappedModel(e.getKey(), modelName));
String name;
if (e.getValue().indexOf('/') >= 0) {
name = ModelUtils.getSimpleRef(e.getValue());
if (ModelUtils.getSchema(openAPI, name) == null) {
LOGGER.error("Failed to lookup the schema '{}' when processing the discriminator mapping of oneOf/anyOf. Please check to ensure it's defined properly.", name);
}
} else {
name = e.getValue();
}
uniqueDescendants.add(new MappedModel(e.getKey(), toModelName(name)));
}
}