Search in sources :

Example 1 with Oas30Parameter

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

the class DeleteAllParameterExamplesCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[DeleteAllParameterExamplesCommand] Executing.");
    if (this.isNullOrUndefined(document)) {
        LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not execute the command, invalid argument.");
        return;
    }
    if (this.isNullOrUndefined(this._parameterPath)) {
        LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Could not execute the command, problem when unmarshalling.");
        return;
    }
    Oas30Parameter parameter = (Oas30Parameter) this._parameterPath.resolve(document);
    if (this.isNullOrUndefined(parameter)) {
        LoggerCompat.debug("[DeleteAllParameterExamplesCommand] Parameter not found.");
        return;
    }
    this._oldExamples = new HashMap<>();
    parameter.getExamples().forEach(e -> {
        this._oldExamples.put(e.getName(), Library.writeNode((Node) e));
    });
    parameter.clearExamples();
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Node(io.apicurio.datamodels.core.models.Node)

Example 2 with Oas30Parameter

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

the class ChangeParameterTypeCommand_30 method doRestoreParameter.

/**
 * @see io.apicurio.datamodels.cmd.commands.ChangeParameterTypeCommand#doRestoreParameter(io.apicurio.datamodels.core.models.common.Parameter, io.apicurio.datamodels.core.models.common.Parameter)
 */
@Override
protected void doRestoreParameter(Parameter parameter, Parameter oldParameter) {
    Oas30Parameter param = (Oas30Parameter) parameter;
    Oas30Parameter oldParam = (Oas30Parameter) oldParameter;
    param.schema = oldParam.schema;
    if (ModelUtils.isDefined(param.schema)) {
        param.schema._parent = param;
        param.schema._ownerDocument = param.ownerDocument();
    }
    param.required = oldParam.required;
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)

Example 3 with Oas30Parameter

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

the class Oas30DataModelReader method readParameter.

/**
 * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readParameter(java.lang.Object, io.apicurio.datamodels.core.models.common.Parameter)
 */
@Override
public void readParameter(Object json, Parameter node) {
    Oas30Parameter param = (Oas30Parameter) node;
    Boolean deprecated = JsonCompat.consumePropertyBoolean(json, Constants.PROP_DEPRECATED);
    String style = JsonCompat.consumePropertyString(json, Constants.PROP_STYLE);
    Boolean explode = JsonCompat.consumePropertyBoolean(json, Constants.PROP_EXPLODE);
    Boolean allowReserved = JsonCompat.consumePropertyBoolean(json, Constants.PROP_ALLOW_RESERVED);
    Object example = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLE);
    Object examples = JsonCompat.consumeProperty(json, Constants.PROP_EXAMPLES);
    Object content = JsonCompat.consumeProperty(json, Constants.PROP_CONTENT);
    param.deprecated = deprecated;
    param.style = style;
    param.explode = explode;
    param.allowReserved = allowReserved;
    param.example = example;
    if (examples != null) {
        JsonCompat.keys(examples).forEach(name -> {
            Object exx = JsonCompat.consumeProperty(examples, name);
            Oas30Example exampleModel = param.createExample(name);
            this.readExample(exx, exampleModel);
            param.addExample(exampleModel);
        });
    }
    if (content != null) {
        JsonCompat.keys(content).forEach(name -> {
            Object mediaType = JsonCompat.consumeProperty(content, name);
            Oas30MediaType mediaTypeModel = param.createMediaType(name);
            this.readMediaType(mediaType, mediaTypeModel);
            param.addMediaType(name, mediaTypeModel);
        });
    }
    super.readParameter(json, node);
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) Oas30Example(io.apicurio.datamodels.openapi.v3.models.Oas30Example) Oas30MediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)

Example 4 with Oas30Parameter

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

the class SetParameterExampleCommand_30 method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[SetParameterExampleCommand_30] Executing.");
    this._oldValue = null;
    this._nullExample = false;
    Oas30Parameter parameter = (Oas30Parameter) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parameter)) {
        return;
    }
    if (!this.isNullOrUndefined(this._newExampleName)) {
        if (this.isNullOrUndefined(parameter.getExample(this._newExampleName))) {
            parameter.addExample(parameter.createExample(this._newExampleName));
            this._nullExample = true;
        } else {
            this._oldValue = parameter.getExample(this._newExampleName).getValue();
        }
        parameter.getExample(this._newExampleName).setValue(this._newExample);
    } else {
        this._oldValue = parameter.getExample();
        parameter.setExample(this._newExample);
    }
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)

Example 5 with Oas30Parameter

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

the class SetParameterExampleCommand_30 method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[SetParameterExampleCommand_30] Reverting.");
    Oas30Parameter parameter = (Oas30Parameter) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parameter)) {
        return;
    }
    if (!this.isNullOrUndefined(this._newExampleName)) {
        if (this._nullExample) {
            parameter.removeExample(this._newExampleName);
        } else {
            parameter.getExample(this._newExampleName).setValue(this._oldValue);
        }
    } else {
        parameter.setExample(this._oldValue);
        this._oldValue = null;
    }
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)

Aggregations

Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)33 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)15 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)13 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)12 Test (org.junit.Test)12 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)9 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)8 Oas30Example (io.apicurio.datamodels.openapi.v3.models.Oas30Example)5 Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)5 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)5 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)4 Node (io.apicurio.datamodels.core.models.Node)3 Oas30SchemaDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30SchemaDefinition)3 IExample (io.apicurio.datamodels.core.models.common.IExample)2 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)2 Oas30Components (io.apicurio.datamodels.openapi.v3.models.Oas30Components)2 Oas30RequestBody (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Library (io.apicurio.datamodels.Library)1 JsonCompat (io.apicurio.datamodels.compat.JsonCompat)1