Search in sources :

Example 1 with Oas20Operation

use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project apicurio-data-models by Apicurio.

the class OasUnmatchedExampleTypeRule method visitExample.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
 */
@Override
public void visitExample(IExample node) {
    Oas20Example example20 = (Oas20Example) node;
    Oas20Document doc = (Oas20Document) example20.ownerDocument();
    List<String> produces = doc.produces;
    Oas20Operation operation = (Oas20Operation) findParentOperation(example20);
    if (isDefined(operation)) {
        if (hasValue(operation.produces)) {
            produces = operation.produces;
        }
        if (!hasValue(produces)) {
            produces = new ArrayList<>();
        }
        List<String> ctypes = example20.getExampleContentTypes();
        for (String ct : ctypes) {
            this.reportIfInvalid(produces.indexOf(ct) != -1, example20, Constants.PROP_PRODUCES, map("contentType", ct));
        }
    }
}
Also used : Oas20Example(io.apicurio.datamodels.openapi.v2.models.Oas20Example) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation)

Example 2 with Oas20Operation

use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project apicurio-data-models by Apicurio.

the class Oas20to30TransformationVisitor method findParentOperation.

private Oas20Operation findParentOperation(Parameter node) {
    OperationFinder finder = new OperationFinder();
    Library.visitTree(node, finder, TraverserDirection.up);
    return (Oas20Operation) finder.found;
}
Also used : OperationFinder(io.apicurio.datamodels.core.visitors.OperationFinder) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation)

Example 3 with Oas20Operation

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

use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project syndesis by syndesisio.

the class Oas20DataShapeGeneratorHelper method getOperationParameters.

static List<Oas20Parameter> getOperationParameters(Oas20Document openApiDoc, Oas20Operation operation) {
    final List<Oas20Parameter> operationParameters = Oas20ModelHelper.getParameters(operation);
    OasPathItem parent = ofNullable(operation.parent()).filter(OasPathItem.class::isInstance).map(OasPathItem.class::cast).orElse(null);
    final List<Oas20Parameter> pathParameters = Oas20ModelHelper.getParameters(parent);
    operationParameters.addAll(pathParameters);
    final List<Oas20ParameterDefinition> globalParameters = ofNullable(openApiDoc.parameters).map(Oas20ParameterDefinitions::getItems).orElse(Collections.emptyList());
    operationParameters.addAll(globalParameters);
    return operationParameters;
}
Also used : OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)

Example 5 with Oas20Operation

use of io.apicurio.datamodels.openapi.v2.models.Oas20Operation in project syndesis by syndesisio.

the class CyclicValidationCheckTest method shouldFindTwoStepCyclicReferencesInResponses.

@Test
public void shouldFindTwoStepCyclicReferencesInResponses() {
    final Oas20Document openApiDoc = new Oas20Document();
    final Oas20PathItem pathItem = new Oas20PathItem("/api");
    final Oas20Operation operation = new Oas20Operation("post");
    Oas20Response response = new Oas20Response("200");
    Oas20Schema responseSchema = new Oas20Schema();
    responseSchema.$ref = "#/definitions/A";
    response.schema = responseSchema;
    operation.responses = operation.createResponses();
    operation.responses.addResponse("200", response);
    pathItem.post = operation;
    openApiDoc.paths = openApiDoc.createPaths();
    openApiDoc.paths.addPathItem("/api", pathItem);
    Oas20SchemaDefinition schemaDefinitionA = new Oas20SchemaDefinition("A");
    schemaDefinitionA.type = "object";
    Oas20Schema propertySchemaA = new Oas20Schema();
    propertySchemaA.$ref = "#/definitions/B";
    schemaDefinitionA.properties = new HashMap<>();
    schemaDefinitionA.properties.put("b", propertySchemaA);
    openApiDoc.definitions = openApiDoc.createDefinitions();
    openApiDoc.definitions.addDefinition("A", schemaDefinitionA);
    Oas20SchemaDefinition schemaDefinitionB = new Oas20SchemaDefinition("B");
    schemaDefinitionB.type = "object";
    Oas20Schema propertySchemaB = new Oas20Schema();
    propertySchemaB.$ref = "#/definitions/A";
    schemaDefinitionB.properties = new HashMap<>();
    schemaDefinitionB.properties.put("a", propertySchemaB);
    openApiDoc.definitions.addDefinition("B", schemaDefinitionB);
    assertThat(CyclicValidationCheck.hasCyclicReferences(getSchemaDefinitions(openApiDoc))).isTrue();
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20PathItem(io.apicurio.datamodels.openapi.v2.models.Oas20PathItem) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Test(org.junit.Test)

Aggregations

Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)22 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)17 Test (org.junit.Test)17 Oas20PathItem (io.apicurio.datamodels.openapi.v2.models.Oas20PathItem)15 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)12 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)11 Oas20SchemaDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)9 Oas20Response (io.apicurio.datamodels.openapi.v2.models.Oas20Response)7 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)7 Violation (io.syndesis.common.model.Violation)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 OperationFinder (io.apicurio.datamodels.core.visitors.OperationFinder)1 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)1 Oas20Example (io.apicurio.datamodels.openapi.v2.models.Oas20Example)1 Oas20ParameterDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)1 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)1 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)1 Oas30Server (io.apicurio.datamodels.openapi.v3.models.Oas30Server)1 Oas30ServerVariable (io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable)1 DataShape (io.syndesis.common.model.DataShape)1