Search in sources :

Example 1 with Oas30ServerVariable

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

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

the class Oas20to30TransformationVisitor method visitDocument.

/**
 * @see io.apicurio.datamodels.core.visitors.IVisitor#visitDocument(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void visitDocument(Document node) {
    this.doc30 = (Oas30Document) Library.createDocument(DocumentType.openapi3);
    Oas20Document doc20 = (Oas20Document) node;
    if (!NodeCompat.isNullOrUndefined(doc20.host)) {
        String basePath = doc20.basePath;
        if (NodeCompat.isNullOrUndefined(basePath)) {
            basePath = "";
        }
        List<String> schemes = doc20.schemes;
        if (NodeCompat.isNullOrUndefined(schemes) || schemes.size() == 0) {
            schemes = NodeCompat.asList("http");
        }
        Oas30Server server30 = (Oas30Server) this.doc30.createServer();
        this.doc30.servers = new ArrayList<>();
        this.doc30.servers.add(server30);
        if (schemes.size() == 1) {
            server30.url = schemes.get(0) + "://" + doc20.host + basePath;
        } else {
            server30.url = "{scheme}://" + doc20.host + basePath;
            Oas30ServerVariable var30 = (Oas30ServerVariable) server30.createServerVariable("scheme");
            server30.addServerVariable("scheme", var30);
            var30.default_ = schemes.get(0);
            var30.enum_ = NodeCompat.copyList(schemes);
            var30.description = "The supported protocol schemes.";
        }
    }
    this.mapNode(doc20, this.doc30);
}
Also used : Oas30Server(io.apicurio.datamodels.openapi.v3.models.Oas30Server) Oas30ServerVariable(io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document)

Aggregations

Oas30Server (io.apicurio.datamodels.openapi.v3.models.Oas30Server)2 Oas30ServerVariable (io.apicurio.datamodels.openapi.v3.models.Oas30ServerVariable)2 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)1 Oas20Operation (io.apicurio.datamodels.openapi.v2.models.Oas20Operation)1 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)1 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)1