@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":"AAEA,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,WA+CH,CAAC"}
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
- if (schema.enum && !Array.isArray(schema.enum))
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
- if (schema.enum && schema.type && !Array.isArray(schema.type)) {
8
- const typeMismatchedValues = schema.enum.filter((item) => !matchesJsonSchemaType(item, schema.type, schema.nullable));
9
- for (const mismatchedValue of typeMismatchedValues) {
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: `All values of \`enum\` field must be of the same type as the \`type\` field: expected "${schema.type}" but received "${oasTypeOf(mismatchedValue)}".`,
12
- location: location.child(['enum', schema.enum.indexOf(mismatchedValue)]),
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 (schema.enum && schema.type && Array.isArray(schema.type)) {
18
- const mismatchedResults = {};
19
- for (const enumValue of schema.enum) {
20
- mismatchedResults[enumValue] = [];
21
- for (const type of schema.type) {
22
- const valid = matchesJsonSchemaType(enumValue, type, schema.nullable);
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":["../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C,IAAI;oBAC/C,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;oBACnC,SAAS,EAAE,iEAAiE;iBAC7E,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/openapi-core",
3
- "version": "2.56.1",
3
+ "version": "2.57.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "types": "lib/index.d.ts",