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;
}
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);
}
}
}
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;
}
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;
}
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());
}
}
Aggregations