Skip to content

Commit

Permalink
feat(rulesets): more consistent messages in OAS ruleset (#1713)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Jul 8, 2021
1 parent ddcb7c8 commit 2899777
Show file tree
Hide file tree
Showing 63 changed files with 229 additions and 261 deletions.
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@stoplight/spectral-parsers": "^0.0.0",
"@stoplight/spectral-ref-resolver": "^0.0.0",
"@stoplight/spectral-ruleset-migrator": "^0.0.0",
"@stoplight/spectral-rulesets": "*",
"@stoplight/spectral-runtime": "^0.0.0",
"@stoplight/types": "12.3.0",
"chalk": "4.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ testRule('contact-properties', [
},
errors: [
{
message: 'Contact object should have `name`, `url` and `email`.',
message: 'Contact object must have "name", "url" and "email".',
path: ['info', 'contact'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ testRule('duplicated-entry-in-enum', [

errors: [
{
message: `A duplicated entry in the enum was found. Error: "enum" property must not have duplicate items (items ## 1 and 5 are identical)`,
message: `"enum" property must not have duplicate items (items ## 1 and 5 are identical)`,
path: ['definitions', 'Test', 'enum'],
severity: DiagnosticSeverity.Warning,
},
Expand Down Expand Up @@ -108,7 +108,7 @@ testRule('duplicated-entry-in-enum', [
},
errors: [
{
message: `A duplicated entry in the enum was found. Error: "enum" property must not have duplicate items (items ## 1 and 5 are identical)`,
message: `"enum" property must not have duplicate items (items ## 1 and 5 are identical)`,
path: ['components', 'schemas', 'Test', 'enum'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/__tests__/info-contact.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ testRule('info-contact', [
},
errors: [
{
message: 'Info object should contain `contact` object.',
message: 'Info object must have "contact" object.',
path: ['info'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ testRule('info-description', [
},
errors: [
{
message: 'OpenAPI object info `description` must be present and non-empty string.',
message: 'Info "description" must be present and non-empty string.',
path: ['info'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/__tests__/info-license.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ testRule('info-license', [
},
errors: [
{
message: 'OpenAPI object `info` should contain a `license` object.',
message: 'Info object must have "license" object.',
path: ['info'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
1 change: 1 addition & 0 deletions packages/rulesets/src/oas/__tests__/license-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ testRule('license-url', [
},
errors: [
{
message: 'License object must include "url".',
path: ['info', 'license'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
28 changes: 14 additions & 14 deletions packages/rulesets/src/oas/__tests__/no-$ref-siblings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,22 @@ testRule('no-$ref-siblings', [
},
errors: [
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['responses'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['responses', '300', 'description'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['responses', '300', 'abc'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['openapi'],
severity: DiagnosticSeverity.Error,
},
Expand Down Expand Up @@ -93,28 +93,28 @@ testRule('no-$ref-siblings', [
},
errors: [
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['securityDefinitions', 'apikey'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path', 'post'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path', 'get'],
severity: DiagnosticSeverity.Error,
},
{
code: 'no-$ref-siblings',
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path', 'get', 'security'],
severity: DiagnosticSeverity.Error,
},
Expand Down Expand Up @@ -149,27 +149,27 @@ testRule('no-$ref-siblings', [
},
errors: [
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['components', 'securityDefinitions', 'apikey'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path', 'post'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path', 'get'],
severity: DiagnosticSeverity.Error,
},
{
message: '$ref cannot be placed next to any other properties',
message: '$ref must not be placed next to any other properties',
path: ['paths', '/path', 'get', 'security'],
severity: DiagnosticSeverity.Error,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ testRule('no-eval-in-markdown', [
},
errors: [
{
message: 'Markdown descriptions should not contain `eval(`.',
message: 'Markdown descriptions must not have "eval(".',
path: ['info', 'title'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -46,7 +46,7 @@ testRule('no-eval-in-markdown', [
},
errors: [
{
message: 'Markdown descriptions should not contain `eval(`.',
message: 'Markdown descriptions must not have "eval(".',
path: ['info', 'description'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ testRule('no-script-tags-in-markdown', [
},
errors: [
{
message: 'Markdown descriptions should not contain `<script>` tags.',
message: 'Markdown descriptions must not have "<script>" tags.',
path: ['info', 'description'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/__tests__/oas2-anyOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ testRule('oas2-anyOf', [
},
errors: [
{
message: 'anyOf is not available in OpenAPI v2, it was added in OpenAPI v3',
message: '"anyOf" keyword must not be used in OpenAPI v2 document.',
path: ['paths', '/test', 'get', 'responses', '200', 'schema', 'anyOf'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/__tests__/oas2-api-host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ testRule('oas2-api-host', [
errors: [
{
code: 'oas2-api-host',
message: 'OpenAPI `host` must be present and non-empty string.',
message: 'OpenAPI "host" must be present and non-empty string.',
path: [],
severity: DiagnosticSeverity.Warning,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/rulesets/src/oas/__tests__/oas2-api-schemes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ testRule('oas2-api-schemes', [
},
errors: [
{
message: 'OpenAPI host `schemes` must be present and non-empty array.',
message: 'OpenAPI host "schemes" must be present and non-empty array.',
path: [],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -36,7 +36,7 @@ testRule('oas2-api-schemes', [
},
errors: [
{
message: 'OpenAPI host `schemes` must be present and non-empty array.',
message: 'OpenAPI host "schemes" must be present and non-empty array.',
path: ['schemes'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ testRule('oas2-host-not-example', [
},
errors: [
{
message: 'Host URL should not point at example.com.',
message: 'Host URL must not point at example.com.',
path: ['host'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ testRule('oas2-host-trailing-slash', [
},
errors: [
{
message: 'Server URL should not have a trailing slash.',
message: 'Server URL must not have trailing slash.',
path: ['host'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/rulesets/src/oas/__tests__/oas2-oneOf.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ testRule('oas2-oneOf', [
},
errors: [
{
message: 'oneOf is not available in OpenAPI v2, it was added in OpenAPI v3',
message: '"oneOf" keyword must not be used in OpenAPI v2 document.',
path: ['paths', '/test', 'get', 'responses', '200', 'schema', 'oneOf'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ testRule('oas2-operation-formData-consume-check', [
errors: [
{
message:
'Operations with an `in: formData` parameter must include `application/x-www-form-urlencoded` or `multipart/form-data` in their `consumes` property.',
'Operations with "in: formData" parameter must include "application/x-www-form-urlencoded" or "multipart/form-data" in their "consumes" property.',
path: ['paths', '/path1', 'get'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ testRule('oas2-operation-security-defined', [
},
errors: [
{
message: 'Operation `security` values must match a scheme defined in the `securityDefinitions` object.',
message: 'Operation "security" values must match a scheme defined in the "securityDefinitions" object.',
path: ['paths', '/path', 'get', 'security', '0'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ testRule('oas2-parameter-description', [
},
errors: [
{
message: 'Parameter objects should have a `description`.',
message: 'Parameter objects must have "description".',
path: ['paths', '/todos', 'parameters', '0'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -105,7 +105,7 @@ testRule('oas2-parameter-description', [
},
errors: [
{
message: 'Parameter objects should have a `description`.',
message: 'Parameter objects must have "description".',
path: ['paths', '/todos', 'get', 'parameters', '0'],
severity: DiagnosticSeverity.Warning,
},
Expand Down Expand Up @@ -143,7 +143,7 @@ testRule('oas2-parameter-description', [
},
errors: [
{
message: 'Parameter objects should have a `description`.',
message: 'Parameter objects must have "description".',
path: ['parameters', 'limit'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
4 changes: 2 additions & 2 deletions packages/rulesets/src/oas/__tests__/oas3-api-servers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ testRule('oas3-api-servers', [
},
errors: [
{
message: 'OpenAPI `servers` must be present and non-empty array.',
message: 'OpenAPI "servers" must be present and non-empty array.',
path: [],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -37,7 +37,7 @@ testRule('oas3-api-servers', [
errors: [
{
code: 'oas3-api-servers',
message: 'OpenAPI `servers` must be present and non-empty array.',
message: 'OpenAPI "servers" must be present and non-empty array.',
path: ['servers'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['components', 'examples', 'first'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -131,7 +131,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['components', 'examples', 'third'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -148,7 +148,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['components', 'examples', 'first'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -169,7 +169,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['components', 'examples', 'second'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -194,7 +194,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['components', 'headers', 'headerName', 'examples', 'second'],
severity: DiagnosticSeverity.Warning,
},
Expand All @@ -219,7 +219,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['components', 'parameters', 'parameterName', 'examples', 'second'],
severity: DiagnosticSeverity.Warning,
},
Expand Down Expand Up @@ -255,7 +255,7 @@ testRule('oas3-examples-value-or-externalValue', [
},
errors: [
{
message: 'Examples should have either a `value` or `externalValue` field.',
message: 'Examples must have either "value" or "externalValue" field.',
path: ['paths', '/path', 'get', 'responses', '200', 'content', 'application/json', 'examples', 'second'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ testRule('oas3-operation-security-defined', [
},
errors: [
{
message: 'Operation `security` values must match a scheme defined in the `components.securitySchemes` object.',
message: 'Operation "security" values must match a scheme defined in the "components.securitySchemes" object.',
path: ['paths', '/path', 'get', 'security', '0'],
severity: DiagnosticSeverity.Warning,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ testRule('oas3-parameter-description', [
},
errors: [
{
message: 'Parameter objects should have a `description`.',
message: 'Parameter objects must have "description".',
path: ['components', 'parameters', 'address'],
severity: DiagnosticSeverity.Warning,
},
Expand Down

0 comments on commit 2899777

Please sign in to comment.