Repository: Redocly/redocly-cli
Pull request #931 (2022-11-11 10:52:45)

chore: ignore discriminator error
## What/Why/How?
We would like to temporarily ignore an error regarding the discriminator usage.

## Reference
N/a

## Testing
Locally.

## Screenshots (optional)
N/a

## Check yourself

- [x] Code is linted
- [ ] Tested with redoc/reference-docs/workflows
- [ ] 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 | 73.45%     |    3309/4505    |
|                                                                           🟡                                                                           | Branches   | 64.89%     |    1863/2871    |
|                                                                           🟡                                                                           | Functions  | 65.92%     |     559/848     |
|                                                                           🟡                                                                           | Lines      | 73.46%     |    3075/4186    |


## Test suite run success
509 tests passing in 84 suites.

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


Patch:
diff --git a/packages/core/src/rules/utils.ts b/packages/core/src/rules/utils.ts
index 0184a066..7ce0df22 100644
--- a/packages/core/src/rules/utils.ts
+++ b/packages/core/src/rules/utils.ts
@@ -118,6 +118,10 @@ export function validateExample(
       }
     }
   } catch (e) {
+    if (e.message === 'discriminator: requires oneOf or anyOf composite keyword') {
+      return;
+    }
+
     report({
       message: `Example validation errored: ${e.message}.`,
       location: location.child('schema'),


Test patch:
diff --git a/packages/core/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts b/packages/core/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts
index 2d85840b..a0930ce9 100644
--- a/packages/core/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts
+++ b/packages/core/src/rules/oas3/__tests__/no-invalid-media-type-examples.test.ts
@@ -438,4 +438,36 @@ describe('no-invalid-media-type-examples', () => {
       ]
     `);
   });
+
+  it('should not report if allOf used with discriminator', async () => {
+    const document = parseYamlToDocument(
+      outdent`
+        openapi: 3.0.0
+        paths:
+          /pet:
+            get:
+              responses:
+                '200':
+                  content:
+                    application/json:
+                      schema:
+                        discriminator:
+                          propertyName: powerSource
+                          mapping: {}
+                        allOf: []
+                      examples:
+                        first:
+                          value: {}
+      `,
+      'foobar.yaml'
+    );
+
+    const results = await lintDocument({
+      externalRefResolver: new BaseResolver(),
+      document,
+      config: await makeConfig({ 'no-invalid-media-type-examples': 'error' }),
+    });
+
+    expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
+  });
 });