Search in sources :

Example 1 with OpenApiModelInfo

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());
}
Also used : Violation(io.syndesis.common.model.Violation) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Test(org.junit.Test)

Example 2 with OpenApiModelInfo

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);
}
Also used : OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Test(org.junit.Test)

Example 3 with OpenApiModelInfo

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();
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Test(org.junit.Test)

Example 4 with OpenApiModelInfo

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");
}
Also used : Violation(io.syndesis.common.model.Violation) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType) Test(org.junit.Test)

Example 5 with OpenApiModelInfo

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");
}
Also used : Violation(io.syndesis.common.model.Violation) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Test(org.junit.Test)

Aggregations

OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)49 Test (org.junit.Test)45 Violation (io.syndesis.common.model.Violation)24 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)21 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)14 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)10 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)10 Oas20PathItem (io.apicurio.datamodels.openapi.v2.models.Oas20PathItem)8 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)7 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)5 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)5 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)4 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)4 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)3 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)3 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)2 Oas20Response (io.apicurio.datamodels.openapi.v2.models.Oas20Response)2 Oas20SecurityScheme (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme)2 Oas30SecurityScheme (io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme)2 BaseOpenApiGeneratorExampleTest (io.syndesis.server.api.generator.openapi.BaseOpenApiGeneratorExampleTest)2