Search in sources :

Example 1 with Oas20ParameterDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition in project apicurio-data-models by Apicurio.

the class ChangeParameterDefinitionTypeCommand_20 method undo.

/**
 * @see io.apicurio.datamodels.cmd.commands.ChangeParameterTypeCommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[ChangeParameterDefinitionType] Reverting.");
    Oas20ParameterDefinition param = (Oas20ParameterDefinition) this._paramPath.resolve(document);
    if (this.isNullOrUndefined(param)) {
        return;
    }
    Oas20Document doc20 = (Oas20Document) document;
    // Remove the old/updated parameter.
    doc20.parameters.removeParameter(param.getName());
    // Restore the parameter from before the command executed.
    Oas20ParameterDefinition oldParam = doc20.parameters.createParameter(param.getName());
    Library.readNode(this._oldParameter, oldParam);
    doc20.parameters.addParameter(param.getName(), oldParam);
}
Also used : Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)

Example 2 with Oas20ParameterDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition 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 3 with Oas20ParameterDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition in project apicurio-data-models by Apicurio.

the class Oas20IReferenceManipulationStrategy method attachAsComponent.

@Override
public ReferenceAndNode attachAsComponent(Document document, String name, Node component) {
    if (!(document instanceof Oas20Document))
        throw new IllegalArgumentException("Oas20Document expected.");
    Oas20Document model = (Oas20Document) document;
    if (component instanceof Oas20Schema) {
        if (model.definitions == null)
            model.definitions = model.createDefinitions();
        if (model.definitions.getDefinition(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas20SchemaDefinition definition = wrap(component, new Oas20SchemaDefinition(name), model);
        definition.attachToParent(model.definitions);
        model.definitions.addDefinition(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "definitions/" + name, definition);
    }
    if (component instanceof Oas20Parameter) {
        if (model.parameters == null)
            model.parameters = model.createParameterDefinitions();
        if (model.parameters.getParameter(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas20ParameterDefinition definition = wrap(component, new Oas20ParameterDefinition(name), model);
        definition.attachToParent(model.parameters);
        model.parameters.addParameter(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "parameters/" + name, definition);
    }
    if (component instanceof Oas20Response) {
        if (model.responses == null)
            model.responses = model.createResponseDefinitions();
        if (model.responses.getResponse(name) != null)
            throw new IllegalArgumentException("Definition with that name already exists: " + name);
        Oas20ResponseDefinition definition = wrap(component, new Oas20ResponseDefinition(name), model);
        definition.attachToParent(model.responses);
        model.responses.addResponse(definition.getName(), definition);
        return new ReferenceAndNode(PREFIX + "responses/" + name, definition);
    }
    return null;
}
Also used : Oas20Schema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas20Response(io.apicurio.datamodels.openapi.v2.models.Oas20Response) Oas20SchemaDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20SchemaDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter) Oas20ResponseDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinition)

Example 4 with Oas20ParameterDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition in project syndesis by syndesisio.

the class Oas20DataShapeGeneratorHelper method getOperationParameters.

static List<Oas20Parameter> getOperationParameters(Oas20Document openApiDoc, Oas20Operation operation) {
    final List<Oas20Parameter> operationParameters = Oas20ModelHelper.getParameters(operation);
    OasPathItem parent = ofNullable(operation.parent()).filter(OasPathItem.class::isInstance).map(OasPathItem.class::cast).orElse(null);
    final List<Oas20Parameter> pathParameters = Oas20ModelHelper.getParameters(parent);
    operationParameters.addAll(pathParameters);
    final List<Oas20ParameterDefinition> globalParameters = ofNullable(openApiDoc.parameters).map(Oas20ParameterDefinitions::getItems).orElse(Collections.emptyList());
    operationParameters.addAll(globalParameters);
    return operationParameters;
}
Also used : OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)

Example 5 with Oas20ParameterDefinition

use of io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition in project apicurio-data-models by Apicurio.

the class Oas20DataModelReader method readParameterDefinitions.

/**
 * Reads the parameter definitions.
 * @param json
 * @param node
 */
public void readParameterDefinitions(Object json, Oas20ParameterDefinitions node) {
    List<String> names = JsonCompat.keys(json);
    for (String name : names) {
        Object definition = JsonCompat.consumeProperty(json, name);
        Oas20ParameterDefinition definitionModel = node.createParameter(name);
        this.readParameterDefinition(definition, definitionModel);
        node.addParameter(name, definitionModel);
    }
}
Also used : Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)

Aggregations

Oas20ParameterDefinition (io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition)6 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)2 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)2 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)2 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)2 Library (io.apicurio.datamodels.Library)1 JsonCompat (io.apicurio.datamodels.compat.JsonCompat)1 NodeCompat (io.apicurio.datamodels.compat.NodeCompat)1 Constants (io.apicurio.datamodels.core.Constants)1 Document (io.apicurio.datamodels.core.models.Document)1 DocumentType (io.apicurio.datamodels.core.models.DocumentType)1 ExtensibleNode (io.apicurio.datamodels.core.models.ExtensibleNode)1 Extension (io.apicurio.datamodels.core.models.Extension)1 IReferenceNode (io.apicurio.datamodels.core.models.IReferenceNode)1 Node (io.apicurio.datamodels.core.models.Node)1 NodePath (io.apicurio.datamodels.core.models.NodePath)1 ValidationProblem (io.apicurio.datamodels.core.models.ValidationProblem)1 Contact (io.apicurio.datamodels.core.models.common.Contact)1 ExternalDocumentation (io.apicurio.datamodels.core.models.common.ExternalDocumentation)1 IDefinition (io.apicurio.datamodels.core.models.common.IDefinition)1