use of io.syndesis.server.api.generator.openapi.OpenApiModelInfo in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldValidateOperationsArePresent.
@Test
public void shouldValidateOperationsArePresent() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/test");
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/test", pathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateOperationsGiven(info);
final List<Violation> errors = validated.getErrors();
assertThat(errors).containsExactly(new Violation.Builder().property("").error("missing-operations").message("No operations defined").build());
}
use of io.syndesis.server.api.generator.openapi.OpenApiModelInfo in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method cyclicSchemaReferencesValidationShouldOperateOnParsedModel.
@Test
public void cyclicSchemaReferencesValidationShouldOperateOnParsedModel() {
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().build();
final OpenApiModelInfo validated = RULES.validateCyclicReferences(info);
assertThat(validated).isSameAs(info);
}
use of io.syndesis.server.api.generator.openapi.OpenApiModelInfo in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldNotGenerateErrorWhenOperationsArePresent.
@Test
public void shouldNotGenerateErrorWhenOperationsArePresent() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/test");
pathItem.get = new Oas30Operation("get");
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/test", pathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateOperationsGiven(info);
assertThat(validated.getErrors()).isEmpty();
assertThat(validated.getWarnings()).isEmpty();
}
use of io.syndesis.server.api.generator.openapi.OpenApiModelInfo in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldValidateMissingResponseBodySchema.
@Test
public void shouldValidateMissingResponseBodySchema() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/path");
Oas30Operation get = new Oas30Operation("get");
get.operationId = "o1";
get.responses = get.createResponses();
get.responses.addResponse("404", get.responses.createResponse("404"));
get.responses.addResponse("200", get.responses.createResponse("200"));
pathItem.get = get;
Oas30Operation post = new Oas30Operation("post");
post.operationId = "o2";
final Oas30Parameter headerParameter = new Oas30Parameter();
headerParameter.in = "header";
post.parameters = Collections.singletonList(headerParameter);
post.requestBody = post.createRequestBody();
Oas30Schema bodySchema = new Oas30Schema();
bodySchema.addProperty("foo", new Oas30Schema());
Oas30MediaType requestBody = post.requestBody.createMediaType("application/json");
requestBody.schema = bodySchema;
post.requestBody.content = Collections.singletonMap("application/json", requestBody);
pathItem.post = post;
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/path", pathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateRequestResponseBodySchemas(info);
final List<Violation> warnings = validated.getWarnings();
assertThat(warnings).hasSize(1);
final Violation reportedWarning = warnings.get(0);
assertThat(reportedWarning.error()).isEqualTo("missing-response-schema");
assertThat(reportedWarning.property()).isEmpty();
assertThat(reportedWarning.message()).isEqualTo("Operation GET /path does not provide a response schema for code 200");
}
use of io.syndesis.server.api.generator.openapi.OpenApiModelInfo in project syndesis by syndesisio.
the class Oas30ValidationRulesTest method shouldValidateOperationUniqueness.
@Test
public void shouldValidateOperationUniqueness() {
final Oas30Document openApiDoc = new Oas30Document();
final Oas30PathItem pathItem = new Oas30PathItem("/path");
Oas30Operation get = new Oas30Operation("get");
get.operationId = "o1";
pathItem.get = get;
Oas30Operation post = new Oas30Operation("post");
post.operationId = "o2";
pathItem.post = post;
openApiDoc.paths = openApiDoc.createPaths();
openApiDoc.paths.addPathItem("/path", pathItem);
final Oas30PathItem otherPathItem = new Oas30PathItem("/other");
Oas30Operation patch = new Oas30Operation("patch");
patch.operationId = "o2";
otherPathItem.patch = patch;
Oas30Operation put = new Oas30Operation("put");
put.operationId = "o3";
otherPathItem.put = put;
openApiDoc.paths.addPathItem("/other", otherPathItem);
final Oas30PathItem morePathItem = new Oas30PathItem("/more");
Oas30Operation options = new Oas30Operation("options");
options.operationId = "o4";
morePathItem.options = options;
Oas30Operation delete = new Oas30Operation("delete");
delete.operationId = "o3";
morePathItem.delete = delete;
openApiDoc.paths.addPathItem("/more", morePathItem);
final OpenApiModelInfo info = new OpenApiModelInfo.Builder().model(openApiDoc).build();
final OpenApiModelInfo validated = RULES.validateUniqueOperationIds(info);
final List<Violation> warnings = validated.getWarnings();
assertThat(warnings).hasSize(1);
final Violation nonUniqueWarning = warnings.get(0);
assertThat(nonUniqueWarning.error()).isEqualTo("non-unique-operation-ids");
assertThat(nonUniqueWarning.property()).isNull();
assertThat(nonUniqueWarning.message()).isEqualTo("Found operations with non unique operationIds: o2, o3");
}
Aggregations