@redocly/openapi-core 1.0.0-beta.101 → 1.0.0-beta.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/lib/config/config.d.ts +3 -3
  2. package/lib/config/load.d.ts +1 -1
  3. package/lib/config/load.js +15 -2
  4. package/lib/config/rules.d.ts +1 -1
  5. package/lib/config/types.d.ts +4 -2
  6. package/lib/decorators/common/filters/filter-helper.d.ts +3 -0
  7. package/lib/decorators/common/filters/filter-helper.js +67 -0
  8. package/lib/decorators/common/filters/filter-in.d.ts +2 -0
  9. package/lib/decorators/common/filters/filter-in.js +17 -0
  10. package/lib/decorators/common/filters/filter-out.d.ts +2 -0
  11. package/lib/decorators/common/filters/filter-out.js +17 -0
  12. package/lib/decorators/oas2/index.d.ts +2 -0
  13. package/lib/decorators/oas2/index.js +5 -1
  14. package/lib/decorators/oas3/index.d.ts +2 -0
  15. package/lib/decorators/oas3/index.js +5 -1
  16. package/lib/index.d.ts +1 -1
  17. package/lib/lint.d.ts +2 -0
  18. package/lib/lint.js +2 -2
  19. package/lib/redocly/registry-api-types.d.ts +2 -0
  20. package/lib/redocly/registry-api.d.ts +1 -1
  21. package/lib/redocly/registry-api.js +3 -1
  22. package/lib/rules/ajv.d.ts +1 -1
  23. package/lib/rules/ajv.js +1 -1
  24. package/lib/rules/common/assertions/asserts.d.ts +6 -1
  25. package/lib/rules/common/assertions/asserts.js +81 -51
  26. package/lib/rules/common/assertions/utils.d.ts +2 -1
  27. package/lib/rules/common/assertions/utils.js +27 -8
  28. package/lib/types/redocly-yaml.js +317 -27
  29. package/lib/utils.d.ts +2 -1
  30. package/lib/utils.js +5 -1
  31. package/lib/walk.d.ts +4 -14
  32. package/lib/walk.js +35 -26
  33. package/package.json +3 -2
  34. package/src/__tests__/lint.test.ts +17 -4
  35. package/src/config/__tests__/load.test.ts +6 -0
  36. package/src/config/load.ts +28 -5
  37. package/src/config/types.ts +6 -5
  38. package/src/decorators/__tests__/filter-in.test.ts +310 -0
  39. package/src/decorators/__tests__/filter-out.test.ts +331 -0
  40. package/src/decorators/common/filters/filter-helper.ts +72 -0
  41. package/src/decorators/common/filters/filter-in.ts +18 -0
  42. package/src/decorators/common/filters/filter-out.ts +18 -0
  43. package/src/decorators/oas2/index.ts +5 -1
  44. package/src/decorators/oas3/index.ts +5 -1
  45. package/src/index.ts +1 -0
  46. package/src/lint.ts +4 -3
  47. package/src/redocly/registry-api-types.ts +2 -0
  48. package/src/redocly/registry-api.ts +4 -0
  49. package/src/rules/ajv.ts +4 -4
  50. package/src/rules/common/assertions/__tests__/asserts.test.ts +149 -146
  51. package/src/rules/common/assertions/asserts.ts +97 -52
  52. package/src/rules/common/assertions/utils.ts +41 -16
  53. package/src/types/redocly-yaml.ts +322 -34
  54. package/src/utils.ts +10 -7
  55. package/src/walk.ts +59 -47
  56. package/tsconfig.tsbuildinfo +1 -1
