@amritk/lint 0.3.2 → 0.4.0

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 (119) hide show
  1. package/AI.md +55 -0
  2. package/dist/core/document.js +12 -10
  3. package/dist/core/formats.js +10 -13
  4. package/dist/core/glob.js +96 -118
  5. package/dist/core/index.d.ts +0 -1
  6. package/dist/core/index.js +30 -11
  7. package/dist/core/jsonpath.js +487 -561
  8. package/dist/core/lint.js +78 -85
  9. package/dist/core/plugin.js +21 -29
  10. package/dist/core/pointers.js +107 -151
  11. package/dist/core/ruleset.js +0 -0
  12. package/dist/core/runner.js +214 -272
  13. package/dist/core/types.js +4 -1
  14. package/dist/core/validate-ruleset.js +98 -112
  15. package/dist/fix/apply.d.ts +1 -1
  16. package/dist/fix/apply.js +58 -96
  17. package/dist/fix/index.js +7 -2
  18. package/dist/fix/plugin.js +15 -20
  19. package/dist/fix/types.d.ts +1 -1
  20. package/dist/functions/alphabetical.d.ts +1 -1
  21. package/dist/functions/alphabetical.js +39 -50
  22. package/dist/functions/casing.d.ts +1 -1
  23. package/dist/functions/casing.js +39 -45
  24. package/dist/functions/defined.d.ts +1 -1
  25. package/dist/functions/defined.js +7 -5
  26. package/dist/functions/enumeration.d.ts +1 -1
  27. package/dist/functions/enumeration.js +15 -25
  28. package/dist/functions/falsy.d.ts +1 -1
  29. package/dist/functions/falsy.js +7 -5
  30. package/dist/functions/index.d.ts +1 -1
  31. package/dist/functions/index.js +60 -44
  32. package/dist/functions/length.d.ts +1 -1
  33. package/dist/functions/length.js +22 -32
  34. package/dist/functions/or.d.ts +1 -1
  35. package/dist/functions/or.js +18 -24
  36. package/dist/functions/pattern.d.ts +1 -1
  37. package/dist/functions/pattern.js +39 -49
  38. package/dist/functions/schema.d.ts +1 -1
  39. package/dist/functions/schema.js +93 -119
  40. package/dist/functions/truthy.d.ts +1 -1
  41. package/dist/functions/truthy.js +7 -5
  42. package/dist/functions/typed-enum.d.ts +1 -1
  43. package/dist/functions/typed-enum.js +33 -36
  44. package/dist/functions/undefined.d.ts +1 -1
  45. package/dist/functions/undefined.js +7 -8
  46. package/dist/functions/unreferenced-reusable-object.d.ts +1 -1
  47. package/dist/functions/unreferenced-reusable-object.js +35 -47
  48. package/dist/functions/xor.d.ts +1 -1
  49. package/dist/functions/xor.js +13 -16
  50. package/dist/index.d.ts +17 -4
  51. package/dist/index.js +149 -164
  52. package/dist/parsers/edit-model.js +316 -444
  53. package/dist/parsers/index.d.ts +1 -1
  54. package/dist/parsers/index.js +23 -19
  55. package/dist/parsers/json.js +39 -37
  56. package/dist/parsers/lines.js +23 -26
  57. package/dist/parsers/types.js +9 -7
  58. package/dist/parsers/yaml.js +137 -204
  59. package/dist/rules/openapi/fixers.js +166 -221
  60. package/dist/rules/openapi/formats.js +26 -27
  61. package/dist/rules/openapi/functions/example-validation.d.ts +1 -1
  62. package/dist/rules/openapi/functions/example-validation.js +98 -138
  63. package/dist/rules/openapi/functions/helpers.js +8 -10
  64. package/dist/rules/openapi/functions/index.d.ts +1 -1
  65. package/dist/rules/openapi/functions/index.js +98 -72
  66. package/dist/rules/openapi/functions/oas-additional-operations.d.ts +1 -1
  67. package/dist/rules/openapi/functions/oas-additional-operations.js +16 -22
  68. package/dist/rules/openapi/functions/oas-discriminator.d.ts +1 -1
  69. package/dist/rules/openapi/functions/oas-discriminator.js +24 -22
  70. package/dist/rules/openapi/functions/oas-example-external-value.d.ts +1 -1
  71. package/dist/rules/openapi/functions/oas-example-external-value.js +13 -21
  72. package/dist/rules/openapi/functions/oas-example-value.d.ts +1 -1
  73. package/dist/rules/openapi/functions/oas-example-value.js +24 -27
  74. package/dist/rules/openapi/functions/oas-mutually-exclusive.d.ts +1 -1
  75. package/dist/rules/openapi/functions/oas-mutually-exclusive.js +15 -19
  76. package/dist/rules/openapi/functions/oas-no-nullable.d.ts +1 -1
  77. package/dist/rules/openapi/functions/oas-no-nullable.js +13 -21
  78. package/dist/rules/openapi/functions/oas-op-form-data-consume-check.d.ts +1 -1
  79. package/dist/rules/openapi/functions/oas-op-form-data-consume-check.js +21 -19
  80. package/dist/rules/openapi/functions/oas-op-id-unique.d.ts +1 -1
  81. package/dist/rules/openapi/functions/oas-op-id-unique.js +27 -27
  82. package/dist/rules/openapi/functions/oas-op-params.d.ts +1 -1
  83. package/dist/rules/openapi/functions/oas-op-params.js +36 -42
  84. package/dist/rules/openapi/functions/oas-op-security-defined.d.ts +1 -1
  85. package/dist/rules/openapi/functions/oas-op-security-defined.js +40 -39
  86. package/dist/rules/openapi/functions/oas-op-success-response.d.ts +1 -1
  87. package/dist/rules/openapi/functions/oas-op-success-response.js +11 -13
  88. package/dist/rules/openapi/functions/oas-path-param.d.ts +1 -1
  89. package/dist/rules/openapi/functions/oas-path-param.js +75 -96
  90. package/dist/rules/openapi/functions/oas-schema-example-deprecated.d.ts +1 -1
  91. package/dist/rules/openapi/functions/oas-schema-example-deprecated.js +33 -40
  92. package/dist/rules/openapi/functions/oas-schema.d.ts +1 -1
  93. package/dist/rules/openapi/functions/oas-schema.js +9 -14
  94. package/dist/rules/openapi/functions/oas-server-name-unique.d.ts +1 -1
  95. package/dist/rules/openapi/functions/oas-server-name-unique.js +21 -19
  96. package/dist/rules/openapi/functions/oas-server-variables.d.ts +1 -1
  97. package/dist/rules/openapi/functions/oas-server-variables.js +45 -49
  98. package/dist/rules/openapi/functions/oas-tag-defined.d.ts +1 -1
  99. package/dist/rules/openapi/functions/oas-tag-defined.js +20 -20
  100. package/dist/rules/openapi/functions/oas-tag-kind.d.ts +1 -1
  101. package/dist/rules/openapi/functions/oas-tag-kind.js +16 -16
  102. package/dist/rules/openapi/functions/oas-tag-parent-defined.d.ts +1 -1
  103. package/dist/rules/openapi/functions/oas-tag-parent-defined.js +40 -43
  104. package/dist/rules/openapi/functions/oas-tags-unique.d.ts +1 -1
  105. package/dist/rules/openapi/functions/oas-tags-unique.js +18 -16
  106. package/dist/rules/openapi/functions/oas-unused-component.d.ts +1 -1
  107. package/dist/rules/openapi/functions/oas-unused-component.js +48 -58
  108. package/dist/rules/openapi/functions/ref-siblings.d.ts +1 -1
  109. package/dist/rules/openapi/functions/ref-siblings.js +13 -11
  110. package/dist/rules/openapi/index.d.ts +2 -1
  111. package/dist/rules/openapi/index.js +99 -117
  112. package/dist/rules/openapi/oas.d.ts +1 -1
  113. package/dist/rules/openapi/oas.js +524 -536
  114. package/dist/rules/openapi/schemas/index.js +17 -33
  115. package/dist/rules/openapi/schemas/oas20.json +1 -1592
  116. package/dist/rules/openapi/schemas/oas30.json +1 -1651
  117. package/dist/rules/openapi/schemas/oas31.json +1 -1412
  118. package/dist/rules/openapi/schemas/oas32.json +1 -1684
  119. package/package.json +11 -6
