Search in sources :

Example 1 with Oas30Components

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

the class Oas30DataModelReader method readComponents.

/**
 * Reads a Components model.
 * @param json
 * @param node
 */
public void readComponents(Object json, Oas30Components node) {
    Object schemas = JsonCompat.consumeProperty(json, Constants.PROP_SCHEMAS);
    Object responses = JsonCompat.consumeProperty(json, Constants.PROP_RESPONSES);
    Object parameters = JsonCompat.consumeProperty(json, Constants.PROP_PARAMETERS);
    Object examples = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLES);
    Object requestBodies = JsonCompat.consumeProperty(json, Constants.PROP_REQUEST_BODIES);
    Object headers = JsonCompat.consumeProperty(json, Constants.PROP_HEADERS);
    Object securitySchemes = JsonCompat.consumeProperty(json, Constants.PROP_SECURITY_SCHEMES);
    Object links = JsonCompat.consumeProperty(json, Constants.PROP_LINKS);
    Object callbacks = JsonCompat.consumeProperty(json, Constants.PROP_CALLBACKS);
    if (schemas != null) {
        JsonCompat.keys(schemas).forEach(name -> {
            Object schema = JsonCompat.consumeProperty(schemas, name);
            Oas30SchemaDefinition schemaModel = node.createSchemaDefinition(name);
            this.readSchema(schema, schemaModel);
            node.addSchemaDefinition(name, schemaModel);
        });
    }
    if (responses != null) {
        JsonCompat.keys(responses).forEach(name -> {
            Object response = JsonCompat.consumeProperty(responses, name);
            Oas30ResponseDefinition responseModel = node.createResponseDefinition(name);
            this.readResponse(response, responseModel);
            node.addResponseDefinition(name, responseModel);
        });
    }
    if (parameters != null) {
        JsonCompat.keys(parameters).forEach(name -> {
            Object parameter = JsonCompat.consumeProperty(parameters, name);
            Oas30ParameterDefinition parameterModel = node.createParameterDefinition(name);
            this.readParameter(parameter, parameterModel);
            node.addParameterDefinition(name, parameterModel);
        });
    }
    if (examples != null) {
        JsonCompat.keys(examples).forEach(name -> {
            Object example = JsonCompat.consumeProperty(examples, name);
            Oas30ExampleDefinition exampleModel = node.createExampleDefinition(name);
            this.readExample(example, exampleModel);
            node.addExampleDefinition(name, exampleModel);
        });
    }
    if (requestBodies != null) {
        JsonCompat.keys(requestBodies).forEach(name -> {
            Object requestBody = JsonCompat.consumeProperty(requestBodies, name);
            Oas30RequestBodyDefinition requestBodyModel = node.createRequestBodyDefinition(name);
            this.readRequestBody(requestBody, requestBodyModel);
            node.addRequestBodyDefinition(name, requestBodyModel);
        });
    }
    if (headers != null) {
        JsonCompat.keys(headers).forEach(name -> {
            Object header = JsonCompat.consumeProperty(headers, name);
            Oas30HeaderDefinition headerModel = node.createHeaderDefinition(name);
            this.readHeader(header, headerModel);
            node.addHeaderDefinition(name, headerModel);
        });
    }
    if (securitySchemes != null) {
        JsonCompat.keys(securitySchemes).forEach(name -> {
            Object securityScheme = JsonCompat.consumeProperty(securitySchemes, name);
            Oas30SecurityScheme securitySchemeModel = node.createSecurityScheme(name);
            this.readSecurityScheme(securityScheme, securitySchemeModel);
            node.addSecurityScheme(name, securitySchemeModel);
        });
    }
    if (links != null) {
        JsonCompat.keys(links).forEach(name -> {
            Object link = JsonCompat.consumeProperty(links, name);
            Oas30LinkDefinition linkModel = node.createLinkDefinition(name);
            this.readLink(link, linkModel);
            node.addLinkDefinition(name, linkModel);
        });
    }
    if (callbacks != null) {
        JsonCompat.keys(callbacks).forEach(name -> {
            Object callback = JsonCompat.consumeProperty(callbacks, name);
            Oas30CallbackDefinition callbackModel = node.createCallbackDefinition(name);
            this.readCallback(callback, callbackModel);
            node.addCallbackDefinition(name, callbackModel);
        });
    }
}
Also used : Oas30CallbackDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition) Oas30SchemaDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition) Oas30ExampleDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition) Oas30LinkDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Oas30RequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition) Oas30ResponseDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition) Oas30HeaderDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)

