use of io.syndesis.common.model.Violation 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.common.model.Violation in project syndesis by syndesisio.
the class ConnectionsITCase method nullNamesShouldNotBeAllowed.
@Test
public void nullNamesShouldNotBeAllowed() {
final Connection connection = new Connection.Builder().build();
final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
assertThat(got.getBody()).containsExactly(new Violation.Builder().property("name").error("NotNull").message("Value is required").build());
}
use of io.syndesis.common.model.Violation in project syndesis by syndesisio.
the class ConnectionsITCase method shouldDetermineValidityForInvalidConnections.
@Test
public void shouldDetermineValidityForInvalidConnections() {
final Connection connection = new Connection.Builder().name("Existing connection").build();
final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
assertThat(got.getBody()).containsExactly(new Violation.Builder().property("name").error("UniqueProperty").message("Value 'Existing connection' is not unique").build());
}
use of io.syndesis.common.model.Violation in project syndesis by syndesisio.
the class ConnectionsITCase method violationsShouldBeGivenForInvalidConnectionCreation.
@Test
public void violationsShouldBeGivenForInvalidConnectionCreation() {
final Connection connection = new Connection.Builder().name("Existing connection").build();
final ResponseEntity<List<Violation>> got = post("/api/v1/connections", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
assertThat(got.getBody()).containsExactly(new Violation.Builder().property("create.obj.name").error("UniqueProperty").message("Value 'Existing connection' is not unique").build());
}
use of io.syndesis.common.model.Violation in project syndesis by syndesisio.
the class ConnectionsITCase method emptyNamesShouldNotBeAllowed.
@Test
public void emptyNamesShouldNotBeAllowed() {
final Connection connection = new Connection.Builder().name(" ").build();
final ResponseEntity<List<Violation>> got = post("/api/v1/connections/validation", connection, RESPONSE_TYPE, tokenRule.validToken(), HttpStatus.BAD_REQUEST);
assertThat(got.getBody()).containsExactly(new Violation.Builder().property("name").error("NotNull").message("Value is required").build());
}
Aggregations