Search in sources :

Example 1 with OasParameter

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

the class NewParamCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[NewParamCommand] Executing.");
    this._created = false;
    IOasParameterParent parent = (IOasParameterParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        LoggerCompat.info("[NewParamCommand] Parent node (operation or path item) is null.");
        return;
    }
    if (this.hasParam(this._paramName, this._paramType, parent)) {
        LoggerCompat.info("[NewParamCommand] Param %s of type %s already exists.", this._paramName, this._paramType);
        return;
    }
    List<OasParameter> parameters = parent.getParameters();
    if (this.isNullOrUndefined(parameters)) {
        parameters = new ArrayList<>();
        NodeCompat.setProperty(parent, Constants.PROP_PARAMETERS, parameters);
    }
    OasParameter param = parent.createParameter();
    boolean configured = false;
    // If overriding a param from the path level, clone it!
    if (this._override) {
        OasParameter oparam = this.findOverridableParam((OasOperation) parent);
        if (ModelUtils.isDefined(oparam)) {
            Library.readNode(Library.writeNode(oparam), param);
            configured = true;
        }
    }
    // If not overriding, then set the basics only.
    if (!configured) {
        param.in = this._paramType;
        param.name = this._paramName;
        if (NodeCompat.equals(param.in, "path")) {
            param.required = true;
        }
        if (ModelUtils.isDefined(this._description)) {
            param.description = this._description;
        }
        if (ModelUtils.isDefined(this._newType)) {
            this._setParameterType(param);
        }
    }
    parent.addParameter(param);
    LoggerCompat.info("[NewParamCommand] Param %s of type %s created successfully.", param.name, param.in);
    this._created = true;
}
Also used : OasParameter(io.apicurio.datamodels.openapi.models.OasParameter) IOasParameterParent(io.apicurio.datamodels.openapi.models.IOasParameterParent)

Example 2 with OasParameter

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

the class NewParamCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[NewParamCommand] Reverting.");
    if (!this._created) {
        return;
    }
    IOasParameterParent parent = (IOasParameterParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    OasParameter theParam = null;
    List<OasParameter> parameters = parent.getParameters();
    for (OasParameter param : parameters) {
        if (NodeCompat.equals(param.in, this._paramType) && NodeCompat.equals(param.name, this._paramName)) {
            theParam = param;
            break;
        }
    }
    // If found, remove it from the params.
    if (ModelUtils.isDefined(theParam)) {
        parameters.remove(parameters.indexOf(theParam));
        if (parameters.size() == 0) {
            NodeCompat.setProperty(parent, Constants.PROP_PARAMETERS, null);
        }
    }
}
Also used : OasParameter(io.apicurio.datamodels.openapi.models.OasParameter) IOasParameterParent(io.apicurio.datamodels.openapi.models.IOasParameterParent)

Example 3 with OasParameter

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

the class NewParamCommand method findOverridableParam.

/**
 * Tries to find the parameter being overridden (if any).  Returns null if it can't
 * find something.
 */
public OasParameter findOverridableParam(OasOperation operation) {
    OasParameter rval = null;
    OasPathItem pathItem = (OasPathItem) operation.parent();
    if (ModelUtils.isDefined(pathItem)) {
        rval = pathItem.getParameter(this._paramType, this._paramName);
    }
    return rval;
}
Also used : OasParameter(io.apicurio.datamodels.openapi.models.OasParameter) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)

Example 4 with OasParameter

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

the class Oas30PathItem method createParameter.

/**
 * @see io.apicurio.datamodels.openapi.models.OasPathItem#createParameter()
 */
@Override
public OasParameter createParameter() {
    OasParameter rval = new Oas30Parameter();
    rval._ownerDocument = this.ownerDocument();
    rval._parent = this;
    return rval;
}
Also used : OasParameter(io.apicurio.datamodels.openapi.models.OasParameter)

Example 5 with OasParameter

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

the class OasBodyParameterUniquenessValidationRule method visitParameter.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitParameter(io.apicurio.datamodels.core.models.common.Parameter)
 */
@Override
public void visitParameter(Parameter node) {
    OasParameter param = (OasParameter) node;
    List<OasParameter> params = ((IOasParameterParent) (node.parent())).getParameters();
    if (equals(param.in, "body")) {
        int count = countBodyParams(params);
        this.reportIf(count > 1, node, Constants.PROP_IN, map());
    }
}
Also used : OasParameter(io.apicurio.datamodels.openapi.models.OasParameter) IOasParameterParent(io.apicurio.datamodels.openapi.models.IOasParameterParent)

Aggregations

OasParameter (io.apicurio.datamodels.openapi.models.OasParameter)30 IOasParameterParent (io.apicurio.datamodels.openapi.models.IOasParameterParent)8 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)7 ArrayList (java.util.ArrayList)5 OasOperation (io.apicurio.datamodels.openapi.models.OasOperation)4 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)3 Citrus (com.consol.citrus.Citrus)2 CitrusSettings (com.consol.citrus.CitrusSettings)2 TestCaseRunner (com.consol.citrus.TestCaseRunner)2 CitrusAnnotations (com.consol.citrus.annotations.CitrusAnnotations)2 CitrusFramework (com.consol.citrus.annotations.CitrusFramework)2 CitrusResource (com.consol.citrus.annotations.CitrusResource)2 TestContext (com.consol.citrus.context.TestContext)2 OasResponse (io.apicurio.datamodels.openapi.models.OasResponse)2 Before (io.cucumber.java.Before)2 Scenario (io.cucumber.java.Scenario)2 And (io.cucumber.java.en.And)2 Given (io.cucumber.java.en.Given)2 Then (io.cucumber.java.en.Then)2 When (io.cucumber.java.en.When)2