Example 2 with Oas30Components

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

the class Oas30Traverser method visitComponents.

/**
 * @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitComponents(io.apicurio.datamodels.core.models.common.Components)
 */
@Override
public void visitComponents(Components node) {
    Oas30Components components = (Oas30Components) node;
    node.accept(this.visitor);
    this.traverseCollection(components.getSchemaDefinitions());
    this.traverseCollection(components.getResponseDefinitions());
    this.traverseCollection(components.getParameterDefinitions());
    this.traverseCollection(components.getExampleDefinitions());
    this.traverseCollection(components.getRequestBodyDefinitions());
    this.traverseCollection(components.getHeaderDefinitions());
    this.traverseCollection(components.getSecuritySchemes());
    this.traverseCollection(components.getLinkDefinitions());
    this.traverseCollection(components.getCallbackDefinitions());
    this.traverseExtensions(node);
    this.traverseValidationProblems(node);
}
Also used : Oas30Components(io.apicurio.datamodels.openapi.v3.models.Oas30Components)

Example 3 with Oas30Components

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

the class Oas20to30TransformationVisitor method visitParameterDefinition.

/**
 * @see io.apicurio.datamodels.core.visitors.IVisitor#visitParameterDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
 */
@Override
public void visitParameterDefinition(IDefinition node) {
    Oas20ParameterDefinition pd20 = (Oas20ParameterDefinition) node;
    if (NodeCompat.equals(pd20.in, "body")) {
        Oas30Components parent30 = this.getOrCreateComponents();
        Oas30RequestBodyDefinition bodyDef30 = parent30.createRequestBodyDefinition(pd20.getName());
        parent30.addRequestBodyDefinition(pd20.getName(), bodyDef30);
        bodyDef30.description = pd20.description;
        bodyDef30.required = pd20.required;
        if (!NodeCompat.isNullOrUndefined(pd20.schema)) {
            List<String> consumes = this.findConsumes(pd20);
            Oas20Schema schema = (Oas20Schema) pd20.schema;
            consumes.forEach(ct -> {
                Oas30MediaType mediaType30 = bodyDef30.createMediaType(ct);
                bodyDef30.addMediaType(ct, mediaType30);
                Oas30Schema schema30 = mediaType30.createSchema();
                mediaType30.schema = this.toSchema(schema, schema30, true);
                this.mapNode(schema, schema30);
            });
        }
    } else if (NodeCompat.equals(pd20.in, "formData")) {
    // Exclude any re-usable formData parameters - they are currently being inlined elsewhere.  I'm not sure
    // what we would do with them anyway.
    } else {
        Oas30Components components30 = this.getOrCreateComponents();
        Oas30ParameterDefinition paramDef30 = components30.createParameterDefinition(pd20.getName());
        components30.addParameterDefinition(pd20.getName(), paramDef30);
        this.transformParam(pd20, paramDef30);
        this.mapNode(pd20, paramDef30);
    }
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas30Components(io.apicurio.datamodels.openapi.v3.models.Oas30Components) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas30RequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with Oas30Components

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

the class Oas20to30TransformationVisitor method visitResponseDefinition.

/**
 * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponseDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
 */
@Override
public void visitResponseDefinition(IDefinition node) {
    Oas30Components parent30 = this.getOrCreateComponents();
    Oas30ResponseDefinition responseDef30 = parent30.createResponseDefinition(node.getName());
    parent30.addResponseDefinition(node.getName(), responseDef30);
    this.transformResponse((Oas20Response) node, responseDef30);
    this.mapNode((Oas20Response) node, responseDef30);
}
Also used : Oas30Components(io.apicurio.datamodels.openapi.v3.models.Oas30Components) Oas30ResponseDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition)

