Search in sources :

Example 1 with Oas30Response

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

the class Oas30DataModelWriter method writeResponse.

/**
 * @see io.apicurio.datamodels.openapi.io.OasDataModelWriter#writeResponse(java.lang.Object, io.apicurio.datamodels.openapi.models.OasResponse)
 */
@Override
protected void writeResponse(Object json, OasResponse node) {
    Oas30Response response = (Oas30Response) node;
    JsonCompat.setPropertyNull(json, Constants.PROP_HEADERS);
    JsonCompat.setPropertyNull(json, Constants.PROP_CONTENT);
    JsonCompat.setPropertyNull(json, Constants.PROP_LINKS);
    super.writeResponse(json, response);
}
Also used : Oas30Response(io.apicurio.datamodels.openapi.v3.models.Oas30Response)

Example 2 with Oas30Response

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

the class Oas30Traverser method traverseResponse.

/**
 * @see io.apicurio.datamodels.openapi.visitors.OasTraverser#traverseResponse(io.apicurio.datamodels.openapi.models.OasResponse)
 */
@Override
protected void traverseResponse(OasResponse node) {
    super.traverseResponse(node);
    Oas30Response response = (Oas30Response) node;
    this.traverseCollection(response.getHeaders());
    this.traverseCollection(response.getMediaTypes());
    this.traverseCollection(response.getLinks());
}
Also used : Oas30Response(io.apicurio.datamodels.openapi.v3.models.Oas30Response)

Example 3 with Oas30Response

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

the class Oas20to30TransformationVisitor method transformResponse.

private void transformResponse(Oas20Response node, Oas30Response response30) {
    response30.description = node.description;
    if (!NodeCompat.isNullOrUndefined(node.schema)) {
        List<String> produces = this.findProduces(node);
        Oas20Schema schema = node.schema;
        produces.forEach(ct -> {
            Oas30MediaType mediaType30 = response30.createMediaType(ct);
            response30.addMediaType(ct, mediaType30);
            Oas30Schema schema30 = mediaType30.createSchema();
            mediaType30.schema = this.toSchema(schema, schema30, true);
            if (!NodeCompat.isNullOrUndefined(node.examples)) {
                Object ctexample = node.examples.getExample(ct);
                if (!NodeCompat.isNullOrUndefined(ctexample)) {
                    mediaType30.example = ctexample;
                }
            }
            this.mapNode(schema, schema30);
        });
        // mark the Response as needing Content post-processing
        if (produces.size() > 1) {
            this._postProcessResponses.add(response30);
        }
    }
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with Oas30Response

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

the class Oas20to30TransformationVisitor method visitHeader.

/**
 * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitHeader(io.apicurio.datamodels.openapi.models.OasHeader)
 */
@Override
public void visitHeader(OasHeader node) {
    Oas30Response parent30 = (Oas30Response) this.lookup(node.parent());
    Oas30Header header30 = parent30.createHeader(node.getName());
    parent30.addHeader(node.getName(), header30);
    header30.description = node.description;
    header30.schema = this.toSchema(node, header30.createSchema(), false);
    this.mapNode(node, header30);
}
Also used : Oas30Response(io.apicurio.datamodels.openapi.v3.models.Oas30Response) Oas30Header(io.apicurio.datamodels.openapi.v3.models.Oas30Header)

Example 5 with Oas30Response

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

Aggregations

Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)13 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)6 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)5 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)5 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)4 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)4 Oas30Header (io.apicurio.datamodels.openapi.v3.models.Oas30Header)3 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)3 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)3 Test (org.junit.Test)3 Oas30Link (io.apicurio.datamodels.openapi.v3.models.Oas30Link)2 Oas30RequestBody (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody)2 Violation (io.syndesis.common.model.Violation)2 Map (java.util.Map)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ModernSecurityScheme (io.apicurio.datamodels.core.models.common.ModernSecurityScheme)1 Server (io.apicurio.datamodels.core.models.common.Server)1 ServerVariable (io.apicurio.datamodels.core.models.common.ServerVariable)1 OasOperation (io.apicurio.datamodels.openapi.models.OasOperation)1 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)1