diff --git a/.changeset/tasty-poems-fly.md b/.changeset/tasty-poems-fly.md new file mode 100644 index 000000000..5c0d8fc0a --- /dev/null +++ b/.changeset/tasty-poems-fly.md @@ -0,0 +1,5 @@ +--- +"@redocly/openapi-core": patch +--- + +Updated Spot validation rules. diff --git a/docs/guides/lint-arazzo.md b/docs/guides/lint-arazzo.md index f403f733f..1266d13f9 100644 --- a/docs/guides/lint-arazzo.md +++ b/docs/guides/lint-arazzo.md @@ -82,7 +82,7 @@ extends: arazzoRules: sourceDescription-name-unique: warn - version-enum: error + spot-supported-versions: error ``` The configuration shown here gives some good entry-level linting using the `minimal` standard, and adds checks that we're using a supported version of Arazzo, and warns if each source description doesn't have a unique name. diff --git a/docs/rules/built-in-rules.md b/docs/rules/built-in-rules.md index 167658641..0f71e0583 100644 --- a/docs/rules/built-in-rules.md +++ b/docs/rules/built-in-rules.md @@ -135,8 +135,7 @@ Within the Arazzo family of rules, there are rules for the main Arazzo specifica The below rules are being migrated to Spot: - [no-criteria-xpath](./spot/no-criteria-xpath.md): the `xpath` type criteria is not supported by Spot. -- [parameters-not-in-body](./spot/parameters-not-in-body.md): the `in` section inside `parameters` must not contain a `body`. -- [version-enum](./spot/version-enum.md): the `version` property must be one of the supported values. +- [spot-supported-versions](./spot/spot-supported-versions.md): the `version` property must be one of the supported values. ## Resources diff --git a/docs/rules/ruleset-templates.md b/docs/rules/ruleset-templates.md index d69485d86..9906de5c7 100644 --- a/docs/rules/ruleset-templates.md +++ b/docs/rules/ruleset-templates.md @@ -221,9 +221,7 @@ rules: ```yaml rules: struct: error - parameters-not-in-body: off sourceDescription-type: off - version-enum: warn workflowId-unique: error stepId-unique: error sourceDescription-name-unique: off @@ -231,6 +229,7 @@ rules: parameters-unique: off step-onSuccess-unique: off step-onFailure-unique: off + spot-supported-versions: off requestBody-replacements-unique: off no-criteria-xpath: off no-actions-type-end: off @@ -491,9 +490,7 @@ rules: ```yaml rules: struct: error - parameters-not-in-body: warn sourceDescription-type: error - version-enum: warn workflowId-unique: error stepId-unique: error sourceDescription-name-unique: error @@ -501,8 +498,9 @@ rules: parameters-unique: error step-onSuccess-unique: warn step-onFailure-unique: warn + spot-supported-versions: off requestBody-replacements-unique: warn - no-criteria-xpath: warn + no-criteria-xpath: off no-actions-type-end: warn criteria-unique: warn ``` diff --git a/docs/rules/spec-ruleset.md b/docs/rules/spec-ruleset.md index 4d7b337c6..af81151be 100644 --- a/docs/rules/spec-ruleset.md +++ b/docs/rules/spec-ruleset.md @@ -7,19 +7,18 @@ slug: /docs/cli/rules/spec This ruleset strictly follows the specifications. All the rules are of severity `error`: -- `struct` +- [struct](./arazzo/struct.md) +- [criteria-unique](./arazzo/criteria-unique.md) +- [sourceDescription-type](./arazzo/sourceDescriptions-type.md) +- [spot-supported-versions](./spot/spot-supported-versions.md) +- [workflowId-unique](./arazzo/workflowId-unique.md) +- [stepId-unique](./arazzo/stepId-unique.md) +- [sourceDescription-name-unique](./arazzo/sourceDescriptions-name-unique.md) +- [sourceDescriptions-not-empty](./arazzo/sourceDescriptions-not-empty.md) +- [workflow-dependsOn](./arazzo/workflow-dependsOn.md) +- [parameters-unique](./arazzo/parameters-unique.md) +- [step-onSuccess-unique](./arazzo/step-onSuccess-unique.md) +- [step-onFailure-unique](./arazzo/step-onFailure-unique.md) +- [requestBody-replacements-unique](./arazzo/requestBody-replacements-unique.md) +- [no-criteria-xpath](./spot/no-criteria-xpath.md) - [criteria-unique](./arazzo/criteria-unique.md) -- `parameters-not-in-body` -- `sourceDescription-type` -- `version-enum` -- `workflowId-unique` -- `stepId-unique` -- `sourceDescription-name-unique` -- `sourceDescriptions-not-empty` -- `workflow-dependsOn` -- `parameters-unique` -- `step-onSuccess-unique` -- `step-onFailure-unique` -- `requestBody-replacements-unique` -- `no-criteria-xpath` -- `criteria-unique` diff --git a/docs/rules/spot/parameters-not-in-body.md b/docs/rules/spot/parameters-not-in-body.md deleted file mode 100644 index 814f42157..000000000 --- a/docs/rules/spot/parameters-not-in-body.md +++ /dev/null @@ -1,58 +0,0 @@ -# parameters-not-in-body - -The `in` section inside `parameters` must not contain a `body`. - -| Arazzo | Compatibility | -| ------ | ------------- | -| 1.0.0 | ✅ | - -## API design principles - -This is rule is specific to the Spot tool. -`body` is not supported in the `in` section inside `parameters`. -This affects parameter lists in: - -- `workflows.[workflow].parameters` -- `workflows.[workflow[.steps.[step].parameters` -- `x-parameters` - -## Configuration - -| Option | Type | Description | -| -------- | ------ | ------------------------------------------------------- | -| severity | string | Possible values: `off`, `warn`, `error`. Default `off`. | - -An example configuration: - -```yaml -arazzoRules: - parameters-not-in-body: error -``` - -## Examples - -Given the following configuration: - -```yaml -arazzoRules: - parameters-not-in-body: error -``` - -Example of a **correct** list of `parameters`: - -```yaml Object example -workflows: - - workflowId: get-museum-hours - parameters: - - in: header - name: Authorization - value: Basic Og== -``` - -## Related rules - -- [version-enum](./version-enum.md) - -## Resources - -- [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/spot/parameters-not-in-body.ts) diff --git a/docs/rules/spot/version-enum.md b/docs/rules/spot/spot-supported-versions.md similarity index 81% rename from docs/rules/spot/version-enum.md rename to docs/rules/spot/spot-supported-versions.md index dce984fcc..e7670ace2 100644 --- a/docs/rules/spot/version-enum.md +++ b/docs/rules/spot/spot-supported-versions.md @@ -1,4 +1,4 @@ -# version-enum +# spot-supported-versions The `version` property must be one of the supported values. @@ -21,7 +21,7 @@ An example configuration: ```yaml arazzoRules: - version-enum: error + spot-supported-versions: error ``` ## Examples @@ -30,7 +30,7 @@ Given the following configuration: ```yaml arazzoRules: - version-enum: error + spot-supported-versions: error ``` Example of a **correct** entry: @@ -41,8 +41,8 @@ arazzo: 1.0.0 ## Related rules -- [parameters-not-in-body](./parameters-not-in-body.md) +- [no-criteria-xpath](./no-criteria-xpath.md) ## Resources -- [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/spot/version-enum.ts) +- [Rule source](https://github.com/Redocly/redocly-cli/blob/main/packages/core/src/rules/spot/spot-supported-versions.ts) diff --git a/docs/sidebars.yaml b/docs/sidebars.yaml index 5579681e6..24e09e0bd 100644 --- a/docs/sidebars.yaml +++ b/docs/sidebars.yaml @@ -139,8 +139,7 @@ - page: rules/async/no-channel-trailing-slash.md - separator: Arazzo - page: rules/spot/no-criteria-xpath.md - - page: rules/spot/version-enum.md - - page: rules/spot/parameters-not-in-body.md + - page: rules/spot/spot-supported-versions.md - page: rules/arazzo/criteria-unique.md - page: rules/arazzo/parameters-unique.md - page: rules/arazzo/requestBody-replacements-unique.md 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 6236055ff..4b3520216 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 @@ -6,17 +6,16 @@ exports[`resolveConfig should ignore minimal from the root and read local file 1 "arazzo1Preprocessors": {}, "arazzo1Rules": { "criteria-unique": "warn", - "no-criteria-xpath": "warn", - "parameters-not-in-body": "warn", + "no-criteria-xpath": "off", "parameters-unique": "error", "requestBody-replacements-unique": "warn", "sourceDescription-name-unique": "error", "sourceDescription-type": "error", "sourceDescriptions-not-empty": "error", + "spot-supported-versions": "off", "step-onFailure-unique": "warn", "step-onSuccess-unique": "warn", "stepId-unique": "error", - "version-enum": "warn", "workflow-dependsOn": "error", "workflowId-unique": "error", }, @@ -233,17 +232,16 @@ exports[`resolveStyleguideConfig should resolve extends with local file config w "arazzo1Preprocessors": {}, "arazzo1Rules": { "criteria-unique": "warn", - "no-criteria-xpath": "warn", - "parameters-not-in-body": "warn", + "no-criteria-xpath": "off", "parameters-unique": "error", "requestBody-replacements-unique": "warn", "sourceDescription-name-unique": "error", "sourceDescription-type": "error", "sourceDescriptions-not-empty": "error", + "spot-supported-versions": "off", "step-onFailure-unique": "warn", "step-onSuccess-unique": "warn", "stepId-unique": "error", - "version-enum": "warn", "workflow-dependsOn": "error", "workflowId-unique": "error", }, diff --git a/packages/core/src/config/all.ts b/packages/core/src/config/all.ts index 70d884617..dcc1a016d 100644 --- a/packages/core/src/config/all.ts +++ b/packages/core/src/config/all.ts @@ -210,8 +210,7 @@ const all: PluginStyleguideConfig<'built-in'> = { }, arazzo1Rules: { 'criteria-unique': 'error', - 'no-criteria-xpath': 'error', - 'parameters-not-in-body': 'error', + 'no-criteria-xpath': 'off', 'parameters-unique': 'error', 'requestBody-replacements-unique': 'error', 'sourceDescription-type': 'error', @@ -220,7 +219,7 @@ const all: PluginStyleguideConfig<'built-in'> = { 'stepId-unique': 'error', 'sourceDescription-name-unique': 'error', 'sourceDescriptions-not-empty': 'error', - 'version-enum': 'error', + 'spot-supported-versions': 'off', 'workflowId-unique': 'error', 'workflow-dependsOn': 'error', }, diff --git a/packages/core/src/config/minimal.ts b/packages/core/src/config/minimal.ts index 04c9a0414..47e097549 100644 --- a/packages/core/src/config/minimal.ts +++ b/packages/core/src/config/minimal.ts @@ -187,7 +187,6 @@ const minimal: PluginStyleguideConfig<'built-in'> = { arazzo1Rules: { 'criteria-unique': 'off', 'no-criteria-xpath': 'off', - 'parameters-not-in-body': 'off', 'parameters-unique': 'off', 'requestBody-replacements-unique': 'off', 'sourceDescription-type': 'off', @@ -196,7 +195,7 @@ const minimal: PluginStyleguideConfig<'built-in'> = { 'step-onFailure-unique': 'off', 'stepId-unique': 'error', 'sourceDescription-name-unique': 'off', - 'version-enum': 'off', + 'spot-supported-versions': 'off', 'workflowId-unique': 'error', 'workflow-dependsOn': 'off', }, diff --git a/packages/core/src/config/recommended-strict.ts b/packages/core/src/config/recommended-strict.ts index 6627ebaf8..cc20c1dcb 100644 --- a/packages/core/src/config/recommended-strict.ts +++ b/packages/core/src/config/recommended-strict.ts @@ -186,8 +186,7 @@ const recommendedStrict: PluginStyleguideConfig<'built-in'> = { }, arazzo1Rules: { 'criteria-unique': 'error', - 'no-criteria-xpath': 'error', - 'parameters-not-in-body': 'error', + 'no-criteria-xpath': 'off', 'parameters-unique': 'error', 'requestBody-replacements-unique': 'error', 'sourceDescription-type': 'error', @@ -196,7 +195,7 @@ const recommendedStrict: PluginStyleguideConfig<'built-in'> = { 'stepId-unique': 'error', 'sourceDescription-name-unique': 'error', 'sourceDescriptions-not-empty': 'error', - 'version-enum': 'error', + 'spot-supported-versions': 'off', 'workflowId-unique': 'error', 'workflow-dependsOn': 'error', }, diff --git a/packages/core/src/config/recommended.ts b/packages/core/src/config/recommended.ts index 6a27fad79..fa1e1f9cf 100644 --- a/packages/core/src/config/recommended.ts +++ b/packages/core/src/config/recommended.ts @@ -186,8 +186,7 @@ const recommended: PluginStyleguideConfig<'built-in'> = { }, arazzo1Rules: { 'criteria-unique': 'warn', - 'no-criteria-xpath': 'warn', - 'parameters-not-in-body': 'warn', + 'no-criteria-xpath': 'off', 'parameters-unique': 'error', 'requestBody-replacements-unique': 'warn', 'sourceDescription-type': 'error', @@ -196,7 +195,7 @@ const recommended: PluginStyleguideConfig<'built-in'> = { 'stepId-unique': 'error', 'sourceDescription-name-unique': 'error', 'sourceDescriptions-not-empty': 'error', - 'version-enum': 'warn', + 'spot-supported-versions': 'off', 'workflowId-unique': 'error', 'workflow-dependsOn': 'error', }, diff --git a/packages/core/src/config/spec.ts b/packages/core/src/config/spec.ts index 2374e2a08..273bfb869 100644 --- a/packages/core/src/config/spec.ts +++ b/packages/core/src/config/spec.ts @@ -11,9 +11,8 @@ const spec: PluginStyleguideConfig<'built-in'> = { async2Rules: {}, async3Rules: {}, arazzo1Rules: { - 'parameters-not-in-body': 'error', 'sourceDescription-type': 'error', - 'version-enum': 'error', + 'spot-supported-versions': 'off', 'workflowId-unique': 'error', 'stepId-unique': 'error', 'sourceDescription-name-unique': 'error', @@ -23,7 +22,7 @@ const spec: PluginStyleguideConfig<'built-in'> = { 'step-onSuccess-unique': 'error', 'step-onFailure-unique': 'error', 'requestBody-replacements-unique': 'error', - 'no-criteria-xpath': 'error', + 'no-criteria-xpath': 'off', 'criteria-unique': 'error', }, }; diff --git a/packages/core/src/rules/arazzo/__tests__/parameters-not-in-body.test.ts b/packages/core/src/rules/arazzo/__tests__/parameters-not-in-body.test.ts deleted file mode 100644 index 177baf9a3..000000000 --- a/packages/core/src/rules/arazzo/__tests__/parameters-not-in-body.test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { outdent } from 'outdent'; -import { lintDocument } from '../../../lint'; -import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils'; -import { BaseResolver } from '../../../resolve'; - -describe('Spot parameters-not-in-body', () => { - const document = parseYamlToDocument( - outdent` - arazzo: '1.0.0' - info: - title: Cool API - version: 1.0.0 - description: A cool API - sourceDescriptions: - - name: museum-api - type: openapi - url: openapi.yaml - workflows: - - workflowId: get-museum-hours - description: This workflow demonstrates how to get the museum opening hours and buy tickets. - parameters: - - in: body - name: Authorization - value: Basic Og== - steps: - - stepId: get-museum-hours - description: >- - Get museum hours by resolving request details with getMuseumHours operationId from openapi.yaml description. - operationId: museum-api.getMuseumHours - successCriteria: - - condition: $statusCode == 200 - `, - 'arazzo.yaml' - ); - - it('should not report on `body` inside parameter `in` field', async () => { - const results = await lintDocument({ - externalRefResolver: new BaseResolver(), - document, - config: await makeConfig({ rules: {} }), - }); - - expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`[]`); - }); - - it('should report on `body` inside parameter `in` field', async () => { - const results = await lintDocument({ - externalRefResolver: new BaseResolver(), - document, - config: await makeConfig({ - rules: { 'parameters-not-in-body': 'error' }, - }), - }); - - expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(` - [ - { - "location": [ - { - "pointer": "#/workflows/0/parameters/0/in", - "reportOnKey": false, - "source": "arazzo.yaml", - }, - ], - "message": "The \`body\` value of the \`in\` property is not supported by Spot.", - "ruleId": "parameters-not-in-body", - "severity": "error", - "suggest": [], - }, - ] - `); - }); -}); diff --git a/packages/core/src/rules/arazzo/__tests__/version-enum.test.ts b/packages/core/src/rules/arazzo/__tests__/spot-supported-versions.test.ts similarity index 93% rename from packages/core/src/rules/arazzo/__tests__/version-enum.test.ts rename to packages/core/src/rules/arazzo/__tests__/spot-supported-versions.test.ts index d45562b48..ba7bbaaa9 100644 --- a/packages/core/src/rules/arazzo/__tests__/version-enum.test.ts +++ b/packages/core/src/rules/arazzo/__tests__/spot-supported-versions.test.ts @@ -3,7 +3,7 @@ import { lintDocument } from '../../../lint'; import { parseYamlToDocument, replaceSourceWithRef, makeConfig } from '../../../../__tests__/utils'; import { BaseResolver } from '../../../resolve'; -describe('Arazzo version-enum', () => { +describe('Arazzo spot-supported-versions', () => { const document = parseYamlToDocument( outdent` arazzo: '1.0.1' @@ -38,7 +38,7 @@ describe('Arazzo version-enum', () => { externalRefResolver: new BaseResolver(), document, config: await makeConfig({ - rules: { 'version-enum': 'error' }, + rules: { 'spot-supported-versions': 'error' }, }), }); @@ -53,7 +53,7 @@ describe('Arazzo version-enum', () => { }, ], "message": "Only 1.0.0 Arazzo version is supported by Spot.", - "ruleId": "version-enum", + "ruleId": "spot-supported-versions", "severity": "error", "suggest": [], }, diff --git a/packages/core/src/rules/arazzo/index.ts b/packages/core/src/rules/arazzo/index.ts index 8e546f360..e78e0e02a 100644 --- a/packages/core/src/rules/arazzo/index.ts +++ b/packages/core/src/rules/arazzo/index.ts @@ -1,9 +1,8 @@ import { Struct } from '../common/struct'; import { Assertions } from '../common/assertions'; -import { ParametersNotInBody } from '../spot/parameters-not-in-body'; import { SourceDescriptionType } from '../arazzo/sourceDescription-type'; import { SourceDescriptionsNotEmpty } from './sourceDescriptions-not-empty'; -import { VersionEnum } from '../spot/version-enum'; +import { SpotSupportedVersions } from '../spot/spot-supported-versions'; import { WorkflowIdUnique } from './workflowId-unique'; import { StepIdUnique } from './stepId-unique'; import { SourceDescriptionsNameUnique } from './sourceDescriptions-name-unique'; @@ -21,9 +20,8 @@ import type { Arazzo1RuleSet } from '../../oas-types'; export const rules: Arazzo1RuleSet<'built-in'> = { struct: Struct as Arazzo1Rule, assertions: Assertions as Arazzo1Rule, - 'parameters-not-in-body': ParametersNotInBody, 'sourceDescription-type': SourceDescriptionType, - 'version-enum': VersionEnum, + 'spot-supported-versions': SpotSupportedVersions, 'workflowId-unique': WorkflowIdUnique, 'stepId-unique': StepIdUnique, 'sourceDescription-name-unique': SourceDescriptionsNameUnique, diff --git a/packages/core/src/rules/spot/parameters-not-in-body.ts b/packages/core/src/rules/spot/parameters-not-in-body.ts deleted file mode 100644 index 4b4ef3e43..000000000 --- a/packages/core/src/rules/spot/parameters-not-in-body.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { Arazzo1Rule } from '../../visitors'; -import type { UserContext } from '../../walk'; - -export const ParametersNotInBody: Arazzo1Rule = () => { - return { - Parameter: { - enter(parameter, { report, location }: UserContext) { - if (parameter.in === 'body') { - report({ - message: 'The `body` value of the `in` property is not supported by Spot.', - location: location.child(['in']), - }); - } - }, - }, - }; -}; diff --git a/packages/core/src/rules/spot/version-enum.ts b/packages/core/src/rules/spot/spot-supported-versions.ts similarity index 92% rename from packages/core/src/rules/spot/version-enum.ts rename to packages/core/src/rules/spot/spot-supported-versions.ts index c19e099e1..117f7b82d 100644 --- a/packages/core/src/rules/spot/version-enum.ts +++ b/packages/core/src/rules/spot/spot-supported-versions.ts @@ -4,7 +4,7 @@ import { pluralize } from '../../utils'; import type { Arazzo1Rule } from '../../visitors'; import type { UserContext } from '../../walk'; -export const VersionEnum: Arazzo1Rule = () => { +export const SpotSupportedVersions: Arazzo1Rule = () => { const supportedVersions = ARAZZO_VERSIONS_SUPPORTED_BY_SPOT.join(', '); return { Root: { diff --git a/packages/core/src/types/redocly-yaml.ts b/packages/core/src/types/redocly-yaml.ts index 356357c75..5d7994afc 100644 --- a/packages/core/src/types/redocly-yaml.ts +++ b/packages/core/src/types/redocly-yaml.ts @@ -141,9 +141,7 @@ export type BuiltInAsync2RuleId = typeof builtInAsync2Rules[number]; export type BuiltInAsync3RuleId = typeof builtInAsync3Rules[number]; const builtInArazzo1Rules = [ - 'parameters-not-in-body', 'sourceDescription-type', - 'version-enum', 'workflowId-unique', 'stepId-unique', 'sourceDescription-name-unique', @@ -152,6 +150,7 @@ const builtInArazzo1Rules = [ 'parameters-unique', 'step-onSuccess-unique', 'step-onFailure-unique', + 'spot-supported-versions', 'requestBody-replacements-unique', 'no-criteria-xpath', 'criteria-unique',