Repository: Redocly/redocly-cli
Pull request #1115 (2023-05-31 14:45:40)

fix: apply regular expression only to fixed fields under components
## What/Why/How?

 Apply regular expression `^[a-zA-Z0-9\.\-_]+$` only to fixed fields under components

## Reference

Closes: https://github.com/Redocly/redocly-cli/issues/1104

## Testing

## Screenshots (optional)

## 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]: | Command | Mean [s] | Min [s] | Max [s] | Relative |
|:---|---:|---:|---:|---:|
| `redocly lint packages/core/src/benchmark/benches/rebilly.yaml` | 1.266 ± 0.025 | 1.231 | 1.312 | 1.00 ± 0.03 |
| `redocly-next lint packages/core/src/benchmark/benches/rebilly.yaml` | 1.264 ± 0.032 | 1.218 | 1.326 | 1.00 |

<!-- thollander/actions-comment-pull-request "hyperfine-comparison" -->
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 | 73.24%     |    3508/4790    |
|                                                                           🟡                                                                           | Branches   | 64.89%     |    2003/3087    |
|                                                                           🟡                                                                           | Functions  | 65.63%     |     588/896     |
|                                                                           🟡                                                                           | Lines      | 73.29%     |    3265/4455    |


<details><summary>Show files with reduced coverage 🔻</summary>
<br/>

| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | File                                                                                                                   | Statements                                                     | Branches | Functions                                                      | Lines                                                          |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------- | :------- | :------------------------------------------------------------- | :------------------------------------------------------------- |
|                                                                           🟡                                                                           | <div title="core/src/rules/oas3/spec-components-invalid-map-name.ts">`...` / spec-components-invalid-map-name.ts</div> | <div title="Base coverage is: 68.75%">66.67% (-2.08% 🔻)</div> | 100%     | <div title="Base coverage is: 58.33%">54.55% (-3.79% 🔻)</div> | <div title="Base coverage is: 66.67%">64.29% (-2.38% 🔻)</div> |

</details>

## Test suite run success
588 tests passing in 85 suites.

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


Patch:
diff --git a/packages/core/src/rules/oas3/spec-components-invalid-map-name.ts b/packages/core/src/rules/oas3/spec-components-invalid-map-name.ts
index 6ee21837..0765aae3 100644
--- a/packages/core/src/rules/oas3/spec-components-invalid-map-name.ts
+++ b/packages/core/src/rules/oas3/spec-components-invalid-map-name.ts
@@ -65,10 +65,5 @@ export const SpecComponentsInvalidMapName: Oas3Rule = () => {
         validateKey(key, report, location, 'callbacks');
       },
     },
-    ExampleMap: {
-      Example(_node, { key, report, location }: UserContext) {
-        validateKey(key, report, location, 'examples');
-      },
-    },
   };
 };


Test patch:
diff --git a/packages/core/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts b/packages/core/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts
index a71087d4..395da6f3 100644
--- a/packages/core/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts
+++ b/packages/core/src/rules/oas3/__tests__/spec-components-invalid-map-name.test.ts
@@ -215,7 +215,7 @@ describe('Oas3 spec-components-invalid-map-name', () => {
     expect(results).toMatchInlineSnapshot(`Array []`);
   });
 
-  it('should report about invalid keys inside nested examples', async () => {
+  it('should not report invalid keys inside nested examples', async () => {
     const document = parseYamlToDocument(outdent`
       openapi: 3.0.0
       info:
@@ -227,7 +227,7 @@ describe('Oas3 spec-components-invalid-map-name', () => {
             description: param
             in: path
             examples:
-              invalid identifier:
+              valid identifier:
                 description: 'Some description'
                 value: 21 
 		`);
@@ -258,7 +258,7 @@ describe('Oas3 spec-components-invalid-map-name', () => {
             description: param
             in: path
             examples:
-              invalid identifier:
+              valid identifier:
                 description: 'Some description'
                 value: 21 ",
                 "mimeType": undefined,
@@ -270,35 +270,6 @@ describe('Oas3 spec-components-invalid-map-name', () => {
           "severity": "error",
           "suggest": Array [],
         },
-        Object {
-          "location": Array [
-            Object {
-              "pointer": "#/components/parameters/my Param/examples/invalid identifier",
-              "reportOnKey": true,
-              "source": Source {
-                "absoluteRef": "",
-                "body": "openapi: 3.0.0
-      info:
-        version: 3.0.0
-      components:
-        parameters:
-          my Param:
-            name: param
-            description: param
-            in: path
-            examples:
-              invalid identifier:
-                description: 'Some description'
-                value: 21 ",
-                "mimeType": undefined,
-              },
-            },
-          ],
-          "message": "The map key in examples \\"invalid identifier\\" does not match the regular expression \\"^[a-zA-Z0-9\\\\.\\\\-_]+$\\"",
-          "ruleId": "spec-components-invalid-map-name",
-          "severity": "error",
-          "suggest": Array [],
-        },
       ]
     `);
   });