Example 5 with Oas30Components

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

the class Oas20to30TransformationVisitor method visitSecurityScheme.

/**
 * @see io.apicurio.datamodels.core.visitors.IVisitor#visitSecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme)
 */
@Override
public void visitSecurityScheme(SecurityScheme node) {
    Oas20SecurityScheme scheme = (Oas20SecurityScheme) node;
    Oas30Components parent30 = this.getOrCreateComponents();
    Oas30SecurityScheme scheme30 = parent30.createSecurityScheme(scheme.getName());
    parent30.addSecurityScheme(scheme.getName(), scheme30);
    scheme30.type = scheme.type;
    scheme30.description = scheme.description;
    scheme30.name = scheme.name;
    scheme30.in = scheme.in;
    if (NodeCompat.equals(scheme.type, "oauth2")) {
        if (NodeCompat.equals(scheme.flow, "implicit")) {
            scheme30.flows = scheme30.createOAuthFlows();
            scheme30.flows.implicit = scheme30.flows.createImplicitOAuthFlow();
            scheme30.flows.implicit.authorizationUrl = scheme.authorizationUrl;
            if (!NodeCompat.isNullOrUndefined(scheme.scopes)) {
                scheme.scopes.getScopeNames().forEach(scopeName -> {
                    scheme30.flows.implicit.addScope(scopeName, scheme.scopes.getScopeDescription(scopeName));
                });
            }
        }
        if (NodeCompat.equals(scheme.flow, "accessCode")) {
            scheme30.flows = scheme30.createOAuthFlows();
            scheme30.flows.authorizationCode = scheme30.flows.createAuthorizationCodeOAuthFlow();
            scheme30.flows.authorizationCode.authorizationUrl = scheme.authorizationUrl;
            scheme30.flows.authorizationCode.tokenUrl = scheme.tokenUrl;
            if (!NodeCompat.isNullOrUndefined(scheme.scopes)) {
                scheme.scopes.getScopeNames().forEach(scopeName -> {
                    scheme30.flows.authorizationCode.addScope(scopeName, scheme.scopes.getScopeDescription(scopeName));
                });
            }
        }
        if (NodeCompat.equals(scheme.flow, "password")) {
            scheme30.flows = scheme30.createOAuthFlows();
            scheme30.flows.password = scheme30.flows.createPasswordOAuthFlow();
            scheme30.flows.password.tokenUrl = scheme.tokenUrl;
            if (!NodeCompat.isNullOrUndefined(scheme.scopes)) {
                scheme.scopes.getScopeNames().forEach(scopeName -> {
                    scheme30.flows.password.addScope(scopeName, scheme.scopes.getScopeDescription(scopeName));
                });
            }
        }
        if (NodeCompat.equals(scheme.flow, "application")) {
            scheme30.flows = scheme30.createOAuthFlows();
            scheme30.flows.clientCredentials = scheme30.flows.createClientCredentialsOAuthFlow();
            scheme30.flows.clientCredentials.tokenUrl = scheme.tokenUrl;
            if (!NodeCompat.isNullOrUndefined(scheme.scopes)) {
                scheme.scopes.getScopeNames().forEach(scopeName -> {
                    scheme30.flows.clientCredentials.addScope(scopeName, scheme.scopes.getScopeDescription(scopeName));
                });
            }
        }
    }
    this.mapNode(scheme, scheme30);
}
Also used : Oas30Components(io.apicurio.datamodels.openapi.v3.models.Oas30Components) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Oas20SecurityScheme(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme)

Aggregations

Oas30Components (io.apicurio.datamodels.openapi.v3.models.Oas30Components)6 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)3 Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)2 Oas30RequestBodyDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition)2 Oas30ResponseDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition)2 Oas30SecurityScheme (io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme)2 Oas20ParameterDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)1 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)1 Oas20SchemaDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)1 Oas20SecurityScheme (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme)1 Oas30CallbackDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition)1 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)1 Oas30ExampleDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition)1 Oas30HeaderDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)1 Oas30LinkDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition)1 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)1 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)1 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)1 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)1 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)1