Repository: Redocly/redocly-cli
Pull request #921 (2022-11-02 09:19:46)

chore: remove deprecated fields from redocly config
## What/Why/How?

Removes deprecated fields suggestions from Redocly config file (like `apiDefinitions`, `lint`, `referenceDocs` &c.). 

## Reference

## Testing

## Screenshots (optional)

## Check yourself

- [x] Code is linted
- [x] 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 | 73.44%     |    3307/4503    |
|                                                                           🟡                                                                           | Branches   | 64.88%     |    1862/2870    |
|                                                                           🟡                                                                           | Functions  | 65.92%     |     559/848     |
|                                                                           🟡                                                                           | Lines      | 73.45%     |    3073/4184    |


## 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 62c7a9e3f4515672baff14c30e3dd0b1183629d5</p>


Patch:
diff --git a/packages/core/src/config/load.ts b/packages/core/src/config/load.ts
index 2e871198..2dd4c345 100644
--- a/packages/core/src/config/load.ts
+++ b/packages/core/src/config/load.ts
@@ -71,11 +71,8 @@ export async function loadConfig(
   } = {}
 ): Promise<Config> {
   const { configPath = findConfig(), customExtends, processRawConfig, files, region } = options;
-  const config = await getConfig(configPath);
+  const config = await getConfig(configPath, processRawConfig);
   const rawConfig = { ...config, files: files ?? config.files, region: region ?? config.region };
-  if (typeof processRawConfig === 'function') {
-    await processRawConfig(rawConfig);
-  }
 
   const redoclyClient = new RedoclyClient();
   const tokens = await redoclyClient.getTokens();
@@ -105,11 +102,17 @@ export function findConfig(dir?: string): string | undefined {
   return existingConfigFiles[0];
 }
 
-export async function getConfig(configPath: string | undefined = findConfig()): Promise<RawConfig> {
+export async function getConfig(
+  configPath: string | undefined = findConfig(),
+  processRawConfig?: (rawConfig: RawConfig) => void | Promise<void>
+): Promise<RawConfig> {
   if (!configPath || !doesYamlFileExist(configPath)) return {};
   try {
     const rawConfig =
       (await loadYaml<RawConfig & DeprecatedInRawConfig & FlatRawConfig>(configPath)) || {};
+    if (typeof processRawConfig === 'function') {
+      await processRawConfig(rawConfig);
+    }
     return transformConfig(rawConfig);
   } catch (e) {
     throw new Error(`Error parsing config file at '${configPath}': ${e.message}`);
diff --git a/packages/core/src/types/redocly-yaml.ts b/packages/core/src/types/redocly-yaml.ts
index 53d2d56e..f8d18d44 100644
--- a/packages/core/src/types/redocly-yaml.ts
+++ b/packages/core/src/types/redocly-yaml.ts
@@ -146,16 +146,8 @@ const ConfigRoot: NodeType = {
   properties: {
     organization: { type: 'string' },
     apis: 'ConfigApis',
-    apiDefinitions: {
-      type: 'object',
-      properties: {},
-      additionalProperties: { properties: { type: 'string' } },
-    }, // deprecated
     ...RootConfigStyleguide.properties,
-    styleguide: 'RootConfigStyleguide', // deprecated
-    lint: 'RootConfigStyleguide', // deprecated
     'features.openapi': 'ConfigReferenceDocs',
-    referenceDocs: 'ConfigReferenceDocs', // deprecated
     'features.mockServer': 'ConfigMockServer',
     region: { enum: ['us', 'eu'] },
     resolve: {


Test patch:
diff --git a/__tests__/lint-config/invalid-config--lint-config-error/snapshot.js b/__tests__/lint-config/invalid-config--lint-config-error/snapshot.js
index a3e4fbb1..5f0156c9 100644
--- a/__tests__/lint-config/invalid-config--lint-config-error/snapshot.js
+++ b/__tests__/lint-config/invalid-config--lint-config-error/snapshot.js
@@ -2,15 +2,15 @@
 
 exports[`E2E lint-config test with option: { dirName: 'invalid-config--lint-config-error', option: 'error' } 1`] = `
 
-[1] .redocly.yaml:6:5 at #/styleguide/rules/context
+[1] .redocly.yaml:5:3 at #/rules/context
 
 Property \`context\` is not expected here.
 
-4 | styleguide:
-5 |   rules:
-6 |     context: null
-  |     ^^^^^^^
-7 |
+3 |     root: ./openapi.yaml
+4 | rules:
+5 |   context: null
+  |   ^^^^^^^
+6 |
 
 Error was generated by the configuration spec rule.
 
diff --git a/__tests__/lint-config/invalid-config--lint-config-warn/snapshot.js b/__tests__/lint-config/invalid-config--lint-config-warn/snapshot.js
index 9961ffae..887dbae2 100644
--- a/__tests__/lint-config/invalid-config--lint-config-warn/snapshot.js
+++ b/__tests__/lint-config/invalid-config--lint-config-warn/snapshot.js
@@ -2,15 +2,15 @@
 
 exports[`E2E lint-config test with option: { dirName: 'invalid-config--lint-config-warn', option: 'warn' } 1`] = `
 
-[1] .redocly.yaml:6:5 at #/styleguide/rules/context
+[1] .redocly.yaml:5:3 at #/rules/context
 
 Property \`context\` is not expected here.
 
-4 | styleguide:
-5 |   rules:
-6 |     context: null
-  |     ^^^^^^^
-7 |
+3 |     root: ./openapi.yaml
+4 | rules:
+5 |   context: null
+  |   ^^^^^^^
+6 |
 
 Warning was generated by the configuration spec rule.
 
diff --git a/__tests__/lint-config/invalid-config--no-option/snapshot.js b/__tests__/lint-config/invalid-config--no-option/snapshot.js
index 506c0bc6..055d63b7 100644
--- a/__tests__/lint-config/invalid-config--no-option/snapshot.js
+++ b/__tests__/lint-config/invalid-config--no-option/snapshot.js
@@ -2,15 +2,15 @@
 
 exports[`E2E lint-config test with option: { dirName: 'invalid-config--no-option', option: null } 1`] = `
 
-[1] .redocly.yaml:6:5 at #/styleguide/rules/context
+[1] .redocly.yaml:5:3 at #/rules/context
 
 Property \`context\` is not expected here.
 
-4 | styleguide:
-5 |   rules:
-6 |     context: null
-  |     ^^^^^^^
-7 |
+3 |     root: ./openapi.yaml
+4 | rules:
+5 |   context: null
+  |   ^^^^^^^
+6 |
 
 Warning was generated by the configuration spec rule.
 
diff --git a/__tests__/lint-config/invalid-config-assertation-config-type/snapshot.js b/__tests__/lint-config/invalid-config-assertation-config-type/snapshot.js
index 1e979d41..9d5cb92a 100644
--- a/__tests__/lint-config/invalid-config-assertation-config-type/snapshot.js
+++ b/__tests__/lint-config/invalid-config-assertation-config-type/snapshot.js
@@ -2,16 +2,16 @@
 
 exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-config-type', option: 'error' } 1`] = `
 
-[1] .redocly.yaml:10:19 at #/styleguide/rules/assert~1path-item-mutually-required/where/0/subject/type
+[1] .redocly.yaml:8:17 at #/rules/assert~1path-item-mutually-required/where/0/subject/type
 
 \`type\` can be one of the following only: "Root", "Tag", "ExternalDocs", "Server", "ServerVariable", "ServerVariablesMap", "SecurityRequirement", "Info", "Contact", "License", "Paths", "PathItem", "Parameter", "Operation", "Callback", "CallbacksMap", "RequestBody", "MediaTypesMap", "MediaType", "Example", "ExamplesMap", "Encoding", "EncodingMap", "Header", "HeadersMap", "Responses", "Response", "Link", "LinksMap", "Schema", "Xml", "SchemaProperties", "DiscriminatorMapping", "Discriminator", "Components", "NamedSchemas", "NamedResponses", "NamedParameters", "NamedExamples", "NamedRequestBodies", "NamedHeaders", "NamedSecuritySchemes", "NamedLinks", "NamedCallbacks", "ImplicitFlow", "PasswordFlow", "ClientCredentials", "AuthorizationCode", "OAuth2Flows", "SecurityScheme", "XCodeSample", "WebhooksMap".
 
- 8 | where:
- 9 |   - subject:
-10 |       type: Invalid-type
+ 6 | where:
+ 7 |   - subject:
+ 8 |       type: Invalid-type
    |             ^^^^^^^^^^^^
-11 |       property: property
-12 |     assertions:
+ 9 |       property: property
+10 |     assertions:
 
 Error was generated by the configuration spec rule.
 
diff --git a/__tests__/lint-config/invalid-config-assertation-name/snapshot.js b/__tests__/lint-config/invalid-config-assertation-name/snapshot.js
index cdd68e68..f39972d6 100644
--- a/__tests__/lint-config/invalid-config-assertation-name/snapshot.js
+++ b/__tests__/lint-config/invalid-config-assertation-name/snapshot.js
@@ -2,16 +2,16 @@
 
 exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-name', option: 'error' } 1`] = `
 
-[1] .redocly.yaml:7:5 at #/styleguide/rules/asset~1path-item-mutually-required
+[1] .redocly.yaml:5:3 at #/rules/asset~1path-item-mutually-required
 
 The field \`severity\` must be present on this level.
 
-5 | extends: []
-6 | rules:
-7 |   asset/path-item-mutually-required:
+3 |     root: ./openapi.yaml
+4 | rules:
+5 |   asset/path-item-mutually-required:
   |   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-8 |     context:
-9 |       - type: PathItem
+6 |     context:
+7 |       - type: PathItem
 
 Error was generated by the configuration spec rule.
 
diff --git a/__tests__/lint-config/invalid-definition-and-config/snapshot.js b/__tests__/lint-config/invalid-definition-and-config/snapshot.js
index 5b0cb8e2..5f846d2d 100644
--- a/__tests__/lint-config/invalid-definition-and-config/snapshot.js
+++ b/__tests__/lint-config/invalid-definition-and-config/snapshot.js
@@ -2,15 +2,15 @@
 
 exports[`E2E lint-config invalid-definition-and-config 1`] = `
 
-[1] .redocly.yaml:6:5 at #/styleguide/rules/context
+[1] .redocly.yaml:5:3 at #/rules/context
 
 Property \`context\` is not expected here.
 
-4 | styleguide:
-5 |   rules:
-6 |     context: null
-  |     ^^^^^^^
-7 |
+3 |     root: ./openapi.yaml
+4 | rules:
+5 |   context: null
+  |   ^^^^^^^
+6 |
 
 Error was generated by the configuration spec rule.
 
diff --git a/__tests__/lint/deprecated-apiDefinitions/snapshot.js b/__tests__/lint/deprecated-apiDefinitions/snapshot.js
index d1d9e645..1a3c8711 100644
--- a/__tests__/lint/deprecated-apiDefinitions/snapshot.js
+++ b/__tests__/lint/deprecated-apiDefinitions/snapshot.js
@@ -2,6 +2,33 @@
 
 exports[`E2E lint deprecated-apiDefinitions 1`] = `
 
+[1] .redocly.yaml:1:1 at #/apiDefinitions
+
+Property \`apiDefinitions\` is not expected here.
+
+1 | apiDefinitions:
+  | ^^^^^^^^^^^^^^
+2 |   main: ./openapi.yaml
+3 | lint:
+
+Warning was generated by the configuration spec rule.
+
+
+[2] .redocly.yaml:3:1 at #/lint
+
+Property \`lint\` is not expected here.
+
+1 | apiDefinitions:
+2 |   main: ./openapi.yaml
+3 | lint:
+  | ^^^^
+4 |   rules:
+5 |     info-contact: warn
+
+Warning was generated by the configuration spec rule.
+
+
+You have 2 warnings.
 The 'apiDefinitions' field is deprecated. Use apis instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
 The 'lint' field is deprecated. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
 validating /openapi.yaml...
diff --git a/__tests__/lint/deprecated-lint/snapshot.js b/__tests__/lint/deprecated-lint/snapshot.js
index ba056180..342a2511 100644
--- a/__tests__/lint/deprecated-lint/snapshot.js
+++ b/__tests__/lint/deprecated-lint/snapshot.js
@@ -2,6 +2,21 @@
 
 exports[`E2E lint deprecated-lint 1`] = `
 
+[1] .redocly.yaml:7:1 at #/lint
+
+Property \`lint\` is not expected here.
+
+5 |       rules:
+6 |         operation-4xx-response: error
+7 | lint:
+  | ^^^^
+8 |   rules:
+9 |     info-contact: warn
+
+Warning was generated by the configuration spec rule.
+
+
+You have 1 warning.
 The 'lint' field is deprecated. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
 validating /openapi.yaml...
 [1] openapi.yaml:11:7 at #/paths/~1pet~1findByStatus/get/responses
diff --git a/__tests__/lint/deprecated-styleguide/snapshot.js b/__tests__/lint/deprecated-styleguide/snapshot.js
index f39da0f4..35a3a0e3 100644
--- a/__tests__/lint/deprecated-styleguide/snapshot.js
+++ b/__tests__/lint/deprecated-styleguide/snapshot.js
@@ -2,6 +2,21 @@
 
 exports[`E2E lint deprecated-styleguide 1`] = `
 
+[1] .redocly.yaml:7:1 at #/styleguide
+
+Property \`styleguide\` is not expected here.
+
+5 |       rules:
+6 |         operation-4xx-response: error
+7 | styleguide:
+  | ^^^^^^^^^^
+8 |   rules:
+9 |     info-contact: warn
+
+Warning was generated by the configuration spec rule.
+
+
+You have 1 warning.
 The 'styleguide' field is deprecated. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
 validating /openapi.yaml...
 [1] openapi.yaml:11:7 at #/paths/~1pet~1findByStatus/get/responses
diff --git a/__tests__/lint/no-enum-type-mismatch-error-recommended-config/.redocly.yaml b/__tests__/lint/no-enum-type-mismatch-error-recommended-config/.redocly.yaml
index 08d47eba..c3a67c4f 100644
--- a/__tests__/lint/no-enum-type-mismatch-error-recommended-config/.redocly.yaml
+++ b/__tests__/lint/no-enum-type-mismatch-error-recommended-config/.redocly.yaml
@@ -1,5 +1,6 @@
-apiDefinitions:
-  main: ./openapi.yaml
+apis:
+  main: 
+    root: ./openapi.yaml
 
 extends:
   - recommended # This is the default (and built in) configuration.
diff --git a/__tests__/lint/no-enum-type-mismatch-error-recommended-config/snapshot.js b/__tests__/lint/no-enum-type-mismatch-error-recommended-config/snapshot.js
index 0f8d5fee..aa82ad40 100644
--- a/__tests__/lint/no-enum-type-mismatch-error-recommended-config/snapshot.js
+++ b/__tests__/lint/no-enum-type-mismatch-error-recommended-config/snapshot.js
@@ -2,7 +2,6 @@
 
 exports[`E2E lint no-enum-type-mismatch-error-recommended-config 1`] = `
 
-The 'apiDefinitions' field is deprecated. Use apis instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
 validating /openapi.yaml...
 [1] openapi.yaml:1:1 at #/openapi
 
diff --git a/__tests__/lint/no-undefined-server-variable-error-recommended-config/.redocly.yaml b/__tests__/lint/no-undefined-server-variable-error-recommended-config/.redocly.yaml
index 0964060a..0f4d8f23 100644
--- a/__tests__/lint/no-undefined-server-variable-error-recommended-config/.redocly.yaml
+++ b/__tests__/lint/no-undefined-server-variable-error-recommended-config/.redocly.yaml
@@ -1,5 +1,6 @@
-apiDefinitions:
-  main: ./openapi.yaml
+apis:
+  main: 
+    root: ./openapi.yaml
 
 extends:
   - recommended # This is the default (and built in) configuration.
\ No newline at end of file
diff --git a/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js b/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js
index 13df1895..8212364f 100644
--- a/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js
+++ b/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js
@@ -2,7 +2,6 @@
 
 exports[`E2E lint no-undefined-server-variable-error-recommended-config 1`] = `
 
-The 'apiDefinitions' field is deprecated. Use apis instead. Read more about this change: https://redocly.com/docs/api-registry/guides/migration-guide-config-file/#changed-properties
 validating /openapi.yaml...
 [1] openapi.yaml:7:5 at #/servers/0/url
 
diff --git a/packages/core/src/__tests__/lint.test.ts b/packages/core/src/__tests__/lint.test.ts
index f974407d..6aa8df8b 100644
--- a/packages/core/src/__tests__/lint.test.ts
+++ b/packages/core/src/__tests__/lint.test.ts
@@ -249,7 +249,24 @@ describe('lint', () => {
     );
     const results = await lintConfig({ document });
 
-    expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
+    expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
+      Array [
+        Object {
+          "from": undefined,
+          "location": Array [
+            Object {
+              "pointer": "#/referenceDocs",
+              "reportOnKey": true,
+              "source": "",
+            },
+          ],
+          "message": "Property \`referenceDocs\` is not expected here.",
+          "ruleId": "configuration spec",
+          "severity": "error",
+          "suggest": Array [],
+        },
+      ]
+    `);
   });
 
   it("'plugins' shouldn't be allowed in 'apis'", async () => {
diff --git a/packages/core/src/config/__tests__/fixtures/load-redocly.yaml b/packages/core/src/config/__tests__/fixtures/load-redocly.yaml
new file mode 100644
index 00000000..e720abcd
--- /dev/null
+++ b/packages/core/src/config/__tests__/fixtures/load-redocly.yaml
@@ -0,0 +1,4 @@
+lint:
+  rules:
+    info-contact: warn
+  extends: []
diff --git a/packages/core/src/config/__tests__/load.test.ts b/packages/core/src/config/__tests__/load.test.ts
index 632f49ba..a15bf5a9 100644
--- a/packages/core/src/config/__tests__/load.test.ts
+++ b/packages/core/src/config/__tests__/load.test.ts
@@ -49,7 +49,10 @@ describe('loadConfig', () => {
 
   it('should call callback if such passed', async () => {
     const mockFn = jest.fn();
-    await loadConfig({ processRawConfig: mockFn });
+    await loadConfig({
+      configPath: path.join(__dirname, './fixtures/load-redocly.yaml'),
+      processRawConfig: mockFn,
+    });
     expect(mockFn).toHaveBeenCalled();
   });
 });