From 9b1239c6d9e76042c71fc399f77cee25800d618e Mon Sep 17 00:00:00 2001 From: Adam Altman Date: Thu, 18 Aug 2022 08:07:10 -0500 Subject: [PATCH] fix: rename rule no-empty-enum-servers to no-server-variables-empty-enum (#813) * fix: rename rule no-empty-enum-servers to no-server-variables-empty-enum - fix no-server-example.com docs * chore: fix snapshots Co-authored-by: Andrew Tatomyr --- .../.redocly.yaml | 2 +- .../openapi.yaml | 0 .../snapshot.js | 6 ++-- .../.redocly.yaml | 2 +- .../openapi.yaml | 0 .../snapshot.js | 2 +- docs/rules.md | 2 +- docs/rules/no-empty-servers.md | 2 +- docs/rules/no-server-example-com.md | 6 ++-- ...s.md => no-server-variables-empty-enum.md} | 14 +++++--- docs/rules/no-undefined-server-variable.md | 3 +- .../config-resolvers.test.ts.snap | 8 ++--- packages/core/src/config/all.ts | 4 +-- packages/core/src/config/minimal.ts | 4 +-- packages/core/src/config/recommended.ts | 4 +-- .../no-empty-enum-servers.com.test.ts | 32 +++++++++---------- packages/core/src/rules/oas3/index.ts | 4 +-- ...m.ts => no-server-variables-empty-enum.ts} | 2 +- packages/core/src/types/redocly-yaml.ts | 2 +- 19 files changed, 52 insertions(+), 47 deletions(-) rename __tests__/lint/{no-servers-empty-enum-errror => no-server-variables-empty-enum-errror}/.redocly.yaml (64%) rename __tests__/lint/{no-servers-empty-enum-errror => no-server-variables-empty-enum-errror}/openapi.yaml (100%) rename __tests__/lint/{no-servers-empty-enum-errror => no-server-variables-empty-enum-errror}/snapshot.js (80%) rename __tests__/lint/{no-servers-empty-enum => no-server-variables-empty-enum}/.redocly.yaml (64%) rename __tests__/lint/{no-servers-empty-enum => no-server-variables-empty-enum}/openapi.yaml (100%) rename __tests__/lint/{no-servers-empty-enum => no-server-variables-empty-enum}/snapshot.js (74%) rename docs/rules/{no-empty-enum-servers.md => no-server-variables-empty-enum.md} (83%) rename packages/core/src/rules/oas3/{no-servers-empty-enum.ts => no-server-variables-empty-enum.ts} (97%) diff --git a/__tests__/lint/no-servers-empty-enum-errror/.redocly.yaml b/__tests__/lint/no-server-variables-empty-enum-errror/.redocly.yaml similarity index 64% rename from __tests__/lint/no-servers-empty-enum-errror/.redocly.yaml rename to __tests__/lint/no-server-variables-empty-enum-errror/.redocly.yaml index 963cb7c9f8..bbacf150dc 100644 --- a/__tests__/lint/no-servers-empty-enum-errror/.redocly.yaml +++ b/__tests__/lint/no-server-variables-empty-enum-errror/.redocly.yaml @@ -4,5 +4,5 @@ apis: styleguide: rules: - no-servers-empty-enum: error + no-server-variables-empty-enum: error extends: [] diff --git a/__tests__/lint/no-servers-empty-enum-errror/openapi.yaml b/__tests__/lint/no-server-variables-empty-enum-errror/openapi.yaml similarity index 100% rename from __tests__/lint/no-servers-empty-enum-errror/openapi.yaml rename to __tests__/lint/no-server-variables-empty-enum-errror/openapi.yaml diff --git a/__tests__/lint/no-servers-empty-enum-errror/snapshot.js b/__tests__/lint/no-server-variables-empty-enum-errror/snapshot.js similarity index 80% rename from __tests__/lint/no-servers-empty-enum-errror/snapshot.js rename to __tests__/lint/no-server-variables-empty-enum-errror/snapshot.js index 7a079fd359..3f1a36d3b8 100644 --- a/__tests__/lint/no-servers-empty-enum-errror/snapshot.js +++ b/__tests__/lint/no-server-variables-empty-enum-errror/snapshot.js @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`E2E lint no-servers-empty-enum-errror 1`] = ` +exports[`E2E lint no-server-variables-empty-enum-errror 1`] = ` validating /openapi.yaml... [1] openapi.yaml:5:1 at #/servers @@ -14,7 +14,7 @@ Server variable with \`enum\` must be a non-empty array. 6 | - url: https://example.com/user/{id}/place/{placeId} 7 | variables: -Error was generated by the no-servers-empty-enum rule. +Error was generated by the no-server-variables-empty-enum rule. [2] openapi.yaml:5:1 at #/servers @@ -28,7 +28,7 @@ Server variable define \`enum\` and \`default\`. \`enum\` must include default v 6 | - url: https://example.com/user/{id}/place/{placeId} 7 | variables: -Error was generated by the no-servers-empty-enum rule. +Error was generated by the no-server-variables-empty-enum rule. /openapi.yaml: validated in ms diff --git a/__tests__/lint/no-servers-empty-enum/.redocly.yaml b/__tests__/lint/no-server-variables-empty-enum/.redocly.yaml similarity index 64% rename from __tests__/lint/no-servers-empty-enum/.redocly.yaml rename to __tests__/lint/no-server-variables-empty-enum/.redocly.yaml index 963cb7c9f8..bbacf150dc 100644 --- a/__tests__/lint/no-servers-empty-enum/.redocly.yaml +++ b/__tests__/lint/no-server-variables-empty-enum/.redocly.yaml @@ -4,5 +4,5 @@ apis: styleguide: rules: - no-servers-empty-enum: error + no-server-variables-empty-enum: error extends: [] diff --git a/__tests__/lint/no-servers-empty-enum/openapi.yaml b/__tests__/lint/no-server-variables-empty-enum/openapi.yaml similarity index 100% rename from __tests__/lint/no-servers-empty-enum/openapi.yaml rename to __tests__/lint/no-server-variables-empty-enum/openapi.yaml diff --git a/__tests__/lint/no-servers-empty-enum/snapshot.js b/__tests__/lint/no-server-variables-empty-enum/snapshot.js similarity index 74% rename from __tests__/lint/no-servers-empty-enum/snapshot.js rename to __tests__/lint/no-server-variables-empty-enum/snapshot.js index 7afc301cd1..f9158940e6 100644 --- a/__tests__/lint/no-servers-empty-enum/snapshot.js +++ b/__tests__/lint/no-server-variables-empty-enum/snapshot.js @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`E2E lint no-servers-empty-enum 1`] = ` +exports[`E2E lint no-server-variables-empty-enum 1`] = ` validating /openapi.yaml... /openapi.yaml: validated in ms diff --git a/docs/rules.md b/docs/rules.md index b6e7dc2cb4..28fd115f36 100644 --- a/docs/rules.md +++ b/docs/rules.md @@ -75,7 +75,7 @@ The *Special rules* group contains rules that may apply to multiple objects or t - [no-empty-servers](./rules/no-empty-servers.md) - [no-server-example.com](./rules/no-server-example-com.md) - [no-server-trailing-slash](./rules/no-server-trailing-slash.md) -- [no-empty-enum-servers](./rules/no-empty-enum-servers.md) +- [no-server-variables-empty-enum](./rules/no-server-variables-empty-enum.md) - [no-undefined-server-variable](./rules/no-undefined-server-variable.md) ### Tags diff --git a/docs/rules/no-empty-servers.md b/docs/rules/no-empty-servers.md index 1f7e2ae259..ad6e904759 100644 --- a/docs/rules/no-empty-servers.md +++ b/docs/rules/no-empty-servers.md @@ -73,7 +73,7 @@ servers: ``` ## Related rules -- [no-server-example-com](./no-server-example-com.md) +- [no-server-example.com](./no-server-example-com.md) - [no-server-trailing-slash](./no-server-trailing-slash.md) ## Resources diff --git a/docs/rules/no-server-example-com.md b/docs/rules/no-server-example-com.md index ff2bd174e6..da8a1a1d17 100644 --- a/docs/rules/no-server-example-com.md +++ b/docs/rules/no-server-example-com.md @@ -1,4 +1,4 @@ -# no-server-example-com +# no-server-example.com Prevents using `example.com` as the value of the `servers.url` fields in your API definitions. The rule checks for all URL schemes (`http`, `https`...). @@ -37,7 +37,7 @@ An example configuration: ```yaml styleguide: rules: - no-server-example-com: error + no-server-example.com: error ``` ## Examples @@ -47,7 +47,7 @@ Given this configuration: ```yaml styleguide: rules: - no-server-example-com: error + no-server-example.com: error ``` Example of **incorrect** server: diff --git a/docs/rules/no-empty-enum-servers.md b/docs/rules/no-server-variables-empty-enum.md similarity index 83% rename from docs/rules/no-empty-enum-servers.md rename to docs/rules/no-server-variables-empty-enum.md index 92cabbbd22..7a102453d4 100644 --- a/docs/rules/no-empty-enum-servers.md +++ b/docs/rules/no-server-variables-empty-enum.md @@ -1,4 +1,8 @@ -# no-empty-enum-servers +--- +redirectFrom: + - /docs/cli/rules/no-empty-enum-servers/ +--- +# no-server-variables-empty-enum Disallow server variables without enum list defined. @@ -36,7 +40,7 @@ An example configuration: ```yaml styleguide: rules: - no-empty-enum-servers: error + no-server-variables-empty-enum: error ``` ## Examples @@ -46,7 +50,7 @@ Given this configuration: ```yaml styleguide: rules: - no-empty-enum-servers: error + no-server-variables-empty-enum: error ``` Example of **incorrect** server variables: @@ -80,10 +84,10 @@ servers: ## Related rules - [no-empty-servers](./no-empty-servers.md) -- [no-server-example-com](./no-server-example-com.md) +- [no-server-example.com](./no-server-example-com.md) - [no-undefined-server-variable](./no-undefined-server-variable.md) ## Resources -- [Rule source](https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/rules/oas3/no-servers-empty-enum.ts) +- [Rule source](https://github.com/Redocly/redocly-cli/blob/master/packages/core/src/rules/oas3/no-server-variables-empty-enum.ts) - [Servers list docs](https://redocly.com/docs/openapi-visual-reference/servers/) diff --git a/docs/rules/no-undefined-server-variable.md b/docs/rules/no-undefined-server-variable.md index d8a51b09a3..674d58cff4 100644 --- a/docs/rules/no-undefined-server-variable.md +++ b/docs/rules/no-undefined-server-variable.md @@ -68,7 +68,8 @@ servers: ## Related rules - [no-empty-servers](./no-empty-servers.md) -- [no-server-example-com](./no-server-example-com.md) +- [no-server-example.com](./no-server-example-com.md) +- [no-server-variables-empty-enum](./no-server-variables-empty-enum.md) ## Resources diff --git a/packages/core/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap b/packages/core/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap index b9b738e299..a4361c16f3 100644 --- a/packages/core/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap +++ b/packages/core/src/config/__tests__/__snapshots__/config-resolvers.test.ts.snap @@ -15,7 +15,7 @@ Object { "no-invalid-media-type-examples": "error", "no-server-example.com": "warn", "no-server-trailing-slash": "error", - "no-servers-empty-enum": "error", + "no-server-variables-empty-enum": "error", "no-undefined-server-variable": "error", "no-unused-components": "warn", }, @@ -27,7 +27,7 @@ Object { "no-invalid-media-type-examples": "error", "no-server-example.com": "warn", "no-server-trailing-slash": "error", - "no-servers-empty-enum": "error", + "no-server-variables-empty-enum": "error", "no-undefined-server-variable": "error", "no-unused-components": "warn", }, @@ -86,7 +86,7 @@ Object { "no-invalid-media-type-examples": "warn", "no-server-example.com": "warn", "no-server-trailing-slash": "error", - "no-servers-empty-enum": "error", + "no-server-variables-empty-enum": "error", "no-undefined-server-variable": "error", "no-unused-components": "warn", }, @@ -98,7 +98,7 @@ Object { "no-invalid-media-type-examples": "warn", "no-server-example.com": "warn", "no-server-trailing-slash": "error", - "no-servers-empty-enum": "error", + "no-server-variables-empty-enum": "error", "no-undefined-server-variable": "error", "no-unused-components": "warn", }, diff --git a/packages/core/src/config/all.ts b/packages/core/src/config/all.ts index fefe8579a2..1aa23b8e70 100644 --- a/packages/core/src/config/all.ts +++ b/packages/core/src/config/all.ts @@ -51,7 +51,7 @@ export default { 'no-example-value-and-externalValue': 'error', 'no-unused-components': 'error', 'no-undefined-server-variable': 'error', - 'no-servers-empty-enum': 'error', + 'no-server-variables-empty-enum': 'error', }, oas3_1Rules: { 'no-server-example.com': 'error', @@ -60,6 +60,6 @@ export default { 'no-example-value-and-externalValue': 'error', 'no-unused-components': 'error', 'no-undefined-server-variable': 'error', - 'no-servers-empty-enum': 'error', + 'no-server-variables-empty-enum': 'error', }, } as PluginStyleguideConfig; diff --git a/packages/core/src/config/minimal.ts b/packages/core/src/config/minimal.ts index 49241fc811..9a2b189ec7 100644 --- a/packages/core/src/config/minimal.ts +++ b/packages/core/src/config/minimal.ts @@ -44,7 +44,7 @@ export default { 'no-example-value-and-externalValue': 'warn', 'no-unused-components': 'warn', 'no-undefined-server-variable': 'warn', - 'no-servers-empty-enum': 'error', + 'no-server-variables-empty-enum': 'error', }, oas3_1Rules: { 'no-invalid-media-type-examples': 'warn', @@ -54,6 +54,6 @@ export default { 'no-example-value-and-externalValue': 'warn', 'no-unused-components': 'warn', 'no-undefined-server-variable': 'warn', - 'no-servers-empty-enum': 'error', + 'no-server-variables-empty-enum': 'error', }, } as PluginStyleguideConfig; diff --git a/packages/core/src/config/recommended.ts b/packages/core/src/config/recommended.ts index 56066405c6..d345159d4b 100644 --- a/packages/core/src/config/recommended.ts +++ b/packages/core/src/config/recommended.ts @@ -44,7 +44,7 @@ export default { 'no-example-value-and-externalValue': 'error', 'no-unused-components': 'warn', 'no-undefined-server-variable': 'error', - 'no-servers-empty-enum': 'error', + 'no-server-variables-empty-enum': 'error', }, oas3_1Rules: { 'no-invalid-media-type-examples': 'warn', @@ -54,6 +54,6 @@ export default { 'no-example-value-and-externalValue': 'error', 'no-unused-components': 'warn', 'no-undefined-server-variable': 'error', - 'no-servers-empty-enum': 'error', + 'no-server-variables-empty-enum': 'error', }, } as PluginStyleguideConfig; diff --git a/packages/core/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts b/packages/core/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts index bae9acb14c..38a6d7a664 100644 --- a/packages/core/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts +++ b/packages/core/src/rules/oas3/__tests__/no-empty-enum-servers.com.test.ts @@ -3,8 +3,8 @@ import { lintDocument } from '../../../lint'; import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils'; import { BaseResolver } from '../../../resolve'; -describe('Oas3 as3-no-servers-empty-enum', () => { - it('oas3-no-servers-empty-enum: should report on server object with empty enum and unknown enum value', async () => { +describe('Oas3 as3-no-server-variables-empty-enum', () => { + it('oas3-no-server-variables-empty-enum: should report on server object with empty enum and unknown enum value', async () => { const document = parseYamlToDocument( outdent` openapi: 3.0.0 @@ -24,7 +24,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, - config: await makeConfig({ 'no-servers-empty-enum': 'error' }), + config: await makeConfig({ 'no-server-variables-empty-enum': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` @@ -38,7 +38,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { }, ], "message": "Server variable with \`enum\` must be a non-empty array.", - "ruleId": "no-servers-empty-enum", + "ruleId": "no-server-variables-empty-enum", "severity": "error", "suggest": Array [], }, @@ -51,7 +51,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { }, ], "message": "Server variable define \`enum\` and \`default\`. \`enum\` must include default value", - "ruleId": "no-servers-empty-enum", + "ruleId": "no-server-variables-empty-enum", "severity": "error", "suggest": Array [], }, @@ -59,7 +59,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { `); }); - it('oas3-no-servers-empty-enum: should report on server object with empty enum', async () => { + it('oas3-no-server-variables-empty-enum: should report on server object with empty enum', async () => { const document = parseYamlToDocument( outdent` openapi: 3.0.0 @@ -78,7 +78,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, - config: await makeConfig({ 'no-servers-empty-enum': 'error' }), + config: await makeConfig({ 'no-server-variables-empty-enum': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` @@ -92,7 +92,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { }, ], "message": "Server variable with \`enum\` must be a non-empty array.", - "ruleId": "no-servers-empty-enum", + "ruleId": "no-server-variables-empty-enum", "severity": "error", "suggest": Array [], }, @@ -100,7 +100,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { `); }); - it('oas3-no-servers-empty-enum: should be success because variables is empty object', async () => { + it('oas3-no-server-variables-empty-enum: should be success because variables is empty object', async () => { const document = parseYamlToDocument( outdent` openapi: 3.0.0 @@ -117,13 +117,13 @@ describe('Oas3 as3-no-servers-empty-enum', () => { const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, - config: await makeConfig({ 'no-servers-empty-enum': 'error' }), + config: await makeConfig({ 'no-server-variables-empty-enum': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); }); - it('oas3-no-servers-empty-enum: should be success because variable is empty object', async () => { + it('oas3-no-server-variables-empty-enum: should be success because variable is empty object', async () => { const document = parseYamlToDocument( outdent` openapi: 3.0.0 @@ -141,13 +141,13 @@ describe('Oas3 as3-no-servers-empty-enum', () => { const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, - config: await makeConfig({ 'no-servers-empty-enum': 'error' }), + config: await makeConfig({ 'no-server-variables-empty-enum': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); }); - it('oas3-no-servers-empty-enum: should be success because enum contains default value', async () => { + it('oas3-no-server-variables-empty-enum: should be success because enum contains default value', async () => { const document = parseYamlToDocument( outdent` openapi: 3.0.0 @@ -168,13 +168,13 @@ describe('Oas3 as3-no-servers-empty-enum', () => { const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, - config: await makeConfig({ 'no-servers-empty-enum': 'error' }), + config: await makeConfig({ 'no-server-variables-empty-enum': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); }); - it('oas3-no-servers-empty-enum: should be success because enum contains default value', async () => { + it('oas3-no-server-variables-empty-enum: should be success because enum contains default value', async () => { const document = parseYamlToDocument( outdent` openapi: 3.0.0 @@ -197,7 +197,7 @@ describe('Oas3 as3-no-servers-empty-enum', () => { const results = await lintDocument({ externalRefResolver: new BaseResolver(), document, - config: await makeConfig({ 'no-servers-empty-enum': 'error' }), + config: await makeConfig({ 'no-server-variables-empty-enum': 'error' }), }); expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`); diff --git a/packages/core/src/rules/oas3/index.ts b/packages/core/src/rules/oas3/index.ts index 4265bbedcb..f36192886e 100644 --- a/packages/core/src/rules/oas3/index.ts +++ b/packages/core/src/rules/oas3/index.ts @@ -37,7 +37,7 @@ import { NoUndefinedServerVariable } from './no-undefined-server-variable'; import { OperationOperationId } from '../common/operation-operationId'; import { OperationSummary } from '../common/operation-summary'; import { NoAmbiguousPaths } from '../common/no-ambiguous-paths'; -import { NoEmptyEnumServers } from './no-servers-empty-enum'; +import { NoServerVariablesEmptyEnum } from './no-server-variables-empty-enum'; import { NoHttpVerbsInPaths } from '../common/no-http-verbs-in-paths'; import { RequestMimeType } from './request-mime-type'; import { ResponseMimeType } from './response-mime-type'; @@ -89,7 +89,7 @@ export const rules = { 'no-identical-paths': NoIdenticalPaths, 'no-ambiguous-paths': NoAmbiguousPaths, 'no-undefined-server-variable': NoUndefinedServerVariable, - 'no-servers-empty-enum': NoEmptyEnumServers, + 'no-server-variables-empty-enum': NoServerVariablesEmptyEnum, 'no-http-verbs-in-paths': NoHttpVerbsInPaths, 'path-excludes-patterns': PathExcludesPatterns, 'request-mime-type': RequestMimeType, diff --git a/packages/core/src/rules/oas3/no-servers-empty-enum.ts b/packages/core/src/rules/oas3/no-server-variables-empty-enum.ts similarity index 97% rename from packages/core/src/rules/oas3/no-servers-empty-enum.ts rename to packages/core/src/rules/oas3/no-server-variables-empty-enum.ts index cae4997e90..38354e498d 100644 --- a/packages/core/src/rules/oas3/no-servers-empty-enum.ts +++ b/packages/core/src/rules/oas3/no-server-variables-empty-enum.ts @@ -6,7 +6,7 @@ enum enumError { invalidDefaultValue = 'invalidDefaultValue', } -export const NoEmptyEnumServers: Oas3Rule = () => { +export const NoServerVariablesEmptyEnum: Oas3Rule = () => { return { DefinitionRoot(root, { report, location }) { if (!root.servers || root.servers.length === 0) return; diff --git a/packages/core/src/types/redocly-yaml.ts b/packages/core/src/types/redocly-yaml.ts index 8e801a41df..44de25b228 100644 --- a/packages/core/src/types/redocly-yaml.ts +++ b/packages/core/src/types/redocly-yaml.ts @@ -40,7 +40,7 @@ const builtInRulesList = [ 'no-identical-paths', 'no-ambiguous-paths', 'no-undefined-server-variable', - 'no-servers-empty-enum', + 'no-server-variables-empty-enum', 'no-http-verbs-in-paths', 'path-excludes-patterns', 'request-mime-type',