@amritk/lint 0.3.2 → 0.3.3
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.
- package/dist/core/document.js +12 -10
- package/dist/core/formats.js +10 -13
- package/dist/core/glob.js +96 -118
- package/dist/core/index.js +31 -11
- package/dist/core/jsonpath.js +487 -561
- package/dist/core/lint.js +78 -85
- package/dist/core/plugin.js +21 -29
- package/dist/core/pointers.js +107 -151
- package/dist/core/ruleset.js +0 -0
- package/dist/core/runner.js +214 -272
- package/dist/core/types.js +4 -1
- package/dist/core/validate-ruleset.js +98 -112
- package/dist/fix/apply.js +58 -96
- package/dist/fix/index.js +7 -2
- package/dist/fix/plugin.js +15 -20
- package/dist/functions/alphabetical.js +39 -50
- package/dist/functions/casing.js +39 -45
- package/dist/functions/defined.js +7 -5
- package/dist/functions/enumeration.js +15 -25
- package/dist/functions/falsy.js +7 -5
- package/dist/functions/index.js +60 -44
- package/dist/functions/length.js +22 -32
- package/dist/functions/or.js +18 -24
- package/dist/functions/pattern.js +39 -49
- package/dist/functions/schema.js +93 -119
- package/dist/functions/truthy.js +7 -5
- package/dist/functions/typed-enum.js +33 -36
- package/dist/functions/undefined.js +7 -8
- package/dist/functions/unreferenced-reusable-object.js +35 -47
- package/dist/functions/xor.js +13 -16
- package/dist/index.js +114 -164
- package/dist/parsers/edit-model.js +316 -444
- package/dist/parsers/index.js +22 -19
- package/dist/parsers/json.js +39 -37
- package/dist/parsers/lines.js +23 -26
- package/dist/parsers/types.js +9 -7
- package/dist/parsers/yaml.js +137 -204
- package/dist/rules/openapi/fixers.js +166 -221
- package/dist/rules/openapi/formats.js +26 -27
- package/dist/rules/openapi/functions/example-validation.js +98 -138
- package/dist/rules/openapi/functions/helpers.js +8 -10
- package/dist/rules/openapi/functions/index.js +98 -72
- package/dist/rules/openapi/functions/oas-additional-operations.js +16 -22
- package/dist/rules/openapi/functions/oas-discriminator.js +24 -22
- package/dist/rules/openapi/functions/oas-example-external-value.js +13 -21
- package/dist/rules/openapi/functions/oas-example-value.js +24 -27
- package/dist/rules/openapi/functions/oas-mutually-exclusive.js +15 -19
- package/dist/rules/openapi/functions/oas-no-nullable.js +13 -21
- package/dist/rules/openapi/functions/oas-op-form-data-consume-check.js +21 -19
- package/dist/rules/openapi/functions/oas-op-id-unique.js +27 -27
- package/dist/rules/openapi/functions/oas-op-params.js +36 -42
- package/dist/rules/openapi/functions/oas-op-security-defined.js +40 -39
- package/dist/rules/openapi/functions/oas-op-success-response.js +11 -13
- package/dist/rules/openapi/functions/oas-path-param.js +75 -96
- package/dist/rules/openapi/functions/oas-schema-example-deprecated.js +33 -40
- package/dist/rules/openapi/functions/oas-schema.js +9 -14
- package/dist/rules/openapi/functions/oas-server-name-unique.js +21 -19
- package/dist/rules/openapi/functions/oas-server-variables.js +45 -49
- package/dist/rules/openapi/functions/oas-tag-defined.js +20 -20
- package/dist/rules/openapi/functions/oas-tag-kind.js +16 -16
- package/dist/rules/openapi/functions/oas-tag-parent-defined.js +40 -43
- package/dist/rules/openapi/functions/oas-tags-unique.js +18 -16
- package/dist/rules/openapi/functions/oas-unused-component.js +48 -58
- package/dist/rules/openapi/functions/ref-siblings.js +13 -11
- package/dist/rules/openapi/index.js +99 -117
- package/dist/rules/openapi/oas.js +524 -536
- package/dist/rules/openapi/schemas/index.js +17 -33
- package/dist/rules/openapi/schemas/oas20.json +1 -1592
- package/dist/rules/openapi/schemas/oas30.json +1 -1651
- package/dist/rules/openapi/schemas/oas31.json +1 -1412
- package/dist/rules/openapi/schemas/oas32.json +1 -1684
- package/package.json +5 -5
|
@@ -1,160 +1,120 @@
|
|
|
1
|
-
import { validate } from
|
|
2
|
-
import { isObject } from
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
14
|
+
return validator(input);
|
|
15
|
+
} catch {
|
|
16
|
+
return true;
|
|
22
17
|
}
|
|
23
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
57
|
-
|
|
29
|
+
const tail = path[path.length - 1];
|
|
30
|
+
return tail === "properties" || tail === "patternProperties";
|
|
58
31
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
|
|
55
|
+
}
|
|
88
56
|
}
|
|
89
|
-
|
|
57
|
+
schemaExampleResults.set(schema, findings);
|
|
58
|
+
}
|
|
59
|
+
return withPath(findings, context.path);
|
|
90
60
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,73 +1,99 @@
|
|
|
1
|
-
import { oasMediaExample, oasSchemaExample } from
|
|
2
|
-
import { oasAdditionalOperations } from
|
|
3
|
-
import { oasDiscriminator } from
|
|
4
|
-
import { oasExampleExternalValue } from
|
|
5
|
-
import { oasExampleValue } from
|
|
6
|
-
import { oasMutuallyExclusive } from
|
|
7
|
-
import { oasNoNullable } from
|
|
8
|
-
import { oasOpFormDataConsumeCheck } from
|
|
9
|
-
import { oasOpIdUnique } from
|
|
10
|
-
import { oasOpParams } from
|
|
11
|
-
import { oasOpSecurityDefined } from
|
|
12
|
-
import { oasOpSuccessResponse } from
|
|
13
|
-
import { oasPathParam } from
|
|
14
|
-
import { oasSchema } from
|
|
15
|
-
import { oasSchemaExampleDeprecated } from
|
|
16
|
-
import { oasServerNameUnique } from
|
|
17
|
-
import { oasServerVariables } from
|
|
18
|
-
import { oasTagDefined } from
|
|
19
|
-
import { oasTagKind } from
|
|
20
|
-
import { oasTagParentDefined } from
|
|
21
|
-
import { oasTagsUnique } from
|
|
22
|
-
import { oasUnusedComponent } from
|
|
23
|
-
import { refSiblings } from
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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,25 +1,19 @@
|
|
|
1
|
-
import { isObject, OPERATION_METHODS } from
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
14
|
+
}
|
|
15
|
+
return results;
|
|
16
|
+
};
|
|
17
|
+
export {
|
|
18
|
+
oasAdditionalOperations
|
|
25
19
|
};
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { isObject } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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,23 +1,15 @@
|
|
|
1
|
-
import { isObject } from
|
|
2
|
-
|
|
3
|
-
|
|
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
|
};
|