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