@@ -31,13 +31,13 @@ export declare class LintConfig {
31
31
  addProblemToIgnore(problem: NormalizedProblem): NormalizedProblem;
32
32
  extendTypes(types: Record<string, NodeType>, version: OasVersion): Record<string, NodeType>;
33
33
  getRuleSettings(ruleId: string, oasVersion: OasVersion): {
34
- severity: import("../walk").ProblemSeverity | "off";
34
+ severity: import("./types").RuleSeverity;
35
35
  };
36
36
  getPreprocessorSettings(ruleId: string, oasVersion: OasVersion): {
37
- severity: import("../walk").ProblemSeverity | "off";
37
+ severity: import("./types").RuleSeverity;
38
38
  };
39
39
  getDecoratorSettings(ruleId: string, oasVersion: OasVersion): {
40
- severity: import("../walk").ProblemSeverity | "off";
40
+ severity: import("./types").RuleSeverity;
41
41
  };
42
42
  getUnusedRules(): {
43
43
  rules: string[];
@@ -1,6 +1,6 @@
1
1
  import { Config } from './config';
2
2
  import type { RawConfig } from './types';
3
- export declare function loadConfig(configPath?: string | undefined, customExtends?: string[]): Promise<Config>;
3
+ export declare function loadConfig(configPath?: string | undefined, customExtends?: string[], processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>): Promise<Config>;
4
4
  export declare const CONFIG_FILE_NAMES: string[];
5
5
  export declare function findConfig(dir?: string): string | undefined;
6
6
  export declare function getConfig(configPath?: string | undefined): Promise<RawConfig>;
@@ -17,10 +17,9 @@ const utils_1 = require("../utils");
17
17
  const config_1 = require("./config");
18
18
  const utils_2 = require("./utils");
19
19
  const config_resolvers_1 = require("./config-resolvers");
20
- function loadConfig(configPath = findConfig(), customExtends) {
20
+ function addConfigMetadata({ rawConfig, customExtends, configPath }) {
21
21
  var _a;
22
22
  return __awaiter(this, void 0, void 0, function* () {
23
- const rawConfig = yield getConfig(configPath);
24
23
  if (customExtends !== undefined) {
25
24
  rawConfig.lint = rawConfig.lint || {};
26
25
  rawConfig.lint.extends = customExtends;
@@ -61,7 +60,21 @@ function loadConfig(configPath = findConfig(), customExtends) {
61
60
  return config_resolvers_1.resolveConfig(rawConfig, configPath);
62
61
  });
63
62
  }
63
+ function loadConfig(configPath = findConfig(), customExtends, processRawConfig) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const rawConfig = yield getConfig(configPath);
66
+ if (typeof processRawConfig === 'function') {
67
+ yield processRawConfig(rawConfig);
68
+ }
69
+ return yield addConfigMetadata({
70
+ rawConfig,
71
+ customExtends,
72
+ configPath,
73
+ });
74
+ });
75
+ }
64
76
  exports.loadConfig = loadConfig;
77
+ ;
65
78
  exports.CONFIG_FILE_NAMES = ['redocly.yaml', 'redocly.yml', '.redocly.yaml', '.redocly.yml'];
66
79
  function findConfig(dir) {
67
80
  if (!fs.hasOwnProperty('existsSync'))
@@ -1,7 +1,7 @@
1
1
  import { RuleSet, OasVersion } from '../oas-types';
2
2
  import { LintConfig } from './config';
3
3
  export declare function initRules<T extends Function, P extends RuleSet<T>>(rules: P[], config: LintConfig, type: 'rules' | 'preprocessors' | 'decorators', oasVersion: OasVersion): {
4
- severity: import("..").ProblemSeverity | "off";
4
+ severity: import("./types").RuleSeverity;
5
5
  ruleId: string;
6
6
  visitor: any;
7
7
  }[];
@@ -1,10 +1,12 @@
1
1
  import type { ProblemSeverity } from '../walk';
2
2
  import type { Oas3PreprocessorsSet, OasMajorVersion, Oas3DecoratorsSet, Oas2RuleSet, Oas2PreprocessorsSet, Oas2DecoratorsSet, Oas3RuleSet, OasVersion } from '../oas-types';
3
3
  import type { NodeType } from '../types';
4
- export declare type RuleConfig = ProblemSeverity | 'off' | ({
4
+ export declare type RuleSeverity = ProblemSeverity | 'off';
5
+ export declare type PreprocessorSeverity = RuleSeverity | 'on';
6
+ export declare type RuleConfig = RuleSeverity | ({
5
7
  severity?: ProblemSeverity;
6
8
  } & Record<string, any>);
7
- export declare type PreprocessorConfig = ProblemSeverity | 'off' | 'on' | ({
9
+ export declare type PreprocessorConfig = PreprocessorSeverity | ({
8
10
  severity?: ProblemSeverity;
9
11
  } & Record<string, any>);
10
12
  export declare type DecoratorConfig = PreprocessorConfig;
@@ -0,0 +1,3 @@
1
+ import { UserContext } from '../../../walk';
2
+ export declare function filter(node: any, ctx: UserContext, criteria: (item: any) => boolean): void;
3
+ export declare function checkIfMatchByStrategy(nodeValue: any, decoratorValue: any, strategy: 'all' | 'any'): boolean;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkIfMatchByStrategy = exports.filter = void 0;
4
+ const ref_utils_1 = require("../../../ref-utils");
5
+ const utils_1 = require("../../../utils");
6
+ function filter(node, ctx, criteria) {
7
+ const { parent, key } = ctx;
8
+ let didDelete = false;
9
+ if (Array.isArray(node)) {
10
+ for (let i = 0; i < node.length; i++) {
11
+ if (ref_utils_1.isRef(node[i])) {
12
+ const resolved = ctx.resolve(node[i]);
13
+ if (criteria(resolved.node)) {
14
+ node.splice(i, 1);
15
+ didDelete = true;
16
+ i--;
17
+ }
18
+ }
19
+ if (criteria(node[i])) {
20
+ node.splice(i, 1);
21
+ didDelete = true;
22
+ i--;
23
+ }
24
+ }
25
+ }
26
+ else if (utils_1.isPlainObject(node)) {
27
+ for (const key of Object.keys(node)) {
28
+ node = node;
29
+ if (ref_utils_1.isRef(node[key])) {
30
+ const resolved = ctx.resolve(node[key]);
31
+ if (criteria(resolved.node)) {
32
+ delete node[key];
33
+ didDelete = true;
34
+ }
35
+ }
36
+ if (criteria(node[key])) {
37
+ delete node[key];
38
+ didDelete = true;
39
+ }
40
+ }
41
+ }
42
+ if (didDelete && (utils_1.isEmptyObject(node) || utils_1.isEmptyArray(node))) {
43
+ delete parent[key];
44
+ }
45
+ }
46
+ exports.filter = filter;
47
+ function checkIfMatchByStrategy(nodeValue, decoratorValue, strategy) {
48
+ if (nodeValue === undefined || decoratorValue === undefined) {
49
+ return false;
50
+ }
51
+ if (!Array.isArray(decoratorValue) && !Array.isArray(nodeValue)) {
52
+ return nodeValue === decoratorValue;
53
+ }
54
+ decoratorValue = toArrayIfNeeded(decoratorValue);
55
+ nodeValue = toArrayIfNeeded(nodeValue);
56
+ if (strategy === 'any') {
57
+ return decoratorValue.some((item) => nodeValue.includes(item));
58
+ }
59
+ if (strategy === 'all') {
60
+ return decoratorValue.every((item) => nodeValue.includes(item));
61
+ }
62
+ return false;
63
+ }
64
+ exports.checkIfMatchByStrategy = checkIfMatchByStrategy;
65
+ function toArrayIfNeeded(value) {
66
+ return Array.isArray(value) ? value : [value];
67
+ }
@@ -0,0 +1,2 @@
1
+ import { Oas2Decorator, Oas3Decorator } from '../../../visitors';
2
+ export declare const FilterIn: Oas3Decorator | Oas2Decorator;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterIn = void 0;
4
+ const filter_helper_1 = require("./filter-helper");
5
+ const DEFAULT_STRATEGY = 'any';
6
+ const FilterIn = ({ property, value, matchStrategy }) => {
7
+ const strategy = matchStrategy || DEFAULT_STRATEGY;
8
+ const filterInCriteria = (item) => (item === null || item === void 0 ? void 0 : item[property]) && !filter_helper_1.checkIfMatchByStrategy(item === null || item === void 0 ? void 0 : item[property], value, strategy);
9
+ return {
10
+ any: {
11
+ enter: (node, ctx) => {
12
+ filter_helper_1.filter(node, ctx, filterInCriteria);
13
+ },
14
+ },
15
+ };
16
+ };
17
+ exports.FilterIn = FilterIn;
@@ -0,0 +1,2 @@
1
+ import { Oas2Decorator, Oas3Decorator } from '../../../visitors';
2
+ export declare const FilterOut: Oas3Decorator | Oas2Decorator;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterOut = void 0;
4
+ const filter_helper_1 = require("./filter-helper");
5
+ const DEFAULT_STRATEGY = 'any';
6
+ const FilterOut = ({ property, value, matchStrategy }) => {
7
+ const strategy = matchStrategy || DEFAULT_STRATEGY;
8
+ const filterOutCriteria = (item) => filter_helper_1.checkIfMatchByStrategy(item === null || item === void 0 ? void 0 : item[property], value, strategy);
9
+ return {
10
+ any: {
11
+ enter: (node, ctx) => {
12
+ filter_helper_1.filter(node, ctx, filterOutCriteria);
13
+ },
14
+ },
15
+ };
16
+ };
17
+ exports.FilterOut = FilterOut;
@@ -5,4 +5,6 @@ export declare const decorators: {
5
5
  'tag-description-override': Oas2Decorator;
6
6
  'info-description-override': Oas2Decorator;
7
7
  'remove-x-internal': Oas2Decorator;
8
+ 'filter-in': Oas2Decorator;
9
+ 'filter-out': Oas2Decorator;
8
10
  };
@@ -6,10 +6,14 @@ const operation_description_override_1 = require("../common/operation-descriptio
6
6
  const tag_description_override_1 = require("../common/tag-description-override");
7
7
  const info_description_override_1 = require("../common/info-description-override");
8
8
  const remove_x_internal_1 = require("../common/remove-x-internal");
9
+ const filter_in_1 = require("../common/filters/filter-in");
10
+ const filter_out_1 = require("../common/filters/filter-out");
9
11
  exports.decorators = {
10
12
  'registry-dependencies': registry_dependencies_1.RegistryDependencies,
11
13
  'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
12
14
  'tag-description-override': tag_description_override_1.TagDescriptionOverride,
13
15
  'info-description-override': info_description_override_1.InfoDescriptionOverride,
14
- 'remove-x-internal': remove_x_internal_1.RemoveXInternal
16
+ 'remove-x-internal': remove_x_internal_1.RemoveXInternal,
17
+ 'filter-in': filter_in_1.FilterIn,
18
+ 'filter-out': filter_out_1.FilterOut,
15
19
  };
@@ -5,4 +5,6 @@ export declare const decorators: {
5
5
  'tag-description-override': Oas3Decorator;
6
6
  'info-description-override': Oas3Decorator;
7
7
  'remove-x-internal': Oas3Decorator;
8
+ 'filter-in': Oas3Decorator;
9
+ 'filter-out': Oas3Decorator;
8
10
  };
@@ -6,10 +6,14 @@ const operation_description_override_1 = require("../common/operation-descriptio
6
6
  const tag_description_override_1 = require("../common/tag-description-override");
7
7
  const info_description_override_1 = require("../common/info-description-override");
8
8
  const remove_x_internal_1 = require("../common/remove-x-internal");
9
+ const filter_in_1 = require("../common/filters/filter-in");
10
+ const filter_out_1 = require("../common/filters/filter-out");
9
11
  exports.decorators = {
10
12
  'registry-dependencies': registry_dependencies_1.RegistryDependencies,
11
13
  'operation-description-override': operation_description_override_1.OperationDescriptionOverride,
12
14
  'tag-description-override': tag_description_override_1.TagDescriptionOverride,
13
15
  'info-description-override': info_description_override_1.InfoDescriptionOverride,
14
- 'remove-x-internal': remove_x_internal_1.RemoveXInternal
16
+ 'remove-x-internal': remove_x_internal_1.RemoveXInternal,
17
+ 'filter-in': filter_in_1.FilterIn,
18
+ 'filter-out': filter_out_1.FilterOut,
15
19
  };
package/lib/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export { Oas2Definition } from './typings/swagger';
8
8
  export { StatsAccumulator, StatsName } from './typings/common';
9
9
  export { normalizeTypes } from './types';
10
10
  export { Stats } from './rules/other/stats';
11
- export { Config, LintConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, } from './config';
11
+ export { Config, LintConfig, RawConfig, IGNORE_FILE, Region, getMergedConfig, transformConfig, loadConfig, getConfig, findConfig, CONFIG_FILE_NAMES, RuleSeverity } from './config';
12
12
  export { RedoclyClient, isRedoclyRegistryURL } from './redocly';
13
13
  export { Source, BaseResolver, Document, resolveDocument, ResolveError, YamlParseError, makeDocumentFromString, } from './resolve';
14
14
  export { parseYaml, stringifyYaml } from './js-yaml';
package/lib/lint.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { BaseResolver, Document } from './resolve';
2
2
  import { NodeType } from './types';
3
+ import { ProblemSeverity } from './walk';
3
4
  import { LintConfig, Config } from './config';
4
5
  export declare function lint(opts: {
5
6
  ref: string;
@@ -20,4 +21,5 @@ export declare function lintDocument(opts: {
20
21
  }): Promise<import("./walk").NormalizedProblem[]>;
21
22
  export declare function lintConfig(opts: {
22
23
  document: Document;
24
+ severity?: ProblemSeverity;
23
25
  }): Promise<import("./walk").NormalizedProblem[]>;
package/lib/lint.js CHANGED
@@ -72,7 +72,7 @@ function lintDocument(opts) {
72
72
  exports.lintDocument = lintDocument;
73
73
  function lintConfig(opts) {
74
74
  return __awaiter(this, void 0, void 0, function* () {
75
- const { document } = opts;
75
+ const { document, severity } = opts;
76
76
  const ctx = {
77
77
  problems: [],
78
78
  oasVersion: oas_types_1.OasVersion.Version3_0,
@@ -84,7 +84,7 @@ function lintConfig(opts) {
84
84
  rules: { spec: 'error' },
85
85
  });
86
86
  const types = types_1.normalizeTypes(redocly_yaml_1.ConfigTypes, config);
87
- const rules = [{ severity: 'error', ruleId: 'spec', visitor: spec_1.OasSpec({ severity: 'error' }) }];
87
+ const rules = [{ severity: severity || 'error', ruleId: 'configuration spec', visitor: spec_1.OasSpec({ severity: 'error' }) }];
88
88
  const normalizedVisitors = visitors_1.normalizeVisitors(rules, types);
89
89
  walk_1.walkDocument({
90
90
  document,
@@ -15,6 +15,8 @@ export declare namespace RegistryApiTypes {
15
15
  branch?: string;
16
16
  isUpsert?: boolean;
17
17
  isPublic?: boolean;
18
+ batchId?: string;
19
+ batchSize?: number;
18
20
  }
19
21
  export interface PrepareFileuploadOKResponse {
20
22
  filePath: string;
@@ -13,5 +13,5 @@ export declare class RegistryApi {
13
13
  organizations: string[];
14
14
  }>;
15
15
  prepareFileUpload({ organizationId, name, version, filesHash, filename, isUpsert, }: RegistryApiTypes.PrepareFileuploadParams): Promise<RegistryApiTypes.PrepareFileuploadOKResponse>;
16
- pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }: RegistryApiTypes.PushApiParams): Promise<void>;
16
+ pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize }: RegistryApiTypes.PushApiParams): Promise<void>;
17
17
  }
@@ -80,7 +80,7 @@ class RegistryApi {
80
80
  throw new Error('Could not prepare file upload');
81
81
  });
82
82
  }
83
- pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, }) {
83
+ pushApi({ organizationId, name, version, rootFilePath, filePaths, branch, isUpsert, isPublic, batchId, batchSize }) {
84
84
  return __awaiter(this, void 0, void 0, function* () {
85
85
  const response = yield this.request(`/${organizationId}/${name}/${version}`, {
86
86
  method: 'PUT',
@@ -94,6 +94,8 @@ class RegistryApi {
94
94
  branch,
95
95
  isUpsert,
96
96
  isPublic,
97
+ batchId,
98
+ batchSize
97
99
  }),
98
100
  }, this.region);
99
101
  if (response.ok) {
@@ -2,7 +2,7 @@ import { ErrorObject } from '@redocly/ajv';
2
2
  import { Location } from '../ref-utils';
3
3
  import { ResolveFn } from '../walk';
4
4
  export declare function releaseAjvInstance(): void;
5
- export declare function validateJsonSchema(data: any, schema: any, schemaLoc: Location, instancePath: string, resolve: ResolveFn<any>, disallowAdditionalProperties: boolean): {
5
+ export declare function validateJsonSchema(data: any, schema: any, schemaLoc: Location, instancePath: string, resolve: ResolveFn, disallowAdditionalProperties: boolean): {
6
6
  valid: boolean;
7
7
  errors: (ErrorObject & {
8
8
  suggest?: string[];
package/lib/rules/ajv.js CHANGED
@@ -24,7 +24,7 @@ function getAjv(resolve, disallowAdditionalProperties) {
24
24
  loadSchemaSync(base, $ref) {
25
25
  const resolvedRef = resolve({ $ref }, base.split('#')[0]);
26
26
  if (!resolvedRef || !resolvedRef.location)
27
- return undefined;
27
+ return false;
28
28
  return Object.assign({ $id: resolvedRef.location.absolutePointer }, resolvedRef.node);
29
29
  },
30
30
  logger: false,
@@ -1,4 +1,9 @@
1
- declare type Asserts = Record<string, (value: any, condition: any) => boolean>;
1
+ import { Location } from '../../../ref-utils';
2
+ declare type AssertResult = {
3
+ isValid: boolean;
4
+ location?: Location;
5
+ };
6
+ declare type Asserts = Record<string, (value: any, condition: any, baseLocation: Location, rawValue?: any) => AssertResult>;
2
7
  export declare const runOnKeysSet: Set<string>;
3
8
  export declare const runOnValuesSet: Set<string>;
4
9
  export declare const asserts: Asserts;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.asserts = exports.runOnValuesSet = exports.runOnKeysSet = void 0;
4
- const utils_1 = require("./utils");
4
+ const utils_1 = require("../../../utils");
5
+ const utils_2 = require("./utils");
5
6
  exports.runOnKeysSet = new Set([
6
7
  'mutuallyExclusive',
7
8
  'mutuallyRequired',
@@ -13,6 +14,8 @@ exports.runOnKeysSet = new Set([
13
14
  'sortOrder',
14
15
  'disallowed',
15
16
  'required',
17
+ 'requireAny',
18
+ 'ref',
16
19
  ]);
17
20
  exports.runOnValuesSet = new Set([
18
21
  'pattern',
@@ -24,78 +27,83 @@ exports.runOnValuesSet = new Set([
24
27
  'maxLength',
25
28
  'casing',
26
29
  'sortOrder',
30
+ 'ref',
27
31
  ]);
28
32
  exports.asserts = {
29
- pattern: (value, condition) => {
33
+ pattern: (value, condition, baseLocation) => {
30
34
  if (typeof value === 'undefined')
31
- return true; // property doesn't exist, no need to lint it with this assert
32
- const values = typeof value === 'string' ? [value] : value;
33
- const regexOptions = condition.match(/(\b\/\b)(.+)/g) || ['/'];
34
- condition = condition.slice(1).replace(regexOptions[0], '');
35
- const regx = new RegExp(condition, regexOptions[0].slice(1));
35
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
36
+ const values = utils_1.isString(value) ? [value] : value;
37
+ const regx = utils_2.regexFromString(condition);
36
38
  for (let _val of values) {
37
- if (!_val.match(regx)) {
38
- return false;
39
+ if (!(regx === null || regx === void 0 ? void 0 : regx.test(_val))) {
40
+ return { isValid: false, location: utils_1.isString(value) ? baseLocation : baseLocation.key() };
39
41
  }
40
42
  }
41
- return true;
43
+ return { isValid: true };
42
44
  },
43
- enum: (value, condition) => {
45
+ enum: (value, condition, baseLocation) => {
44
46
  if (typeof value === 'undefined')
45
- return true; // property doesn't exist, no need to lint it with this assert
46
- const values = typeof value === 'string' ? [value] : value;
47
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
48
+ const values = utils_1.isString(value) ? [value] : value;
47
49
  for (let _val of values) {
48
50
  if (!condition.includes(_val)) {
49
- return false;
51
+ return {
52
+ isValid: false,
53
+ location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
54
+ };
50
55
  }
51
56
  }
52
- return true;
57
+ return { isValid: true };
53
58
  },
54
- defined: (value, condition = true) => {
59
+ defined: (value, condition = true, baseLocation) => {
55
60
  const isDefined = typeof value !== 'undefined';
56
- return condition ? isDefined : !isDefined;
61
+ return { isValid: condition ? isDefined : !isDefined, location: baseLocation };
57
62
  },
58
- required: (value, keys) => {
63
+ required: (value, keys, baseLocation) => {
59
64
  for (const requiredKey of keys) {
60
65
  if (!value.includes(requiredKey)) {
61
- return false;
66
+ return { isValid: false, location: baseLocation.key() };
62
67
  }
63
68
  }
64
- return true;
69
+ return { isValid: true };
65
70
  },
66
- disallowed: (value, condition) => {
71
+ disallowed: (value, condition, baseLocation) => {
67
72
  if (typeof value === 'undefined')
68
- return true; // property doesn't exist, no need to lint it with this assert
69
- const values = typeof value === 'string' ? [value] : value;
73
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
74
+ const values = utils_1.isString(value) ? [value] : value;
70
75
  for (let _val of values) {
71
76
  if (condition.includes(_val)) {
72
- return false;
77
+ return {
78
+ isValid: false,
79
+ location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
80
+ };
73
81
  }
74
82
  }
75
- return true;
83
+ return { isValid: true };
76
84
  },
77
- undefined: (value, condition = true) => {
85
+ undefined: (value, condition = true, baseLocation) => {
78
86
  const isUndefined = typeof value === 'undefined';
79
- return condition ? isUndefined : !isUndefined;
87
+ return { isValid: condition ? isUndefined : !isUndefined, location: baseLocation };
80
88
  },
81
- nonEmpty: (value, condition = true) => {
89
+ nonEmpty: (value, condition = true, baseLocation) => {
82
90
  const isEmpty = typeof value === 'undefined' || value === null || value === '';
83
- return condition ? !isEmpty : isEmpty;
91
+ return { isValid: condition ? !isEmpty : isEmpty, location: baseLocation };
84
92
  },
85
- minLength: (value, condition) => {
93
+ minLength: (value, condition, baseLocation) => {
86
94
  if (typeof value === 'undefined')
87
- return true; // property doesn't exist, no need to lint it with this assert
88
- return value.length >= condition;
95
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
96
+ return { isValid: value.length >= condition, location: baseLocation };
89
97
  },
90
- maxLength: (value, condition) => {
98
+ maxLength: (value, condition, baseLocation) => {
91
99
  if (typeof value === 'undefined')
92
- return true; // property doesn't exist, no need to lint it with this assert
93
- return value.length <= condition;
100
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
101
+ return { isValid: value.length <= condition, location: baseLocation };
94
102
  },
95
- casing: (value, condition) => {
103
+ casing: (value, condition, baseLocation) => {
96
104
  if (typeof value === 'undefined')
97
- return true; // property doesn't exist, no need to lint it with this assert
98
- const values = typeof value === 'string' ? [value] : value;
105
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
106
+ const values = utils_1.isString(value) ? [value] : value;
99
107
  for (let _val of values) {
100
108
  let matchCase = false;
101
109
  switch (condition) {
@@ -122,25 +130,47 @@ exports.asserts = {
122
130
  break;
123
131
  }
124
132
  if (!matchCase) {
125
- return false;
133
+ return {
134
+ isValid: false,
135
+ location: utils_1.isString(value) ? baseLocation : baseLocation.child(_val).key(),
136
+ };
126
137
  }
127
138
  }
128
- return true;
139
+ return { isValid: true };
129
140
  },
130
- sortOrder: (value, condition) => {
141
+ sortOrder: (value, condition, baseLocation) => {
131
142
  if (typeof value === 'undefined')
132
- return true;
133
- return utils_1.isOrdered(value, condition);
143
+ return { isValid: true };
144
+ return { isValid: utils_2.isOrdered(value, condition), location: baseLocation };
134
145
  },
135
- mutuallyExclusive: (value, condition) => {
136
- return utils_1.getIntersectionLength(value, condition) < 2;
146
+ mutuallyExclusive: (value, condition, baseLocation) => {
147
+ return { isValid: utils_2.getIntersectionLength(value, condition) < 2, location: baseLocation.key() };
137
148
  },
138
- mutuallyRequired: (value, condition) => {
139
- return utils_1.getIntersectionLength(value, condition) > 0
140
- ? utils_1.getIntersectionLength(value, condition) === condition.length
141
- : true;
149
+ mutuallyRequired: (value, condition, baseLocation) => {
150
+ return {
151
+ isValid: utils_2.getIntersectionLength(value, condition) > 0
152
+ ? utils_2.getIntersectionLength(value, condition) === condition.length
153
+ : true,
154
+ location: baseLocation.key(),
155
+ };
142
156
  },
143
- requireAny: (value, condition) => {
144
- return utils_1.getIntersectionLength(value, condition) >= 1;
157
+ requireAny: (value, condition, baseLocation) => {
158
+ return { isValid: utils_2.getIntersectionLength(value, condition) >= 1, location: baseLocation.key() };
159
+ },
160
+ ref: (_value, condition, baseLocation, rawValue) => {
161
+ if (typeof rawValue === 'undefined')
162
+ return { isValid: true }; // property doesn't exist, no need to lint it with this assert
163
+ const hasRef = rawValue.hasOwnProperty('$ref');
164
+ if (typeof condition === 'boolean') {
165
+ return {
166
+ isValid: condition ? hasRef : !hasRef,
167
+ location: hasRef ? baseLocation : baseLocation.key(),
168
+ };
169
+ }
170
+ const regex = utils_2.regexFromString(condition);
171
+ return {
172
+ isValid: hasRef && (regex === null || regex === void 0 ? void 0 : regex.test(rawValue['$ref'])),
173
+ location: hasRef ? baseLocation : baseLocation.key(),
174
+ };
145
175
  },
146
176
  };
@@ -15,6 +15,7 @@ export declare type AssertToApply = {
15
15
  runsOnValues: boolean;
16
16
  };
17
17
  export declare function buildVisitorObject(subject: string, context: Record<string, any>[], subjectVisitor: any): Record<string, any>;
18
- export declare function buildSubjectVisitor(properties: string | string[], asserts: AssertToApply[], context?: Record<string, any>[]): (node: any, { report, location, key, type, resolve }: UserContext) => void;
18
+ export declare function buildSubjectVisitor(properties: string | string[], asserts: AssertToApply[], context?: Record<string, any>[]): (node: any, { report, location, rawLocation, key, type, resolve, rawNode }: UserContext) => void;
19
19
  export declare function getIntersectionLength(keys: string[], properties: string[]): number;
20
20
  export declare function isOrdered(value: any[], options: OrderOptions | OrderDirection): boolean;
21
+ export declare function regexFromString(input: string): RegExp | null;