@@ -1,160 +1,120 @@
1
- import { validate } from '@amritk/runtime-validators';
2
- import { isObject } from './helpers.js';
3
- // The example schemas come from the *linted document*, so they are only known at
4
- // runtime. `@amritk/runtime-validators` interprets a schema directly — no
5
- // `ajv.compile` (whose codegen dominated lint time on large specs, recompiling
6
- // `$ref`-duplicated schemas tens of thousands of times) and no `new Function`,
7
- // so it is also CSP/edge-runtime safe. Returns undefined for a non-object or a
8
- // schema the validator can't build (mirrors the old skip-on-compile-failure
9
- // behavior).
10
- //
11
- // Formats are asserted (`formats: 'all'`) to match Spectral, whose example rules
12
- // run ajv with `ajv-formats` enabled — otherwise a format-violating example (a
13
- // bad `email`/`date`/`uuid`) would slip through. This mirrors the core `schema`
14
- // built-in's option exactly; `@amritk/runtime-validators` treats the OAS-specific
15
- // numeric/binary formats (`int32`/`int64`/`float`/`byte`/`binary`) as non-failing.
1
+ import { validate } from "@amritk/runtime-validators";
2
+ import { isObject } from "./helpers.js";
16
3
  const buildValidator = (schema) => {
17
- if (!isObject(schema))
18
- return undefined;
19
- let validator;
4
+ if (!isObject(schema))
5
+ return void 0;
6
+ let validator;
7
+ try {
8
+ validator = validate(schema, { formats: "all" });
9
+ } catch {
10
+ return void 0;
11
+ }
12
+ return (input) => {
20
13
  try {
21
- validator = validate(schema, { formats: 'all' });
14
+ return validator(input);
15
+ } catch {
16
+ return true;
22
17
  }
23
- catch {
24
- return undefined;
25
- }
26
- // A schema can carry a `$ref` the runtime validator cannot resolve (an external
27
- // or cyclic ref left behind after `$ref` inlining), which throws at *run* time
28
- // rather than build time. Treat that as "cannot validate — skip" (returning a
29
- // valid result) so an unresolvable example schema never crashes the whole lint.
30
- return (input) => {
31
- try {
32
- return validator(input);
33
- }
34
- catch {
35
- return true;
36
- }
37
- };
18
+ };
38
19
  };
