Search in sources :

Example 1 with Oas30Callback

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

the class Oas30DataModelReader method readOperation.

/**
 * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readOperation(java.lang.Object, io.apicurio.datamodels.core.models.common.Operation)
 */
@Override
public void readOperation(Object json, Operation node) {
    Oas30Operation operation = (Oas30Operation) node;
    Object requestBody = JsonCompat.consumeProperty(json, Constants.PROP_REQUEST_BODY);
    Object callbacks = JsonCompat.consumeProperty(json, Constants.PROP_CALLBACKS);
    List<Object> servers = JsonCompat.consumePropertyArray(json, Constants.PROP_SERVERS);
    if (requestBody != null) {
        operation.requestBody = operation.createRequestBody();
        this.readRequestBody(requestBody, operation.requestBody);
    }
    if (callbacks != null) {
        JsonCompat.keys(callbacks).forEach(name -> {
            Object callback = JsonCompat.consumeProperty(callbacks, name);
            Oas30Callback callbackModel = operation.createCallback(name);
            this.readCallback(callback, callbackModel);
            operation.addCallback(name, callbackModel);
        });
    }
    if (servers != null) {
        servers.forEach(server -> {
            Oas30Server serverModel = (Oas30Server) operation.createServer();
            this.readServer(server, serverModel);
            operation.addServer(serverModel);
        });
    }
    super.readOperation(json, node);
}
Also used : Oas30Server(io.apicurio.datamodels.openapi.v3.models.Oas30Server) Oas30Callback(io.apicurio.datamodels.openapi.v3.models.Oas30Callback) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation)

Example 2 with Oas30Callback

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

the class Oas30IReferenceManipulationStrategy method attachAsComponent.

@Override
public ReferenceAndNode attachAsComponent(Document document, String name, Node component) {
    // TODO visitor?
    if (// TODO get documenttype
    !(document instanceof Oas30Document))
        throw new IllegalArgumentException("Oas30Document expected.");
    Oas30Document model = (Oas30Document) document;
    if (component instanceof Oas30Schema) {
        if (model.components.getSchemaDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30SchemaDefinition definition = wrap(component, new Oas30SchemaDefinition(name), model);
        // TODO this should be done by vvv
        definition.attachToParent(model.components);
        model.components.addSchemaDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "schemas/" + name, definition);
    }
    if (component instanceof Oas30Response) {
        if (model.components.getResponseDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30ResponseDefinition definition = wrap(component, new Oas30ResponseDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addResponseDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "responses/" + name, definition);
    }
    if (component instanceof Oas30Parameter) {
        if (model.components.getParameterDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30ParameterDefinition definition = wrap(component, new Oas30ParameterDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addParameterDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "parameters/" + name, definition);
    }
    if (component instanceof Oas30Example) {
        if (model.components.getExampleDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30ExampleDefinition definition = wrap(component, new Oas30ExampleDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addExampleDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "examples/" + name, definition);
    }
    if (component instanceof Oas30RequestBody) {
        if (model.components.getRequestBodyDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30RequestBodyDefinition definition = wrap(component, new Oas30RequestBodyDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addRequestBodyDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "requestBodies/" + name, definition);
    }
    if (component instanceof Oas30Header) {
        if (model.components.getHeaderDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30HeaderDefinition definition = wrap(component, new Oas30HeaderDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addHeaderDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "headers/" + name, definition);
    }
    if (component instanceof ModernSecurityScheme) {
        if (model.components.getSecurityScheme(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30SecurityScheme definition = wrap(component, new Oas30SecurityScheme(name), model);
        definition.attachToParent(model.components);
        model.components.addSecurityScheme(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "securitySchemes/" + name, definition);
    }
    if (component instanceof Oas30Link) {
        if (model.components.getLinkDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30LinkDefinition definition = wrap(component, new Oas30LinkDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addLinkDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "links/" + name, definition);
    }
    if (component instanceof Oas30Callback) {
        if (model.components.getCallbackDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas30CallbackDefinition definition = wrap(component, new Oas30CallbackDefinition(name), model);
        definition.attachToParent(model.components);
        model.components.addCallbackDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "callbacks/" + name, definition);
    }
    return null;
}
Also used : ModernSecurityScheme(io.apicurio.datamodels.core.models.common.ModernSecurityScheme) Oas30CallbackDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition) Oas30SchemaDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition) Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example) Oas30Callback(io.apicurio.datamodels.openapi.v3.models.Oas30Callback) Oas30RequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition) Oas30ResponseDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30Header(io.apicurio.datamodels.openapi.v3.models.Oas30Header) Oas30HeaderDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) Oas30ExampleDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition) Oas30LinkDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition) Oas30ParameterDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition) Oas30RequestBody(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody) Oas30Link(io.apicurio.datamodels.openapi.v3.models.Oas30Link) Oas30SecurityScheme(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityScheme) Oas30Response(io.apicurio.datamodels.openapi.v3.models.Oas30Response)

Example 3 with Oas30Callback

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

the class Oas30DataModelReader method readCallback.

/**
 * Reads an OAS 3.0 Callback object from the given JS data.
 * @param json
 * @param node
 */
public void readCallback(Object json, Oas30Callback node) {
    JsonCompat.keys(json).forEach(name -> {
        if (NodeCompat.equals(name, Constants.PROP_$REF)) {
            node.$ref = JsonCompat.consumePropertyString(json, name);
        } else {
            Object pathItem = JsonCompat.consumeProperty(json, name);
            Oas30CallbackPathItem pathItemModel = node.createPathItem(name);
            this.readPathItem(pathItem, pathItemModel);
            node.addPathItem(name, pathItemModel);
        }
    });
    this.readExtensions(json, node);
    this.readExtraProperties(json, node);
}
Also used : Oas30CallbackPathItem(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackPathItem)

Aggregations

Oas30Callback (io.apicurio.datamodels.openapi.v3.models.Oas30Callback)2 ModernSecurityScheme (io.apicurio.datamodels.core.models.common.ModernSecurityScheme)1 Oas30CallbackDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition)1 Oas30CallbackPathItem (io.apicurio.datamodels.openapi.v3.models.Oas30CallbackPathItem)1 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)1 Oas30Example (io.apicurio.datamodels.openapi.v3.models.Oas30Example)1 Oas30ExampleDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition)1 Oas30Header (io.apicurio.datamodels.openapi.v3.models.Oas30Header)1 Oas30HeaderDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)1 Oas30Link (io.apicurio.datamodels.openapi.v3.models.Oas30Link)1 Oas30LinkDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition)1 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)1 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)1 Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)1 Oas30RequestBody (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody)1 Oas30RequestBodyDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition)1 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)1 Oas30ResponseDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition)1 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)1 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)1