Search in sources :

Example 1 with Oas30SchemaDefinition

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

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

the class ReplaceSchemaDefinitionCommand_30 method removeNode.

/**
 * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#removeNode(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.Node)
 */
@Override
protected void removeNode(Document doc, Oas30SchemaDefinition node) {
    Oas30Document doc30 = (Oas30Document) doc;
    doc30.components.removeSchemaDefinition(node.getName());
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document)

Example 3 with Oas30SchemaDefinition

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

the class ReplaceSchemaDefinitionCommand_30 method addNode.

/**
 * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#addNode(io.apicurio.datamodels.core.models.Document, io.apicurio.datamodels.core.models.Node)
 */
@Override
protected void addNode(Document doc, Oas30SchemaDefinition node) {
    Oas30Document doc30 = (Oas30Document) doc;
    node._ownerDocument = doc;
    node._parent = doc30.components;
    doc30.components.addSchemaDefinition(node.getName(), node);
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document)

Example 4 with Oas30SchemaDefinition

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

the class ReplaceSchemaDefinitionCommand_30 method readNode.

/**
 * @see io.apicurio.datamodels.cmd.commands.ReplaceNodeCommand#readNode(io.apicurio.datamodels.core.models.Document, java.lang.Object)
 */
@Override
protected Oas30SchemaDefinition readNode(Document doc, Object node) {
    Oas30Document doc30 = (Oas30Document) doc;
    Oas30SchemaDefinition definition = doc30.components.createSchemaDefinition(this._defName);
    Library.readNode(node, definition);
    return definition;
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30SchemaDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)

Example 5 with Oas30SchemaDefinition

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

the class RenameSchemaDefinitionCommand_30 method _renameSchemaDefinition.

/**
 * @see RenameSchemaDefinitionCommand#_renameSchemaDefinition(Document, String, String)
 */
@Override
protected boolean _renameSchemaDefinition(Document document, String fromName, String toName) {
    Oas30Document doc30 = (Oas30Document) document;
    if (this.isNullOrUndefined(doc30.components) || this.isNullOrUndefined(doc30.components.schemas)) {
        return false;
    }
    if (ModelUtils.isDefined(doc30.components.getSchemaDefinition(toName))) {
        return false;
    }
    Oas30SchemaDefinition schemaDef = doc30.components.removeSchemaDefinition(fromName);
    schemaDef.rename(toName);
    doc30.components.addSchemaDefinition(toName, schemaDef);
    return true;
}
Also used : Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30SchemaDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)

Aggregations

Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)10 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)9 Oas30CallbackDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition)2 Oas30Components (io.apicurio.datamodels.openapi.v3.models.Oas30Components)2 Oas30ExampleDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition)2 Oas30HeaderDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)2 Oas30LinkDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition)2 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)2 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 ModernSecurityScheme (io.apicurio.datamodels.core.models.common.ModernSecurityScheme)1 Oas20SchemaDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition)1 Oas30Callback (io.apicurio.datamodels.openapi.v3.models.Oas30Callback)1 Oas30Example (io.apicurio.datamodels.openapi.v3.models.Oas30Example)1 Oas30Header (io.apicurio.datamodels.openapi.v3.models.Oas30Header)1 Oas30Link (io.apicurio.datamodels.openapi.v3.models.Oas30Link)1 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)1 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)1