Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set default severity for lint config #1292

Merged
merged 11 commits into from
Oct 19, 2023
5 changes: 5 additions & 0 deletions .changeset/witty-taxis-occur.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@redocly/cli': patch
---

Set default severity for the config validation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include why this is useful, and what behaviour change the user might experience.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

26 changes: 20 additions & 6 deletions __tests__/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ describe('E2E', () => {
{ dirName: 'invalid-config--lint-config-error', option: 'error' },
{ dirName: 'invalid-lint-config-severity', option: 'something' },
{ dirName: 'invalid-config--no-option', option: null },
{ dirName: 'invalid-config-assertation-name', option: 'error' },
{ dirName: 'invalid-config-assertation-config-type', option: 'error' },
{ dirName: 'invalid-config-assertation-name', option: 'warn' },
{ dirName: 'invalid-config-assertation-config-type', option: 'warn' },
{ dirName: 'invalid-config-format-json', option: 'warn', format: 'json' },
];

Expand All @@ -85,15 +85,29 @@ describe('E2E', () => {
(expect(result) as any).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
});

test('invalid-definition-and-config', () => {
const folderPath = join(__dirname, 'lint-config/invalid-definition-and-config');
const configSeverityOptions: { dirName: string; option: string | null; snapshot: string }[] = [
{
dirName: 'invalid-definition-and-config',
option: 'error',
snapshot: 'config-with-error.snapshot.js',
},
{
dirName: 'invalid-definition-and-config',
option: 'warn',
snapshot: 'config-with-warn.snapshot.js',
},
];

test.each(configSeverityOptions)('invalid-definition-and-config: %s', (severityOption) => {
const { dirName, option, snapshot } = severityOption;
const folderPath = join(__dirname, `lint-config/${dirName}`);
const relativeInvalidOpenapiFile = relative(folderPath, invalidOpenapiFile);
const args = [relativeInvalidOpenapiFile, `--lint-config=error`];
const args = [relativeInvalidOpenapiFile, `--lint-config=${option}`];
const passedArgs = getParams('../../../packages/cli/src/index.ts', 'lint', args);

const result = getCommandOutput(passedArgs, folderPath);

(expect(result) as any).toMatchSpecificSnapshot(join(folderPath, 'snapshot.js'));
(expect(result) as any).toMatchSpecificSnapshot(join(folderPath, snapshot));
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ Error was generated by the configuration spec rule.


❌ Your config has 1 error.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms

Woohoo! Your API description is valid. 🎉

[WARNING] Unused rules found in .redocly.yaml: context.
Check the spelling and verify the added plugin prefix.

`;
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Property \`context\` is not expected here.
Warning was generated by the configuration spec rule.


You have 1 warning.
⚠️ Your config has 1 warning.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Property \`context\` is not expected here.
Warning was generated by the configuration spec rule.


You have 1 warning.
⚠️ Your config has 1 warning.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,31 @@ validating ../__fixtures__/valid-openapi.yaml...
Woohoo! Your API description is valid. 🎉


`;

exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-config-type', option: 'warn' } 1`] = `
IgorKarpiuk marked this conversation as resolved.
Show resolved Hide resolved

[1] .redocly.yaml:8:17 at #/rules/assert~1path-item-mutually-required/where/0/subject/type

\`type\` can be one of the following only: "any", "Root", "Tag", "TagList", "ExternalDocs", "Server", "ServerList", "ServerVariable", "ServerVariablesMap", "SecurityRequirement", "SecurityRequirementList", "Info", "Contact", "License", "Paths", "PathItem", "Parameter", "ParameterList", "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", "XCodeSampleList", "WebhooksMap", "SpecExtension", "Message".

6 | where:
7 | - subject:
8 | type: Invalid-type
| ^^^^^^^^^^^^
9 | property: property
10 | assertions:

Warning was generated by the configuration spec rule.


⚠️ Your config has 1 warning.

The 'assert/' syntax in assert/path-item-mutually-required is deprecated. Update your configuration to use 'rule/' instead. Examples and more information: https://redocly.com/docs/cli/rules/configurable-rules/
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms

Woohoo! Your API description is valid. 🎉


`;
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,30 @@ Woohoo! Your API description is valid. 🎉
Check the spelling and verify the added plugin prefix.

`;

exports[`E2E lint-config test with option: { dirName: 'invalid-config-assertation-name', option: 'warn' } 1`] = `
IgorKarpiuk marked this conversation as resolved.
Show resolved Hide resolved

[1] .redocly.yaml:5:3 at #/rules/asset~1path-item-mutually-required

The field \`severity\` must be present on this level.

3 | root: ./openapi.yaml
4 | rules:
5 | asset/path-item-mutually-required:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6 | context:
7 | - type: PathItem

Warning was generated by the configuration spec rule.


⚠️ Your config has 1 warning.
validating ../__fixtures__/valid-openapi.yaml...
../__fixtures__/valid-openapi.yaml: validated in <test>ms

Woohoo! Your API description is valid. 🎉

[WARNING] Unused rules found in .redocly.yaml: asset/path-item-mutually-required.
Check the spelling and verify the added plugin prefix.

`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config invalid-definition-and-config: {
dirName: 'invalid-definition-and-config',
option: 'error',
snapshot: 'config-with-error.snapshot.js'
} 1`] = `

[1] .redocly.yaml:5:3 at #/rules/context

Property \`context\` is not expected here.

3 | root: ./openapi.yaml
4 | rules:
5 | context: null
| ^^^^^^^
6 | extends:
7 | - recommended

Error was generated by the configuration spec rule.


❌ Your config has 1 error.


`;
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`E2E lint-config invalid-definition-and-config 1`] = `
exports[`E2E lint-config invalid-definition-and-config: {
dirName: 'invalid-definition-and-config',
option: 'warn',
snapshot: 'config-with-warn.snapshot.js'
} 1`] = `

[1] .redocly.yaml:5:3 at #/rules/context

Expand All @@ -13,10 +17,10 @@ Property \`context\` is not expected here.
6 | extends:
7 | - recommended

Error was generated by the configuration spec rule.
Warning was generated by the configuration spec rule.


Your config has 1 error.
⚠️ Your config has 1 warning.
validating ../__fixtures__/invalid-openapi.yaml...
[1] ../__fixtures__/invalid-openapi.yaml:4:1 at #/info

Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint/deprecated-apiDefinitions/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Did you mean: env ?
Warning was generated by the configuration spec rule.


You have 2 warnings.
⚠️ Your config has 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...
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint/deprecated-lint/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Did you mean: env ?
Warning was generated by the configuration spec rule.


You have 1 warning.
⚠️ Your config has 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
Expand Down
2 changes: 1 addition & 1 deletion __tests__/lint/deprecated-styleguide/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Property \`styleguide\` is not expected here.
Warning was generated by the configuration spec rule.


You have 1 warning.
⚠️ Your config has 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
Expand Down
13 changes: 8 additions & 5 deletions __tests__/split/missing-outDir/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ Positionals:
api API description file that you want to split [string] [required]

Options:
--version Show version number. [boolean]
--help Show help. [boolean]
--outDir Output directory where files will be saved. [string] [required]
--separator File path separator used while splitting. [string] [default: "_"]
--config Path to the config file. [string]
--version Show version number. [boolean]
--help Show help. [boolean]
--outDir Output directory where files will be saved. [string] [required]
--separator File path separator used while splitting.
[string] [default: "_"]
--config Path to the config file. [string]
--lint-config Severity level for config file linting.
[choices: "warn", "error", "off"] [default: "warn"]

Missing required argument: outDir

Expand Down
25 changes: 13 additions & 12 deletions docs/commands/build-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@ redocly build-docs <api> -t custom.hbs --templateOptions.metaDescription "Page m

## Options

| Option | Type | Description |
| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| api | string | Path to the API description filename or alias that you want to generate the build for. Refer to the [API examples](#api-examples) for more information. |
| --output, -o | string | Sets the path and name of the output file. The default value is `redoc-static.html`. |
| --title | string | Sets the page title. |
| --disableGoogleFont | boolean | Disables Google fonts. The default value is `false`. |
| --template, -t | string | Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI description. |
| --templateOptions | string | Adds template options you want to pass to your custom Handlebars template. To add options, use dot notation. |
| --theme.openapi | string | Customizes your output with [Redoc functionality options](https://redocly.com/docs/api-reference-docs/configuration/functionality/) or [Redoc theming options](https://redocly.com/docs/api-reference-docs/configuration/theming/). |
| --config | string | Specifies path to the [configuration file](#custom-configuration-file). |
| --help | boolean | Shows help. |
| --version | boolean | Shows version number. |
| Option | Type | Description |
| ------------------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| api | string | Path to the API description filename or alias that you want to generate the build for. Refer to the [API examples](#api-examples) for more information. |
| --output, -o | string | Sets the path and name of the output file. The default value is `redoc-static.html`. |
| --title | string | Sets the page title. |
| --disableGoogleFont | boolean | Disables Google fonts. The default value is `false`. |
| --template, -t | string | Uses custom [Handlebars](https://handlebarsjs.com/) templates to render your OpenAPI description. |
| --templateOptions | string | Adds template options you want to pass to your custom Handlebars template. To add options, use dot notation. |
| --theme.openapi | string | Customizes your output with [Redoc functionality options](https://redocly.com/docs/api-reference-docs/configuration/functionality/) or [Redoc theming options](https://redocly.com/docs/api-reference-docs/configuration/theming/). |
| --config | string | Specifies path to the [configuration file](#custom-configuration-file). |
| --help | boolean | Shows help. |
| --version | boolean | Shows version number. |
| --lint-config | string | Specify the severity level for the configuration file. <br/> **Possible values:** `warn`, `error`, `off`. Default value is `warn`. |

## Examples

Expand Down
Loading
Loading