var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
import { OasInvalidPropertyValueRule } from './OasInvalidPropertyValueRule';
/**
 * Constructor.
 * @param {ValidationRuleMetaData} ruleInfo
 * @class
 * @extends OasInvalidPropertyValueRule
 * @author eric.wittmann@gmail.com
 */
var OasMissingPathParamDefinitionRule = /** @class */ (function (_super) {
    __extends(OasMissingPathParamDefinitionRule, _super);
    function OasMissingPathParamDefinitionRule(ruleInfo) {
        var _this = _super.call(this, ruleInfo) || this;
        _this.pathItemsWithError = ([]);
        return _this;
    }
    /**
     * Returns true if the list of parameters includes a path param with the given name.
     * @param {string} paramName
     * @param {OasParameter[]} parameters
     * @return {boolean}
     * @private
     */
    /*private*/ OasMissingPathParamDefinitionRule.prototype.hasPathParameter = function (paramName, parameters) {
        for (var index150 = 0; index150 < parameters.length; index150++) {
            var parameter = parameters[index150];
            {
                if (this.equals(parameter.in, "path") && this.equals(parameter.name, paramName)) {
                    return true;
                }
            }
        }
        return false;
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)
     * @param {OasPathItem} node
     */
    OasMissingPathParamDefinitionRule.prototype.visitPathItem = function (node) {
        if (!this.isPathWellFormed(node.getPath())) {
            /* add */ (this.pathItemsWithError.push(node.getPath()) > 0);
        }
    };
    /**
     * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
     * @param {Operation} node
     */
    OasMissingPathParamDefinitionRule.prototype.visitOperation = function (node) {
        var pathItem = node.parent();
        var path = pathItem.getPath();
        if (this.pathItemsWithError.indexOf(path) !== -1) {
            return;
        }
        var mergedParameters = this.mergeParameters(node);
        var pathSegs = this.getPathSegments(path);
        for (var index151 = 0; index151 < pathSegs.length; index151++) {
            var pathSeg = pathSegs[index151];
            {
                if (!this.hasValue(pathSeg.formalName)) {
                    continue;
                }
                var valid = this.hasPathParameter(pathSeg.formalName, mergedParameters);
                this.reportIfInvalid(valid, node, null, this.map("param", pathSeg.formalName, "path", path, "method", node.getType().toUpperCase()));
            }
        }
    };
    return OasMissingPathParamDefinitionRule;
}(OasInvalidPropertyValueRule));
export { OasMissingPathParamDefinitionRule };
OasMissingPathParamDefinitionRule["__class"] = "io.apicurio.datamodels.core.validation.rules.invalid.value.OasMissingPathParamDefinitionRule";
OasMissingPathParamDefinitionRule["__interfaces"] = ["io.apicurio.datamodels.core.visitors.IVisitor", "io.apicurio.datamodels.asyncapi.v2.visitors.IAai20Visitor", "io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor", "io.apicurio.datamodels.asyncapi.visitors.IAaiVisitor", "io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor", "io.apicurio.datamodels.openapi.visitors.IOasVisitor"];
//# sourceMappingURL=OasMissingPathParamDefinitionRule.js.map