@redocly/openapi-core 2.56.1 → 2.57.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-enum-type-mismatch.d.ts","sourceRoot":"","sources":["../../../src/rules/common/no-enum-type-mismatch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-enum-type-mismatch.d.ts","sourceRoot":"","sources":["../../../src/rules/common/no-enum-type-mismatch.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIjG,eAAO,MAAM,kBAAkB,EAC3B,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,UAAU,GACV,WAqCH,CAAC"}
|
|
@@ -1,38 +1,32 @@
|
|
|
1
|
+
import { isPlainObject } from '../../utils/is-plain-object.js';
|
|
1
2
|
import { matchesJsonSchemaType, oasTypeOf } from '../utils.js';
|
|
2
3
|
export const NoEnumTypeMismatch = () => {
|
|
3
4
|
return {
|
|
4
5
|
Schema(schema, { report, location }) {
|
|
5
|
-
|
|
6
|
+
// the walker also visits boolean schemas (valid since OAS 3.1), which have nothing to check
|
|
7
|
+
if (!isPlainObject(schema) || !schema.type)
|
|
6
8
|
return;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const types = Array.isArray(schema.type) ? schema.type : [schema.type];
|
|
10
|
+
const matchesAnyType = (value) => types.some((type) => matchesJsonSchemaType(value, type, schema.nullable));
|
|
11
|
+
if (Array.isArray(schema.enum)) {
|
|
12
|
+
for (const [index, enumValue] of schema.enum.entries()) {
|
|
13
|
+
if (matchesAnyType(enumValue))
|
|
14
|
+
continue;
|
|
10
15
|
report({
|
|
11
|
-
message:
|
|
12
|
-
|
|
16
|
+
message: Array.isArray(schema.type)
|
|
17
|
+
? `Enum value \`${enumValue}\` must be of allowed types: \`${schema.type}\`.`
|
|
18
|
+
: `All values of \`enum\` field must be of the same type as the \`type\` field: expected "${schema.type}" but received "${oasTypeOf(enumValue)}".`,
|
|
19
|
+
location: location.child(['enum', index]),
|
|
13
20
|
reference: 'https://redocly.com/docs/cli/rules/common/no-enum-type-mismatch',
|
|
14
21
|
});
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!valid)
|
|
24
|
-
mismatchedResults[enumValue].push(type);
|
|
25
|
-
}
|
|
26
|
-
if (mismatchedResults[enumValue].length !== schema.type.length)
|
|
27
|
-
delete mismatchedResults[enumValue];
|
|
28
|
-
}
|
|
29
|
-
for (const mismatchedKey of Object.keys(mismatchedResults)) {
|
|
30
|
-
report({
|
|
31
|
-
message: `Enum value \`${mismatchedKey}\` must be of allowed types: \`${schema.type}\`.`,
|
|
32
|
-
location: location.child(['enum', schema.enum.indexOf(mismatchedKey)]),
|
|
33
|
-
reference: 'https://redocly.com/docs/cli/rules/common/no-enum-type-mismatch',
|
|
34
|
-
});
|
|
35
|
-
}
|
|
24
|
+
if ('const' in schema && !matchesAnyType(schema.const)) {
|
|
25
|
+
report({
|
|
26
|
+
message: `The \`const\` value must be of the same type as the \`type\` field: expected "${types.join('" or "')}" but received "${oasTypeOf(schema.const)}".`,
|
|
27
|
+
location: location.child(['const']),
|
|
28
|
+
reference: 'https://redocly.com/docs/cli/rules/common/no-enum-type-mismatch',
|
|
29
|
+
});
|
|
36
30
|
}
|
|
37
31
|
},
|
|
38
32
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"no-enum-type-mismatch.js","sourceRoot":"","sources":["../../../src/rules/common/no-enum-type-mismatch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"no-enum-type-mismatch.js","sourceRoot":"","sources":["../../../src/rules/common/no-enum-type-mismatch.ts"],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