Repository: Redocly/redocly-cli
Pull request #784 (2022-07-31 11:13:55)

fix: fix enum type mismatch message
## What/Why/How?

The current message is wrong, because in 3.1 you can define multiple types. The behavior works fine though except for `type: any` and an issue is opened for that (#786).

## Testing

Tests were adjusted as well.

## Screenshots (optional)

<img width="712" alt="2022-07-31_06-00-53" src="https://user-images.githubusercontent.com/1161871/182023010-02ba993e-6721-4057-924a-5c7c51bccfee.png">


## Check yourself

- [x] Code is linted
- [ ] Tested with redoc/reference-docs/workflows
- [x] All new/updated code is covered with tests

## Security

- [x] Security impact of change has been considered
- [x] Code follows company security practices and guidelines


github-actions[bot]: <!-- jest coverage report action for options with hash 3339ae53a38c44382c0fb4491bdb282d -->

## Coverage report 



| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | Category   | Percentage | Covered / Total |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------- | :--------- | :-------------: |
|                                                                           🟡                                                                           | Statements | 67.87%     |    2830/4170    |
|                                                                           🟡                                                                           | Branches   | 61%        |    1561/2559    |
|                                                                           🔴                                                                           | Functions  | 59.19%     |     451/762     |
|                                                                           🟡                                                                           | Lines      | 68.14%     |    2626/3854    |


## Test suite run success
422 tests passing in 74 suites.

<p align="right">Report generated by <a href="https://github.com/ArtiomTr/jest-coverage-report-action">🧪jest coverage report action</a> from 8508a75322cfcef417f2e251140013c22d84e8a0</p>

adamaltman: @tatomyr do I need to prepare a changelog? If so, we should also update this: https://github.com/Redocly/redocly-cli/blob/master/.github/CONTRIBUTING.md#pull-request-guidelines
tatomyr: I don't think you need. We will do this when creating the next release.

Patch:
diff --git a/packages/core/src/rules/common/no-enum-type-mismatch.ts b/packages/core/src/rules/common/no-enum-type-mismatch.ts
index 28c1fedb..e9aa6611 100644
--- a/packages/core/src/rules/common/no-enum-type-mismatch.ts
+++ b/packages/core/src/rules/common/no-enum-type-mismatch.ts
@@ -39,7 +39,7 @@ export const NoEnumTypeMismatch: Oas3Rule | Oas2Rule = () => {
 
         for (const mismatchedKey of Object.keys(mismatchedResults)) {
           report({
-            message: `Enum value \`${mismatchedKey}\` must be of one type. Allowed types: \`${schema.type}\`.`,
+            message: `Enum value \`${mismatchedKey}\` must be of allowed types: \`${schema.type}\`.`,
             location: location.child(['enum', schema.enum.indexOf(mismatchedKey)]),
           });
         };


Test patch:
diff --git a/__tests__/lint/no-enum-type-mismatch-error/snapshot.js b/__tests__/lint/no-enum-type-mismatch-error/snapshot.js
index 90bb9a12..1cc55de4 100644
--- a/__tests__/lint/no-enum-type-mismatch-error/snapshot.js
+++ b/__tests__/lint/no-enum-type-mismatch-error/snapshot.js
@@ -5,7 +5,7 @@ exports[`E2E lint no-enum-type-mismatch-error 1`] = `
 validating /openapi.yaml...
 [1] openapi.yaml:21:21 at #/paths/~1ping/get/responses/200/content/application~1json/schema/enum/3
 
-Enum value \`string\` must be of one type. Allowed types: \`integer,array\`.
+Enum value \`string\` must be of allowed types: \`integer,array\`.
 
 19 |                 - [ 1, 2, 3, string]
 20 |                 - 3
diff --git a/packages/core/src/rules/common/__tests__/no-enum-type-mismatch.test.ts b/packages/core/src/rules/common/__tests__/no-enum-type-mismatch.test.ts
index ac9aa077..d537995f 100644
--- a/packages/core/src/rules/common/__tests__/no-enum-type-mismatch.test.ts
+++ b/packages/core/src/rules/common/__tests__/no-enum-type-mismatch.test.ts
@@ -153,7 +153,7 @@ describe('Oas3 typed enum', () => {
               "source": "foobar.yaml",
             },
           ],
-          "message": "Enum value \`string\` must be of one type. Allowed types: \`integer,array\`.",
+          "message": "Enum value \`string\` must be of allowed types: \`integer,array\`.",
           "ruleId": "no-enum-type-mismatch",
           "severity": "error",
           "suggest": Array [],