Search in sources :

Example 1 with Node

use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.

the class DeleteAllExamplesCommand method execute.

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

Example 2 with Node

use of io.apicurio.datamodels.core.models.Node 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 3 with Node

use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.

the class DeleteExampleCommand_30 method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[DeleteExampleCommand] Executing.");
    this._oldExample = null;
    IExamplesParent parent = (IExamplesParent) this._mediaTypePath.resolve(document);
    if (this.isNullOrUndefined(parent) || this.isNullOrUndefined(parent.getExample(this._exampleName))) {
        LoggerCompat.debug("[DeleteExampleCommand] No example named: " + this._exampleName);
        return;
    }
    IExample example = parent.removeExample(this._exampleName);
    this._oldExample = Library.writeNode((Node) example);
}
Also used : IExample(io.apicurio.datamodels.core.models.common.IExample) Node(io.apicurio.datamodels.core.models.Node) IExamplesParent(io.apicurio.datamodels.core.models.common.IExamplesParent)

Example 4 with Node

use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.

the class ChangePropertyCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@SuppressWarnings("unchecked")
@Override
public void execute(Document document) {
    LoggerCompat.info("[ChangePropertyCommand] Executing.");
    Node node = this._nodePath.resolve(document);
    if (this.isNullOrUndefined(node)) {
        return;
    }
    this._oldValue = (T) NodeCompat.getProperty(node, this._property);
    NodeCompat.setProperty(node, this._property, this._newValue);
}
Also used : Node(io.apicurio.datamodels.core.models.Node)

Example 5 with Node

use of io.apicurio.datamodels.core.models.Node in project apicurio-data-models by Apicurio.

the class ChangePropertyTypeCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[ChangePropertyTypeCommand] Executing: " + this._newType);
    IPropertySchema prop = (IPropertySchema) this._propPath.resolve(document);
    if (this.isNullOrUndefined(prop)) {
        return;
    }
    IPropertyParent parent = (IPropertyParent) ((Node) prop).parent();
    List<String> required = parent.getRequiredProperties();
    // Save the old info (for later undo operation)
    this._oldProperty = Library.writeNode((Node) prop);
    this._oldRequired = ModelUtils.isDefined(required) && required.size() > 0 && required.indexOf(prop.getPropertyName()) != -1;
    // Update the schema's type
    SimplifiedTypeUtil.setSimplifiedType((Schema) prop, this._newType);
    if (!this.isNullOrUndefined(this._newType.required)) {
        // Going from optional to required
        if (Boolean.TRUE.equals(this._newType.required) && !this._oldRequired) {
            if (this.isNullOrUndefined(required)) {
                required = new ArrayList<>();
                parent.setRequiredProperties(required);
                this._nullRequired = true;
            }
            required.add(prop.getPropertyName());
        }
        // Going from required to optional - remove property name from required list.
        if (Boolean.FALSE.equals(this._newType.required) && this._oldRequired) {
            required.remove(required.indexOf(prop.getPropertyName()));
        }
    }
}
Also used : IPropertyParent(io.apicurio.datamodels.core.models.common.IPropertyParent) Node(io.apicurio.datamodels.core.models.Node) IPropertySchema(io.apicurio.datamodels.core.models.common.IPropertySchema)

Aggregations

Node (io.apicurio.datamodels.core.models.Node)26 Document (io.apicurio.datamodels.core.models.Document)7 NodePath (io.apicurio.datamodels.core.models.NodePath)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 DocumentType (io.apicurio.datamodels.core.models.DocumentType)3 IReferenceNode (io.apicurio.datamodels.core.models.IReferenceNode)3 IExample (io.apicurio.datamodels.core.models.common.IExample)3 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)3 URL (java.net.URL)3 AaiSchema (io.apicurio.datamodels.asyncapi.models.AaiSchema)2 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)2 JsonCompat (io.apicurio.datamodels.compat.JsonCompat)2 Constants (io.apicurio.datamodels.core.Constants)2 ExtensibleNode (io.apicurio.datamodels.core.models.ExtensibleNode)2 Extension (io.apicurio.datamodels.core.models.Extension)2 ValidationProblem (io.apicurio.datamodels.core.models.ValidationProblem)2 IDefinition (io.apicurio.datamodels.core.models.common.IDefinition)2 IExamplesParent (io.apicurio.datamodels.core.models.common.IExamplesParent)2 IPropertySchema (io.apicurio.datamodels.core.models.common.IPropertySchema)2