Search in sources :

Example 1 with ISecurityRequirementParent

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

the class DeleteSecurityRequirementCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteSecurityRequirementCommand] Reverting.");
    if (this.isNullOrUndefined(this._oldRequirement)) {
        return;
    }
    ISecurityRequirementParent parent = (ISecurityRequirementParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    SecurityRequirement restoredRequirement = parent.createSecurityRequirement();
    Library.readNode(this._oldRequirement, restoredRequirement);
    parent.addSecurityRequirement(restoredRequirement);
}
Also used : ISecurityRequirementParent(io.apicurio.datamodels.core.models.common.ISecurityRequirementParent) SecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)

Example 2 with ISecurityRequirementParent

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

the class DeleteAllSecurityRequirementsCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeleteAllSecurityRequirementsCommand] Reverting.");
    if (ModelUtils.isDefined(this._oldSecurityRequirements) && this._oldSecurityRequirements.size() == 0) {
        return;
    }
    ISecurityRequirementParent parent = (ISecurityRequirementParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    List<SecurityRequirement> requirements = parent.getSecurityRequirements();
    if (this.isNullOrUndefined(requirements)) {
        requirements = new ArrayList<>();
        NodeCompat.setProperty(parent, Constants.PROP_SECURITY, requirements);
    }
    for (Object oldSecurityRequirement : this._oldSecurityRequirements) {
        SecurityRequirement requirement = parent.createSecurityRequirement();
        Library.readNode(oldSecurityRequirement, requirement);
        requirements.add(requirement);
    }
}
Also used : ISecurityRequirementParent(io.apicurio.datamodels.core.models.common.ISecurityRequirementParent) SecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)

Example 3 with ISecurityRequirementParent

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

the class SecurityRequirementUniquenessValidationRule method visitSecurityRequirement.

/**
 * @param node
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
 */
public void visitSecurityRequirement(SecurityRequirement node) {
    ISecurityRequirementParent parent = (ISecurityRequirementParent) node.parent();
    List<SecurityRequirement> securityRequirements = parent.getSecurityRequirements();
    if (securityRequirements.size() <= 1) {
        return;
    }
    if (checkForDuplicates(node, securityRequirements)) {
        this.report(node, Constants.PROP_SECURITY, map("securityReq", node.getSecurityRequirementNames().toString()));
    }
}
Also used : ISecurityRequirementParent(io.apicurio.datamodels.core.models.common.ISecurityRequirementParent) SecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)

Example 4 with ISecurityRequirementParent

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

the class ReplaceSecurityRequirementCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[ReplaceSecurityRequirementCommand] Reverting.");
    if (!this._replaced) {
        return;
    }
    ISecurityRequirementParent parent = (ISecurityRequirementParent) this._parentPath.resolve(document);
    if (this.isNullOrUndefined(parent)) {
        return;
    }
    SecurityRequirement replacementRequirement = parent.createSecurityRequirement();
    Library.readNode(this._newRequirement, replacementRequirement);
    int idx = this.indexOfRequirement(parent.getSecurityRequirements(), replacementRequirement);
    if (idx == -1) {
        return;
    }
    SecurityRequirement originalRequirement = parent.createSecurityRequirement();
    Library.readNode(this._oldRequirement, originalRequirement);
    parent.getSecurityRequirements().set(idx, originalRequirement);
}
Also used : ISecurityRequirementParent(io.apicurio.datamodels.core.models.common.ISecurityRequirementParent) SecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)

Example 5 with ISecurityRequirementParent

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

the class Oas20to30TransformationVisitor method visitSecurityRequirement.

/**
 * @see io.apicurio.datamodels.core.visitors.IVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
 */
@Override
public void visitSecurityRequirement(SecurityRequirement node) {
    Oas20SecurityRequirement req = (Oas20SecurityRequirement) node;
    ISecurityRequirementParent parent30 = (ISecurityRequirementParent) this.lookup(req.parent());
    Oas30SecurityRequirement securityRequirement30 = (Oas30SecurityRequirement) parent30.createSecurityRequirement();
    parent30.addSecurityRequirement(securityRequirement30);
    req.getSecurityRequirementNames().forEach(name -> {
        securityRequirement30.addSecurityRequirementItem(name, req.getScopes(name));
    });
    this.mapNode(req, securityRequirement30);
}
Also used : Oas30SecurityRequirement(io.apicurio.datamodels.openapi.v3.models.Oas30SecurityRequirement) Oas20SecurityRequirement(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityRequirement) ISecurityRequirementParent(io.apicurio.datamodels.core.models.common.ISecurityRequirementParent)

Aggregations

ISecurityRequirementParent (io.apicurio.datamodels.core.models.common.ISecurityRequirementParent)10 SecurityRequirement (io.apicurio.datamodels.core.models.common.SecurityRequirement)9 Oas20SecurityRequirement (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityRequirement)1 Oas30SecurityRequirement (io.apicurio.datamodels.openapi.v3.models.Oas30SecurityRequirement)1