use of com.reprezen.kaizen.oasparser.OpenApi3Parser in project policies-ui-backend by RedHatInsights.
the class OapiTest method validateOpenApi.
@Test
void validateOpenApi() throws Exception {
OpenApi3 model = new OpenApi3Parser().parse(url, true);
System.out.printf("OpenAPI Model at %s\n", url);
if (!model.isValid()) {
for (ValidationResults.ValidationItem item : model.getValidationItems()) {
System.err.println(item);
}
fail("OpenAPI spec is not valid");
}
//
// Now that basic validation is done, we can add some of our own
//
Map<String, Path> paths = model.getPaths();
Map<String, Schema> schemas = model.getSchemas();
// The base path filler. See also OASModifier.mangleName
assertTrue(paths.containsKey("/"));
// User config is private, so don't show it
assertFalse(paths.containsKey("/user-config"));
assertFalse(schemas.containsKey("SettingsValues"));
// Check that openapi does not (again) collapse parameters
assertEquals(9, paths.get("/policies").getOperation("get").getParameters().size());
// Check that all properties are present ( https://github.com/smallrye/smallrye-open-api/issues/437 )
Map<String, Schema> policyProperties = schemas.get("Policy").getProperties();
assertEquals(9, policyProperties.size());
assertTrue(policyProperties.containsKey("ctime"));
assertTrue(policyProperties.containsKey("mtime"));
// Now that the OpenAPI file has been validated, save a copy to the filesystem
// This file is going to be uploaded in a regular CI build to know the API state
// for a given build.
InputStream in = url.openStream();
Files.copy(in, Paths.get(TARGET_OPENAPI), StandardCopyOption.REPLACE_EXISTING);
}
use of com.reprezen.kaizen.oasparser.OpenApi3Parser in project KaiZen-OpenAPI-Editor by RepreZen.
the class OpenApi3Validator method validate.
@Override
public Set<SwaggerError> validate(JsonDocument document, URI baseURI) {
final Set<SwaggerError> errors = super.validate(document, baseURI);
final long nbOfErrors = errors.stream().filter(e -> e.getLevel() == SEVERITY_ERROR).count();
// and option in UI is enable.
if (isAdvancedValidation() && nbOfErrors == 0) {
try {
OpenApi3 result = new OpenApi3Parser().parse(document.get(), baseURI.toURL(), true);
for (ValidationItem item : result.getValidationResults().getItems()) {
PositionInfo pos = item.getPositionInfo();
int line = pos != null ? pos.getLine() : 1;
errors.add(new SwaggerError(line, getSeverity(item.getSeverity()), item.getMsg()));
}
} catch (Exception e) {
Activator.getDefault().getLog().log(new Status(Status.ERROR, Activator.PLUGIN_ID, e.getLocalizedMessage()));
}
}
return errors;
}
Aggregations