39
20
  const buildValidatorOrNull = (schema) => buildValidator(schema) ?? null;
40
- // Keyed by the Schema Object node; `oasSchemaExample` validates a schema's own
41
- // `example`/`default` against the schema minus its `example`/`examples` keywords.
42
- const schemaExampleResults = new WeakMap();
43
- // Keyed by the Media Type / Response Object node; `oasMediaExample` validates the
44
- // object's example(s) against its `schema`. The node (not the schema) is the cache
45
- // key because two media objects can share a `schema` but carry different examples.
46
- const mediaExampleResults = new WeakMap();
21
+ const schemaExampleResults = /* @__PURE__ */ new WeakMap();
22
+ const mediaExampleResults = /* @__PURE__ */ new WeakMap();
47
23
  const withPath = (findings, path) => {
48
- if (findings.length === 0)
49
- return [];
50
- return findings.map((finding) => ({ message: finding.message, path: [...path, ...finding.suffix] }));
24
+ if (findings.length === 0)
25
+ return [];
26
+ return findings.map((finding) => ({ message: finding.message, path: [...path, ...finding.suffix] }));
51
27
  };
52
- // A schema node reached via `$..[?(...)]` might be a `properties`/`patternProperties`
53
- // *map* whose keys happen to look like schema keywords (e.g. a property literally
54
- // named `type`). Those maps are not Schema Objects, so we never validate them.
55
28
  const isPropertiesMap = (path) => {
56
- const tail = path[path.length - 1];
57
- return tail === 'properties' || tail === 'patternProperties';
29
+ const tail = path[path.length - 1];
30
+ return tail === "properties" || tail === "patternProperties";
58
31
  };
