Skip to content

Commit

Permalink
fix: rename rule no-empty-enum-servers to no-server-variables-empty-e…
Browse files Browse the repository at this point in the history
…num (#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 <andrew.tatomyr@redocly.com>
  • Loading branch information
adamaltman and tatomyr authored Aug 18, 2022
1 parent 682b6a6 commit 9b1239c
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apis:

styleguide:
rules:
no-servers-empty-enum: error
no-server-variables-empty-enum: error
extends: []
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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 <test>ms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apis:

styleguide:
rules:
no-servers-empty-enum: error
no-server-variables-empty-enum: error
extends: []
Original file line number Diff line number Diff line change
@@ -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 <test>ms
Expand Down
2 changes: 1 addition & 1 deletion docs/rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/rules/no-empty-servers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions docs/rules/no-server-example-com.md
Original file line number Diff line number Diff line change
@@ -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`...).
Expand Down Expand Up @@ -37,7 +37,7 @@ An example configuration:
```yaml
styleguide:
rules:
no-server-example-com: error
no-server-example.com: error
```
## Examples
Expand All @@ -47,7 +47,7 @@ Given this configuration:
```yaml
styleguide:
rules:
no-server-example-com: error
no-server-example.com: error
```
Example of **incorrect** server:
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -36,7 +40,7 @@ An example configuration:
```yaml
styleguide:
rules:
no-empty-enum-servers: error
no-server-variables-empty-enum: error
```
## Examples
Expand All @@ -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:
Expand Down Expand Up @@ -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/)
3 changes: 2 additions & 1 deletion docs/rules/no-undefined-server-variable.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand All @@ -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",
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/config/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
4 changes: 2 additions & 2 deletions packages/core/src/config/minimal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
4 changes: 2 additions & 2 deletions packages/core/src/config/recommended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(`
Expand All @@ -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 [],
},
Expand All @@ -51,15 +51,15 @@ 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 [],
},
]
`);
});

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
Expand All @@ -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(`
Expand All @@ -92,15 +92,15 @@ 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 [],
},
]
`);
});

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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 []`);
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/rules/oas3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types/redocly-yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

1 comment on commit 9b1239c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements 68.7% 2889/4205
🟡 Branches 61.88% 1589/2568
🟡 Functions 60.13% 463/770
🟡 Lines 68.54% 2677/3906

Test suite run success

459 tests passing in 76 suites.

Report generated by 🧪jest coverage report action from 9b1239c

Please sign in to comment.