Skip to content
Open
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 @@ -96,13 +96,9 @@ private static ValidationRule.Result checkNullType(SchemaWrapper schemaWrapper)
// OAS spec is 3.0.x
if (ModelUtils.isNullType(schema)) {
result = new ValidationRule.Fail();
String name = schema.getName();
if (name == null) {
name = schema.getTitle();
}
result.setDetails(String.format(Locale.ROOT,
"Schema '%s' uses a 'null' type, which is specified in OAS 3.1 and above, but OAS document is version %s",
name, schemaWrapper.getOpenAPI().getOpenapi()));
nameOf(schema), schemaWrapper.getOpenAPI().getOpenapi()));
return result;
}
}
Expand All @@ -126,20 +122,22 @@ private static ValidationRule.Result checkNullableAttribute(SchemaWrapper schema
if (version.atLeast("3.1")) {
if (ModelUtils.isNullable(schema)) {
result = new ValidationRule.Fail();
String name = schema.getName();
if (name == null) {
name = schema.getTitle();
}
result.setDetails(String.format(Locale.ROOT,
"OAS document is version '%s'. Schema '%s' uses 'nullable' attribute, which has been deprecated in OAS 3.1.",
schemaWrapper.getOpenAPI().getOpenapi(), name));
schemaWrapper.getOpenAPI().getOpenapi(), nameOf(schema)));
return result;
}
}
}
return result;
}

private static String nameOf(Schema schema) {
if (schema.getName() != null) return schema.getName();
if (schema.getTitle() != null) return schema.getTitle();
return "(unnamed)";
}

// The set of valid OAS values for the 'type' attribute.
private static Set<String> validTypes = new HashSet<String>(
Arrays.asList("null", "boolean", "object", "array", "number", "string", "integer"));
Expand All @@ -157,13 +155,9 @@ private static ValidationRule.Result checkInvalidType(SchemaWrapper schemaWrappe
ValidationRule.Result result = ValidationRule.Pass.empty();
if (schema.getType() != null && !validTypes.contains(schema.getType())) {
result = new ValidationRule.Fail();
String name = schema.getName();
if (name == null) {
name = schema.getTitle();
}
result.setDetails(String.format(Locale.ROOT,
"Schema '%s' uses the '%s' type, which is not a valid type.",
name, schema.getType()));
nameOf(schema), schema.getType()));
return result;
}
return result;
Expand Down
Loading