59
- /** Validates a schema object's inline `example` and `default` against the schema itself. */
60
- export const oasSchemaExample = (schema, _options, context) => {
61
- if (!isObject(schema))
62
- return [];
63
- if (schema['example'] === undefined && schema['default'] === undefined)
64
- return [];
65
- if (isPropertiesMap(context.path))
66
- return [];
67
- let findings = schemaExampleResults.get(schema);
68
- if (findings === undefined) {
69
- findings = [];
70
- // `example`/`examples` are annotations, not constraints, so drop them before
71
- // building the validator; `default` stays (it is not a validation keyword).
72
- const { example, examples, ...rest } = schema;
73
- void example;
74
- void examples;
75
- const check = buildValidatorOrNull(rest);
76
- if (check) {
77
- for (const field of ['example', 'default']) {
78
- if (schema[field] === undefined)
79
- continue;
80
- const result = check(schema[field]);
81
- if (result !== true) {
82
- for (const error of result.errors)
83
- findings.push({ message: `"${field}" ${error.message}`.trim(), suffix: [field] });
84
- }
85
- }
32
+ const oasSchemaExample = (schema, _options, context) => {
33
+ if (!isObject(schema))
34
+ return [];
35
+ if (schema["example"] === void 0 && schema["default"] === void 0)
36
+ return [];
37
+ if (isPropertiesMap(context.path))
38
+ return [];
39
+ let findings = schemaExampleResults.get(schema);
40
+ if (findings === void 0) {
41
+ findings = [];
42
+ const { example, examples, ...rest } = schema;
43
+ void example;
44
+ void examples;
45
+ const check = buildValidatorOrNull(rest);
46
+ if (check) {
47
+ for (const field of ["example", "default"]) {
48
+ if (schema[field] === void 0)
49
+ continue;
50
+ const result = check(schema[field]);
51
+ if (result !== true) {
52
+ for (const error of result.errors)
53
+ findings.push({ message: `"${field}" ${error.message}`.trim(), suffix: [field] });
86
54
  }
87
- schemaExampleResults.set(schema, findings);
55
+ }
88
56
  }
89
- return withPath(findings, context.path);
57
+ schemaExampleResults.set(schema, findings);
58
+ }
59
+ return withPath(findings, context.path);
90
60
  };
91
- /**
92
- * Validates a Media Type / Response / Parameter object's examples against its
93
- * `schema`. Version-split because OpenAPI 2.0 and 3.x model examples differently:
94
- * - OAS3: a singular `example` value plus an `examples` map of Example Objects,
95
- * each of which carries the value under `value`.
96
- * - OAS2: `examples` is a MIME-type → value map (`{ 'application/json': value }`),
97
- * with no Example Objects and no singular `example` on the media object — so the
98
- * 3.x logic validated nothing at all for a real 2.0 document.
99
- */
100
- export const oasMediaExample = (media, options, context) => {
101
- if (!isObject(media) || !isObject(media['schema']))
102
- return [];
103
- const oasVersion = options?.oasVersion ?? 3;
104
- // Skip building a validator when there is nothing to check — most media objects
105
- // in a large spec have a schema but no example. (OAS2 only has the map form.)
106
- const hasExample = (oasVersion !== 2 && media['example'] !== undefined) || isObject(media['examples']);
107
- if (!hasExample)
108
- return [];
109
- let findings = mediaExampleResults.get(media);
110
- if (findings === undefined) {
111
- findings = [];
112
- const check = buildValidatorOrNull(media['schema']);
113
- if (check) {
114
- if (oasVersion === 2)
115
- collectOas2(media, check, findings);
116
- else
117
- collectOas3(media, check, findings);
118
- }
119
- mediaExampleResults.set(media, findings);
61
+ const oasMediaExample = (media, options, context) => {
62
+ if (!isObject(media) || !isObject(media["schema"]))
63
+ return [];
64
+ const oasVersion = options?.oasVersion ?? 3;
65
+ const hasExample = oasVersion !== 2 && media["example"] !== void 0 || isObject(media["examples"]);
66
+ if (!hasExample)
67
+ return [];
68
+ let findings = mediaExampleResults.get(media);
69
+ if (findings === void 0) {
70
+ findings = [];
71
+ const check = buildValidatorOrNull(media["schema"]);
72
+ if (check) {
73
+ if (oasVersion === 2)
74
+ collectOas2(media, check, findings);
75
+ else
76
+ collectOas3(media, check, findings);
120
77
  }
121
- return withPath(findings, context.path);
78
+ mediaExampleResults.set(media, findings);
79
+ }
80
+ return withPath(findings, context.path);
122
81
  };
123
- /** OAS2: validate each `examples[mimeType]` value against the sibling `schema`. */
124
82
  const collectOas2 = (media, check, findings) => {
125
- const examples = isObject(media['examples']) ? media['examples'] : undefined;
126
- if (!examples)
127
- return;
128
- for (const [mimeType, value] of Object.entries(examples)) {
129
- const result = check(value);
130
- if (result !== true) {
131
- for (const error of result.errors) {
132
- findings.push({ message: `Example "${mimeType}" ${error.message}`.trim(), suffix: ['examples', mimeType] });
133
- }
134
- }
83
+ const examples = isObject(media["examples"]) ? media["examples"] : void 0;
84
+ if (!examples)
85
+ return;
86
+ for (const [mimeType, value] of Object.entries(examples)) {
87
+ const result = check(value);
88
+ if (result !== true) {
89
+ for (const error of result.errors) {
90
+ findings.push({ message: `Example "${mimeType}" ${error.message}`.trim(), suffix: ["examples", mimeType] });
91
+ }
135
92
  }
93
+ }
136
94
  };
137
- /** OAS3: validate the singular `example` and each `examples[name].value` against the `schema`. */
138
95
  const collectOas3 = (media, check, findings) => {
139
- if (media['example'] !== undefined) {
140
- const result = check(media['example']);
141
- if (result !== true) {
142
- for (const error of result.errors)
143
- findings.push({ message: `"example" ${error.message}`.trim(), suffix: ['example'] });
144
- }
96
+ if (media["example"] !== void 0) {
97
+ const result = check(media["example"]);
98
+ if (result !== true) {
99
+ for (const error of result.errors)
100
+ findings.push({ message: `"example" ${error.message}`.trim(), suffix: ["example"] });
145
101
  }
146
- const examples = isObject(media['examples']) ? media['examples'] : undefined;
147
- if (!examples)
148
- return;
149
- for (const [name, example] of Object.entries(examples)) {
150
- // An external-value example is fetched elsewhere, so there is nothing inline to check.
151
- if (isObject(example) && example['value'] !== undefined) {
152
- const result = check(example['value']);
153
- if (result !== true) {
154
- for (const error of result.errors) {
155
- findings.push({ message: `Example "${name}" ${error.message}`.trim(), suffix: ['examples', name, 'value'] });
156
- }
157
- }
102
+ }
103
+ const examples = isObject(media["examples"]) ? media["examples"] : void 0;
104
+ if (!examples)
105
+ return;
106
+ for (const [name, example] of Object.entries(examples)) {
107
+ if (isObject(example) && example["value"] !== void 0) {
108
+ const result = check(example["value"]);
109
+ if (result !== true) {
110
+ for (const error of result.errors) {
111
+ findings.push({ message: `Example "${name}" ${error.message}`.trim(), suffix: ["examples", name, "value"] });
158
112
  }
113
+ }
159
114
  }
115
+ }
116
+ };
117
+ export {
118
+ oasMediaExample,
119
+ oasSchemaExample
160
120
  };
@@ -1,10 +1,8 @@
1
- /** True for a non-null, non-array object (an OpenAPI "object" value). */
2
- export const isObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
3
- // The eight standard HTTP methods that have a dedicated fixed field on the Path
4
- // Item Object. Shared by the rules that iterate a path item's operations.
5
- export const HTTP_METHODS = new Set(['get', 'put', 'post', 'delete', 'options', 'head', 'patch', 'trace']);
6
- // OpenAPI 3.2 promoted `query` to a fixed Path Item Object operation field, so the
7
- // rules that walk a path item's operations must consider it too. Including it is
8
- // harmless on older versions, which never carry a `query` operation, so the same
9
- // set works across every OpenAPI version.
10
- export const OPERATION_METHODS = new Set([...HTTP_METHODS, 'query']);
1
+ const isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
2
+ const HTTP_METHODS = /* @__PURE__ */ new Set(["get", "put", "post", "delete", "options", "head", "patch", "trace"]);
3
+ const OPERATION_METHODS = /* @__PURE__ */ new Set([...HTTP_METHODS, "query"]);
4
+ export {
5
+ HTTP_METHODS,
6
+ OPERATION_METHODS,
7
+ isObject
8
+ };
@@ -1,4 +1,4 @@
1
- import type { FunctionRegistry } from '../../../core/index.js';
1
+ import type { FunctionRegistry } from '../../../core/types.js';
2
2
  export { type IOasExampleOptions, oasMediaExample, oasSchemaExample } from './example-validation.js';
3
3
  export { oasAdditionalOperations } from './oas-additional-operations.js';
4
4
  export { oasDiscriminator } from './oas-discriminator.js';
@@ -1,73 +1,99 @@
1
- import { oasMediaExample, oasSchemaExample } from './example-validation.js';
2
- import { oasAdditionalOperations } from './oas-additional-operations.js';
3
- import { oasDiscriminator } from './oas-discriminator.js';
4
- import { oasExampleExternalValue } from './oas-example-external-value.js';
5
- import { oasExampleValue } from './oas-example-value.js';
6
- import { oasMutuallyExclusive } from './oas-mutually-exclusive.js';
7
- import { oasNoNullable } from './oas-no-nullable.js';
8
- import { oasOpFormDataConsumeCheck } from './oas-op-form-data-consume-check.js';
9
- import { oasOpIdUnique } from './oas-op-id-unique.js';
10
- import { oasOpParams } from './oas-op-params.js';
11
- import { oasOpSecurityDefined } from './oas-op-security-defined.js';
12
- import { oasOpSuccessResponse } from './oas-op-success-response.js';
13
- import { oasPathParam } from './oas-path-param.js';
14
- import { oasSchema } from './oas-schema.js';
15
- import { oasSchemaExampleDeprecated } from './oas-schema-example-deprecated.js';
16
- import { oasServerNameUnique } from './oas-server-name-unique.js';
17
- import { oasServerVariables } from './oas-server-variables.js';
18
- import { oasTagDefined } from './oas-tag-defined.js';
19
- import { oasTagKind } from './oas-tag-kind.js';
20
- import { oasTagParentDefined } from './oas-tag-parent-defined.js';
21
- import { oasTagsUnique } from './oas-tags-unique.js';
22
- import { oasUnusedComponent } from './oas-unused-component.js';
23
- import { refSiblings } from './ref-siblings.js';
24
- export { oasMediaExample, oasSchemaExample } from './example-validation.js';
25
- export { oasAdditionalOperations } from './oas-additional-operations.js';
26
- export { oasDiscriminator } from './oas-discriminator.js';
27
- export { oasExampleExternalValue } from './oas-example-external-value.js';
28
- export { oasExampleValue } from './oas-example-value.js';
29
- export { oasMutuallyExclusive } from './oas-mutually-exclusive.js';
30
- export { oasNoNullable } from './oas-no-nullable.js';
31
- export { oasOpFormDataConsumeCheck } from './oas-op-form-data-consume-check.js';
32
- export { oasOpIdUnique } from './oas-op-id-unique.js';
33
- export { oasOpParams } from './oas-op-params.js';
34
- export { oasOpSecurityDefined } from './oas-op-security-defined.js';
35
- export { oasOpSuccessResponse } from './oas-op-success-response.js';
36
- export { oasPathParam } from './oas-path-param.js';
37
- export { oasSchema } from './oas-schema.js';
38
- export { oasSchemaExampleDeprecated } from './oas-schema-example-deprecated.js';
39
- export { oasServerNameUnique } from './oas-server-name-unique.js';
40
- export { oasServerVariables } from './oas-server-variables.js';
41
- export { oasTagDefined } from './oas-tag-defined.js';
42
- export { oasTagKind } from './oas-tag-kind.js';
43
- export { oasTagParentDefined } from './oas-tag-parent-defined.js';
44
- export { oasTagsUnique } from './oas-tags-unique.js';
45
- export { oasUnusedComponent } from './oas-unused-component.js';
46
- export { refSiblings } from './ref-siblings.js';
47
- /** The OpenAPI-specific custom functions, keyed by name for ruleset `then` references. */
48
- export const oasFunctions = {
49
- refSiblings,
50
- oasOpSuccessResponse,
51
- oasTagDefined,
52
- oasOpIdUnique,
53
- oasPathParam,
54
- oasOpParams,
55
- oasTagsUnique,
56
- oasOpSecurityDefined: oasOpSecurityDefined,
57
- oasOpFormDataConsumeCheck,
58
- oasDiscriminator,
59
- oasServerVariables,
60
- oasSchemaExample,
61
- oasMediaExample: oasMediaExample,
62
- oasUnusedComponent,
63
- oasMutuallyExclusive: oasMutuallyExclusive,
64
- oasNoNullable,
65
- oasSchema: oasSchema,
66
- oasAdditionalOperations,
67
- oasServerNameUnique,
68
- oasTagParentDefined,
69
- oasSchemaExampleDeprecated,
70
- oasTagKind,
71
- oasExampleValue,
72
- oasExampleExternalValue,
1
+ import { oasMediaExample, oasSchemaExample } from "./example-validation.js";
2
+ import { oasAdditionalOperations } from "./oas-additional-operations.js";
3
+ import { oasDiscriminator } from "./oas-discriminator.js";
4
+ import { oasExampleExternalValue } from "./oas-example-external-value.js";
5
+ import { oasExampleValue } from "./oas-example-value.js";
6
+ import { oasMutuallyExclusive } from "./oas-mutually-exclusive.js";
7
+ import { oasNoNullable } from "./oas-no-nullable.js";
8
+ import { oasOpFormDataConsumeCheck } from "./oas-op-form-data-consume-check.js";
9
+ import { oasOpIdUnique } from "./oas-op-id-unique.js";
10
+ import { oasOpParams } from "./oas-op-params.js";
11
+ import { oasOpSecurityDefined } from "./oas-op-security-defined.js";
12
+ import { oasOpSuccessResponse } from "./oas-op-success-response.js";
13
+ import { oasPathParam } from "./oas-path-param.js";
14
+ import { oasSchema } from "./oas-schema.js";
15
+ import { oasSchemaExampleDeprecated } from "./oas-schema-example-deprecated.js";
16
+ import { oasServerNameUnique } from "./oas-server-name-unique.js";
17
+ import { oasServerVariables } from "./oas-server-variables.js";
18
+ import { oasTagDefined } from "./oas-tag-defined.js";
19
+ import { oasTagKind } from "./oas-tag-kind.js";
20
+ import { oasTagParentDefined } from "./oas-tag-parent-defined.js";
21
+ import { oasTagsUnique } from "./oas-tags-unique.js";
22
+ import { oasUnusedComponent } from "./oas-unused-component.js";
23
+ import { refSiblings } from "./ref-siblings.js";
24
+ import { oasMediaExample as oasMediaExample2, oasSchemaExample as oasSchemaExample2 } from "./example-validation.js";
25
+ import { oasAdditionalOperations as oasAdditionalOperations2 } from "./oas-additional-operations.js";
26
+ import { oasDiscriminator as oasDiscriminator2 } from "./oas-discriminator.js";
27
+ import { oasExampleExternalValue as oasExampleExternalValue2 } from "./oas-example-external-value.js";
28
+ import { oasExampleValue as oasExampleValue2 } from "./oas-example-value.js";
29
+ import { oasMutuallyExclusive as oasMutuallyExclusive2 } from "./oas-mutually-exclusive.js";
30
+ import { oasNoNullable as oasNoNullable2 } from "./oas-no-nullable.js";
31
+ import { oasOpFormDataConsumeCheck as oasOpFormDataConsumeCheck2 } from "./oas-op-form-data-consume-check.js";
32
+ import { oasOpIdUnique as oasOpIdUnique2 } from "./oas-op-id-unique.js";
33
+ import { oasOpParams as oasOpParams2 } from "./oas-op-params.js";
34
+ import { oasOpSecurityDefined as oasOpSecurityDefined2 } from "./oas-op-security-defined.js";
35
+ import { oasOpSuccessResponse as oasOpSuccessResponse2 } from "./oas-op-success-response.js";
36
+ import { oasPathParam as oasPathParam2 } from "./oas-path-param.js";
37
+ import { oasSchema as oasSchema2 } from "./oas-schema.js";
38
+ import { oasSchemaExampleDeprecated as oasSchemaExampleDeprecated2 } from "./oas-schema-example-deprecated.js";
39
+ import { oasServerNameUnique as oasServerNameUnique2 } from "./oas-server-name-unique.js";
40
+ import { oasServerVariables as oasServerVariables2 } from "./oas-server-variables.js";
41
+ import { oasTagDefined as oasTagDefined2 } from "./oas-tag-defined.js";
42
+ import { oasTagKind as oasTagKind2 } from "./oas-tag-kind.js";
43
+ import { oasTagParentDefined as oasTagParentDefined2 } from "./oas-tag-parent-defined.js";
44
+ import { oasTagsUnique as oasTagsUnique2 } from "./oas-tags-unique.js";
45
+ import { oasUnusedComponent as oasUnusedComponent2 } from "./oas-unused-component.js";
46
+ import { refSiblings as refSiblings2 } from "./ref-siblings.js";
47
+ const oasFunctions = {
48
+ refSiblings,
49
+ oasOpSuccessResponse,
50
+ oasTagDefined,
51
+ oasOpIdUnique,
52
+ oasPathParam,
53
+ oasOpParams,
54
+ oasTagsUnique,
55
+ oasOpSecurityDefined,
56
+ oasOpFormDataConsumeCheck,
57
+ oasDiscriminator,
58
+ oasServerVariables,
59
+ oasSchemaExample,
60
+ oasMediaExample,
61
+ oasUnusedComponent,
62
+ oasMutuallyExclusive,
63
+ oasNoNullable,
64
+ oasSchema,
65
+ oasAdditionalOperations,
66
+ oasServerNameUnique,
67
+ oasTagParentDefined,
68
+ oasSchemaExampleDeprecated,
69
+ oasTagKind,
70
+ oasExampleValue,
71
+ oasExampleExternalValue
72
+ };
73
+ export {
74
+ oasAdditionalOperations2 as oasAdditionalOperations,
75
+ oasDiscriminator2 as oasDiscriminator,
76
+ oasExampleExternalValue2 as oasExampleExternalValue,
77
+ oasExampleValue2 as oasExampleValue,
78
+ oasFunctions,
79
+ oasMediaExample2 as oasMediaExample,
80
+ oasMutuallyExclusive2 as oasMutuallyExclusive,
81
+ oasNoNullable2 as oasNoNullable,
82
+ oasOpFormDataConsumeCheck2 as oasOpFormDataConsumeCheck,
83
+ oasOpIdUnique2 as oasOpIdUnique,
84
+ oasOpParams2 as oasOpParams,
85
+ oasOpSecurityDefined2 as oasOpSecurityDefined,
86
+ oasOpSuccessResponse2 as oasOpSuccessResponse,
87
+ oasPathParam2 as oasPathParam,
88
+ oasSchema2 as oasSchema,
89
+ oasSchemaExample2 as oasSchemaExample,
90
+ oasSchemaExampleDeprecated2 as oasSchemaExampleDeprecated,
91
+ oasServerNameUnique2 as oasServerNameUnique,
92
+ oasServerVariables2 as oasServerVariables,
93
+ oasTagDefined2 as oasTagDefined,
94
+ oasTagKind2 as oasTagKind,
95
+ oasTagParentDefined2 as oasTagParentDefined,
96
+ oasTagsUnique2 as oasTagsUnique,
97
+ oasUnusedComponent2 as oasUnusedComponent,
98
+ refSiblings2 as refSiblings
73
99
  };
@@ -1,4 +1,4 @@
1
- import type { RulesetFunction } from '../../../core/index.js';
1
+ import type { RulesetFunction } from '../../../core/types.js';
2
2
  /**
3
3
  * Flags standard HTTP methods inside an OpenAPI 3.2 `additionalOperations` map.
4
4
  * The spec reserves that map for methods without a dedicated fixed field, so a
@@ -1,25 +1,19 @@
1
- import { isObject, OPERATION_METHODS } from './helpers.js';
2
- // Methods that have a dedicated fixed field on the Path Item Object (the eight
3
- // standard methods plus 3.2's `query`). These MUST NOT be redefined inside the
4
- // new `additionalOperations` map, which is reserved for non-standard methods.
1
+ import { isObject, OPERATION_METHODS } from "./helpers.js";
5
2
  const FIXED_PATH_ITEM_METHODS = OPERATION_METHODS;
6
- /**
7
- * Flags standard HTTP methods inside an OpenAPI 3.2 `additionalOperations` map.
8
- * The spec reserves that map for methods without a dedicated fixed field, so a
9
- * standard method key (sent uppercase, e.g. `POST`) belongs in the lowercase
10
- * fixed field (`post`) instead.
11
- */
12
- export const oasAdditionalOperations = (input, _options, context) => {
13
- if (!isObject(input))
14
- return [];
15
- const results = [];
16
- for (const method of Object.keys(input)) {
17
- if (FIXED_PATH_ITEM_METHODS.has(method.toLowerCase())) {
18
- results.push({
19
- message: `"additionalOperations" must not redefine the standard method "${method}"; use the "${method.toLowerCase()}" field instead`,
20
- path: [...context.path, method],
21
- });
22
- }
3
+ const oasAdditionalOperations = (input, _options, context) => {
4
+ if (!isObject(input))
5
+ return [];
6
+ const results = [];
7
+ for (const method of Object.keys(input)) {
8
+ if (FIXED_PATH_ITEM_METHODS.has(method.toLowerCase())) {
9
+ results.push({
10
+ message: `"additionalOperations" must not redefine the standard method "${method}"; use the "${method.toLowerCase()}" field instead`,
11
+ path: [...context.path, method]
12
+ });
23
13
  }
24
- return results;
14
+ }
15
+ return results;
16
+ };
17
+ export {
18
+ oasAdditionalOperations
25
19
  };
@@ -1,3 +1,3 @@
1
- import type { RulesetFunction } from '../../../core/index.js';
1
+ import type { RulesetFunction } from '../../../core/types.js';
2
2
  /** Validates a v2 discriminator references a required property. */
3
3
  export declare const oasDiscriminator: RulesetFunction;
@@ -1,23 +1,25 @@
1
- import { isObject } from './helpers.js';
2
- /** Validates a v2 discriminator references a required property. */
3
- export const oasDiscriminator = (schema, _options, context) => {
4
- if (!isObject(schema) || typeof schema['discriminator'] !== 'string')
5
- return [];
6
- const property = schema['discriminator'];
7
- const required = Array.isArray(schema['required']) ? schema['required'] : [];
8
- const properties = isObject(schema['properties']) ? schema['properties'] : {};
9
- const results = [];
10
- if (!(property in properties)) {
11
- results.push({
12
- message: `Discriminator "${property}" must be defined in properties`,
13
- path: [...context.path, 'discriminator'],
14
- });
15
- }
16
- if (!required.includes(property)) {
17
- results.push({
18
- message: `Discriminator "${property}" must be a required property`,
19
- path: [...context.path, 'discriminator'],
20
- });
21
- }
22
- return results;
1
+ import { isObject } from "./helpers.js";
2
+ const oasDiscriminator = (schema, _options, context) => {
3
+ if (!isObject(schema) || typeof schema["discriminator"] !== "string")
4
+ return [];
5
+ const property = schema["discriminator"];
6
+ const required = Array.isArray(schema["required"]) ? schema["required"] : [];
7
+ const properties = isObject(schema["properties"]) ? schema["properties"] : {};
8
+ const results = [];
9
+ if (!(property in properties)) {
10
+ results.push({
11
+ message: `Discriminator "${property}" must be defined in properties`,
12
+ path: [...context.path, "discriminator"]
13
+ });
14
+ }
15
+ if (!required.includes(property)) {
16
+ results.push({
17
+ message: `Discriminator "${property}" must be a required property`,
18
+ path: [...context.path, "discriminator"]
19
+ });
20
+ }
21
+ return results;
22
+ };
23
+ export {
24
+ oasDiscriminator
23
25
  };
@@ -1,4 +1,4 @@
1
- import type { RulesetFunction } from '../../../core/index.js';
1
+ import type { RulesetFunction } from '../../../core/types.js';
2
2
  /**
3
3
  * Enforces that an Example Object carries exactly one inline value source. Across
4
4
  * all of OpenAPI 3.x an Example must use either `value` or `externalValue` (not
@@ -1,23 +1,15 @@
1
- import { isObject } from './helpers.js';
2
- /**
3
- * Enforces that an Example Object carries exactly one inline value source. Across
4
- * all of OpenAPI 3.x an Example must use either `value` or `externalValue` (not
5
- * both, not neither). OpenAPI 3.2 added `dataValue`/`serializedValue` as further
6
- * ways to supply the example, so their presence also satisfies the "has an
7
- * example" requirement — otherwise a valid 3.2 `dataValue`-only example would be
8
- * wrongly flagged. The mutual exclusivity of the new fields is policed separately
9
- * by `oas3_2-example-value`.
10
- */
11
- export const oasExampleExternalValue = (example) => {
12
- if (!isObject(example))
13
- return [];
14
- // A 3.2 dataValue/serializedValue already provides the example, so value /
15
- // externalValue are optional in that case.
16
- if (example['dataValue'] !== undefined || example['serializedValue'] !== undefined)
17
- return [];
18
- const present = ['value', 'externalValue'].filter((property) => property in example);
19
- if (present.length !== 1) {
20
- return [{ message: 'Example object must have exactly one of "value" or "externalValue"' }];
21
- }
1
+ import { isObject } from "./helpers.js";
2
+ const oasExampleExternalValue = (example) => {
3
+ if (!isObject(example))
22
4
  return [];
5
+ if (example["dataValue"] !== void 0 || example["serializedValue"] !== void 0)
6
+ return [];
7
+ const present = ["value", "externalValue"].filter((property) => property in example);
8
+ if (present.length !== 1) {
9
+ return [{ message: 'Example object must have exactly one of "value" or "externalValue"' }];
10
+ }
11
+ return [];
12
+ };
13
+ export {
14
+ oasExampleExternalValue
23
15
  };
@@ -1,3 +1,3 @@
1
- import type { RulesetFunction } from '../../../core/index.js';
1
+ import type { RulesetFunction } from '../../../core/types.js';
2
2
  /** Flags forbidden field combinations on an OpenAPI 3.2 Example Object. */
3
3
  export declare const oasExampleValue: RulesetFunction;