use of io.syndesis.server.connector.generator.swagger.SwaggerModelInfo in project syndesis by syndesisio.
the class SwaggerHelperTest method testThatAllSwaggerFilesAreValid.
@Test
public void testThatAllSwaggerFilesAreValid() throws IOException {
final String[] specifications = { "/swagger/concur.swagger.json", "/swagger/petstore.swagger.json", "/swagger/todo.swagger.yaml" };
for (final String specificationFile : specifications) {
final String specification = resource(specificationFile);
final SwaggerModelInfo info = SwaggerHelper.parse(specification, true);
assertThat(info.getErrors()).withFailMessage("Specification " + specificationFile + " has errors: " + info.getErrors()).isEmpty();
}
}
use of io.syndesis.server.connector.generator.swagger.SwaggerModelInfo in project syndesis by syndesisio.
the class SwaggerHelperTest method testThatWarningPetstoreSwaggerContainsWarnings.
@Test
public void testThatWarningPetstoreSwaggerContainsWarnings() throws IOException {
final String specification = resource("/swagger/invalid/warning-petstore.swagger.json");
final SwaggerModelInfo info = SwaggerHelper.parse(specification, true);
assertThat(info.getErrors()).isEmpty();
assertThat(info.getWarnings()).hasSize(3);
}
use of io.syndesis.server.connector.generator.swagger.SwaggerModelInfo in project syndesis by syndesisio.
the class SwaggerHelper method validateJSonSchema.
private static SwaggerModelInfo validateJSonSchema(final String specification, final Swagger model) {
try {
final JsonNode specRoot = convertToJson(specification);
final ProcessingReport report = SWAGGER_2_0_SCHEMA.validate(specRoot);
final List<Violation> errors = new ArrayList<>();
final List<Violation> warnings = new ArrayList<>();
for (final ProcessingMessage message : report) {
final boolean added = append(errors, message, Optional.of("error"));
if (!added) {
append(warnings, message, Optional.empty());
}
}
return new SwaggerModelInfo.Builder().errors(errors).warnings(warnings).model(model).resolvedSpecification(specification).build();
} catch (IOException | ProcessingException ex) {
LOG.error("Unable to load the schema file embedded in the artifact", ex);
return new SwaggerModelInfo.Builder().addError(new Violation.Builder().error("error").property("").message("Unable to load the swagger schema file embedded in the artifact").build()).build();
}
}
use of io.syndesis.server.connector.generator.swagger.SwaggerModelInfo in project syndesis by syndesisio.
the class SwaggerHelper method parse.
public static SwaggerModelInfo parse(final String specification, final boolean validate) {
final SwaggerModelInfo.Builder resultBuilder = new SwaggerModelInfo.Builder();
final String resolvedSpecification;
try {
resolvedSpecification = resolve(specification);
resultBuilder.resolvedSpecification(resolvedSpecification);
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final Exception e) {
LOG.debug("Unable to resolve Swagger specification\n{}\n", specification, e);
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to resolve Swagger specification from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
}
final SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.parse(resolvedSpecification);
if (swagger == null) {
LOG.debug("Unable to read Swagger specification\n{}\n", specification);
return resultBuilder.addError(new Violation.Builder().error("error").property("").message("Unable to read Swagger specification from: " + ofNullable(specification).map(s -> StringUtils.abbreviate(s, 100)).orElse("")).build()).build();
}
if (validate) {
final SwaggerModelInfo swaggerModelInfo = validateJSonSchema(resolvedSpecification, swagger);
return SyndesisSwaggerValidationRules.getInstance().apply(swaggerModelInfo);
}
return resultBuilder.model(swagger).build();
}
use of io.syndesis.server.connector.generator.swagger.SwaggerModelInfo in project syndesis by syndesisio.
the class SwaggerHelperTest method testThatInvalidTypePetstoreSwaggerIsInvalid.
@Test
public void testThatInvalidTypePetstoreSwaggerIsInvalid() throws IOException {
final String specification = resource("/swagger/invalid/invalid-type.petstore.swagger.json");
final SwaggerModelInfo info = SwaggerHelper.parse(specification, true);
assertThat(info.getErrors()).hasSize(1);
assertThat(info.getWarnings()).isEmpty();
assertThat(info.getErrors().get(0).message()).startsWith("instance failed to match exactly one schema");
assertThat(info.getErrors().get(0).property()).contains("/paths/~1pet~1{petId}/post/parameters/2");
assertThat(info.getErrors().get(0).error()).contains("validation");
}
Aggregations