use of io.apicurio.datamodels.openapi.v3.models.Oas30MediaType in project apicurio-data-models by Apicurio.
the class DeleteExampleCommand_30 method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteExampleCommand] Reverting.");
if (this.isNullOrUndefined(this._oldExample)) {
return;
}
Oas30MediaType mediaType = (Oas30MediaType) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(mediaType)) {
LoggerCompat.info("[DeleteExampleCommand] No media type found.");
return;
}
IExample example = mediaType.createExample(this._exampleName);
Library.readNode(this._oldExample, (Node) example);
mediaType.addExample(example);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30MediaType in project apicurio-data-models by Apicurio.
the class DeleteMediaTypeCommand method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[DeleteMediaTypeCommand] Reverting.");
if (this.isNullOrUndefined(this._oldMediaType)) {
return;
}
IOas30MediaTypeParent parent = (IOas30MediaTypeParent) this._parentPath.resolve(document);
if (this.isNullOrUndefined(parent)) {
return;
}
Oas30MediaType mediaType = parent.createMediaType(this._mediaTypeName);
Library.readNode(this._oldMediaType, mediaType);
parent.addMediaType(this._mediaTypeName, mediaType);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30MediaType in project apicurio-data-models by Apicurio.
the class ChangeMediaTypeTypeCommand method execute.
/**
* @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void execute(Document document) {
LoggerCompat.info("[ChangeMediaTypeTypeCommand] Executing.");
this._changed = false;
Oas30MediaType mediaType = (Oas30MediaType) this._mediaTypePath.resolve(document);
if (this.isNullOrUndefined(mediaType)) {
return;
}
// Save the old info (for later undo operation)
if (this.isNullOrUndefined(mediaType.schema)) {
this._oldMediaTypeSchema = null;
mediaType.schema = mediaType.createSchema();
} else {
this._oldMediaTypeSchema = Library.writeNode(mediaType.schema);
}
// Update the media type schema's type
SimplifiedTypeUtil.setSimplifiedType(mediaType.schema, this._newType);
this._changed = true;
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30MediaType in project apicurio-data-models by Apicurio.
the class AddExampleCommand_30 method undo.
/**
* @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
*/
@Override
public void undo(Document document) {
LoggerCompat.info("[AddExampleCommand_30] Reverting.");
if (!this._exampleAdded) {
return;
}
Oas30MediaType mediaType = (Oas30MediaType) this._parentPath.resolve(document);
if (this.isNullOrUndefined(mediaType) || this.isNullOrUndefined(mediaType.examples)) {
return;
}
mediaType.removeExample(this._newExampleName);
}
use of io.apicurio.datamodels.openapi.v3.models.Oas30MediaType 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);
}
Aggregations