Repository: Redocly/openapi-cli (ts)

Issue:
Add 3.1 support to typeExtension
Currently, trying to use a `typeExtension` with a 3.1.0 OpenAPI document raises an exception in `extendTypes`:

https://github.com/Redocly/openapi-cli/blob/0c92e4e528b6086b769ffe71cdd5907638935ca7/packages/core/src/config/config.ts#L248-L265

resulting in

```
Something went wrong when processing openapi31.yaml:

  - Not implemented.

/.../node_modules/@redocly/openapi-core/lib/config/config.js:116
                        throw new Error('Not implemented');
                              ^

Error: Not implemented
    at LintConfig.extendTypes (/.../node_modules/@redocly/openapi-core/lib/config/config.js:116:31)
    at /.../node_modules/@redocly/openapi-core/lib/bundle.js:52:53
    at Generator.next (<anonymous>)
    at /.../node_modules/@redocly/openapi-core/lib/bundle.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/.../node_modules/@redocly/openapi-core/lib/bundle.js:4:12)
    at bundleDocument (/.../node_modules/@redocly/openapi-core/lib/bundle.js:47:12)
    at Object.<anonymous> (/.../node_modules/@redocly/openapi-core/lib/bundle.js:42:16)
    at Generator.next (<anonymous>)
    at fulfilled (/.../node_modules/@redocly/openapi-core/lib/bundle.js:5:58)
```

My plugin simply adds a definition for `x-tagGroups`:

```
const listOf = require('@redocly/openapi-core/lib/types').listOf
const id = 'myPlugin'

/** @type { import('@redocly/openapi-core/src/types').NodeType} */
const XTagGroup = {
  properties: {
    name: { type: 'string' },
    tags: { type: 'array', items: { type: 'string' } }
  }
}

/** @type { import('@redocly/openapi-cli/src/config/config').TypeExtensionsConfig } */
const typeExtension = {
  oas3 (types, oasVersion) {
    return {
      ...types,
      DefinitionRoot: {
        ...types.DefinitionRoot,
        properties: {
          ...types.DefinitionRoot.properties,
          'x-tagGroups': listOf('XTagGroup')
        }
      },
      XTagGroup
    }
  }
}

module.exports = {
  id,
  typeExtension
}
```

Can this please have an additional `case OasVersion.Version3_1:` line added to the `OasVersion.Version3_0` block?

Pull request:
Support OAS 3.1 in type extensions
## What/Why/How?

Plugin type extensions are the only remaining place that doesn't support
OpenAPI 3.1.0 documents.

## Reference

Fixes #314

## Testing

I've parametrized the existing type extensions test. The fact that the test
adds webhook support (something OAS 3.1 has explicit support for now) may be
slightly silly, but the test is no less valid for it.

## Check yourself

- [X] Code is linted
- [ ] Tested with redoc/reference-docs/workflows
  - (I don't think this is applicable here)
- [X] All new/updated code is covered with tests


Patch:
diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts
index 05a4f861..9d89aecb 100755
--- a/packages/core/src/config/config.ts
+++ b/packages/core/src/config/config.ts
@@ -251,6 +251,7 @@ export class LintConfig {
       if (plugin.typeExtension !== undefined) {
         switch (version) {
           case OasVersion.Version3_0:
+          case OasVersion.Version3_1:
             if (!plugin.typeExtension.oas3) continue;
             extendedTypes = plugin.typeExtension.oas3(extendedTypes, version);
           case OasVersion.Version2:


Test patch:
diff --git a/packages/core/__tests__/walk.test.ts b/packages/core/__tests__/walk.test.ts
index be407fd2..8c4e77d7 100644
--- a/packages/core/__tests__/walk.test.ts
+++ b/packages/core/__tests__/walk.test.ts
@@ -1,4 +1,5 @@
 import outdent from 'outdent';
+import each from 'jest-each';
 import * as path from 'path';
 
 import { lintDocument } from '../src/lint';
@@ -1246,7 +1247,10 @@ describe('context.resolve', () => {
 });
 
 describe('type extensions', () => {
-  it('should correctly visit extended types', async () => {
+  each([
+    ['3.0.0', 'oas3_0'],
+    ['3.1.0', 'oas3_1'],
+  ]).it('should correctly visit OpenAPI %s extended types', async (openapi, oas) => {
     const calls: string[] = [];
 
     const testRuleSet: Oas3RuleSet = {
@@ -1274,7 +1278,7 @@ describe('type extensions', () => {
 
     const document = parseYamlToDocument(
       outdent`
-        openapi: 3.0.0
+        openapi: ${openapi}
         x-webhooks:
           name: test
           parameters:
@@ -1289,7 +1293,7 @@ describe('type extensions', () => {
       config: makeConfigForRuleset(testRuleSet, {
         typeExtension: {
           oas3(types, version) {
-            expect(version).toEqual('oas3_0');
+            expect(version).toEqual(oas);
 
             return {
               ...types,