Search in sources :

Example 1 with Oas30PathItem

use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project apicurio-data-models by Apicurio.

the class OasMissingPathParamDefinitionRule method visitOperation.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
 */
@Override
public void visitOperation(Operation node) {
    // Perform operation level checks only if there are no issues at the pathItem level.
    Oas30PathItem pathItem = (Oas30PathItem) node.parent();
    String path = pathItem.getPath();
    if (this.pathItemsWithError.indexOf(path) != -1) {
        return;
    }
    // Check parameters are unique within operation
    List<OasParameter> mergedParameters = mergeParameters((OasOperation) node);
    List<PathSegment> pathSegs = getPathSegments(path);
    // Report all the path segments that don't have an associated parameter definition
    for (PathSegment pathSeg : pathSegs) {
        if (!hasValue(pathSeg.formalName)) {
            continue;
        }
        boolean valid = hasPathParameter(pathSeg.formalName, mergedParameters);
        this.reportIfInvalid(valid, node, null, map("param", pathSeg.formalName, "path", path, "method", node.getType().toUpperCase()));
    }
}
Also used : OasParameter(io.apicurio.datamodels.openapi.models.OasParameter) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)

Example 2 with Oas30PathItem

use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem in project apicurio-data-models by Apicurio.

the class Oas20to30TransformationVisitor method visitOperation.

/**
 * @see io.apicurio.datamodels.core.visitors.IVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
 */
@Override
public void visitOperation(Operation node) {
    Oas20Operation op = (Oas20Operation) node;
    Oas30PathItem pathItem30 = (Oas30PathItem) this.lookup(node.parent());
    Oas30Operation operation30 = (Oas30Operation) pathItem30.createOperation(node.getType());
    pathItem30.setOperation(operation30);
    operation30.tags = op.tags;
    operation30.summary = op.summary;
    operation30.description = op.description;
    operation30.operationId = op.operationId;
    operation30.deprecated = op.deprecated;
    if (!NodeCompat.isNullOrUndefined(op.schemes) && op.schemes.size() > 0 && !NodeCompat.isNullOrUndefined(this.doc30.servers) && this.doc30.servers.size() > 0) {
        Oas30Server server30 = (Oas30Server) operation30.createServer();
        operation30.servers = new ArrayList<>();
        operation30.servers.add(server30);
        server30.url = this.doc30.servers.get(0).url;
        if (op.schemes.size() == 1) {
            server30.url = server30.url.replace("{scheme}", op.schemes.get(0));
            server30.removeServerVariable("scheme");
        } else {
            server30.url = "{scheme}" + server30.url.substring(server30.url.indexOf("://"));
            Oas30ServerVariable var30 = (Oas30ServerVariable) server30.createServerVariable("scheme");
            server30.addServerVariable("scheme", var30);
            var30.description = "The supported protocol schemes.";
            var30.default_ = op.schemes.get(0);
            var30.enum_ = NodeCompat.copyList(op.schemes);
        }
    }
    // Note: consumes/produces will be handled elsewhere (when Request Body and Response models are created)
    this.mapNode(op, operation30);
}
Also used : Oas30Server(io.apicurio.datamodels.openapi.v3.models.Oas30Server) Oas30ServerVariable(io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas30PathItem(io.apicurio.datamodels.openapi.v3.models.Oas30PathItem) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation)

Example 3 with Oas30PathItem

use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem 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 4 with Oas30PathItem

use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem 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 5 with Oas30PathItem

use of io.apicurio.datamodels.openapi.v3.models.Oas30PathItem 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)

Aggregations

Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)23 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)17 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)16 Test (org.junit.Test)16 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)11 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)10 Violation (io.syndesis.common.model.Violation)6 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)5 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)4 Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)3 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)3 Oas30Server (io.apicurio.datamodels.openapi.v3.models.Oas30Server)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 OasParameter (io.apicurio.datamodels.openapi.models.OasParameter)1 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)1 Oas30Components (io.apicurio.datamodels.openapi.v3.models.Oas30Components)1 Oas30Paths (io.apicurio.datamodels.openapi.v3.models.Oas30Paths)1 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)1 Oas30ServerVariable (io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable)1