Repository: Redocly/redocly-cli
Pull request #1119 (2023-06-02 08:41:48)

fix: rename spec-ref-validation to spec-strict-refs
## What/Why/How?

Rename `spec-ref-validation` to `spec-strict-refs`

## Reference

## Testing

## Screenshots (optional)

## Check yourself

- [x] Code is linted
- [ ] Tested with redoc/reference-docs/workflows
- [x] All new/updated code is covered with tests

## Security

- [x] Security impact of change has been considered
- [x] Code follows company security practices and guidelines


github-actions[bot]: | Command | Mean [s] | Min [s] | Max [s] | Relative |
|:---|---:|---:|---:|---:|
| `redocly lint packages/core/src/benchmark/benches/rebilly.yaml` | 1.263 ± 0.028 | 1.211 | 1.310 | 1.00 |
| `redocly-next lint packages/core/src/benchmark/benches/rebilly.yaml` | 1.289 ± 0.036 | 1.232 | 1.336 | 1.02 ± 0.04 |

<!-- thollander/actions-comment-pull-request "hyperfine-comparison" -->
RomanHotsiy: The PR title and description is invalid. In code it `spec-strict-refs` but in descriptions its `spec-restrict-refs`.
github-actions[bot]: <!-- jest coverage report action for options with hash 3339ae53a38c44382c0fb4491bdb282d -->

## Coverage report 



| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | Category   | Percentage | Covered / Total |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------- | :--------- | :-------------: |
|                                                                           🟡                                                                           | Statements | 73.3%      |    3519/4801    |
|                                                                           🟡                                                                           | Branches   | 64.95%     |    2007/3090    |
|                                                                           🟡                                                                           | Functions  | 65.74%     |     591/899     |
|                                                                           🟡                                                                           | Lines      | 73.35%     |    3275/4465    |

<details><summary>Show new covered files 🐣</summary>
<br/>

| <div title="Status of coverage:&#10; 🟢 - ok&#10; 🟡 - slightly more than threshold&#10; 🔴 - under the threshold">St.<sup>:grey_question:</sup></div> | File                                                                                     | Statements | Branches | Functions | Lines |
| :----------------------------------------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------- | :--------- | :------- | :-------- | :---- |
|                                                                           🟢                                                                           | <div title="core/src/rules/common/spec-strict-refs.ts">`...` / spec-strict-refs.ts</div> | 100%       | 100%     | 100%      | 100%  |

</details>


## Test suite run success
588 tests passing in 86 suites.

<p align="right">Report generated by <a href="https://github.com/ArtiomTr/jest-coverage-report-action">🧪jest coverage report action</a> from 497eb6dade432db745f3db127c7d0797cca209ea</p>

IgorKarpiuk: > The PR title and description is invalid. In code it `spec-strict-refs` but in descriptions its `spec-restrict-refs`.

Fixed, Thank you
lornajane: It works for me. Thanks!

Patch:
diff --git a/packages/core/src/rules/common/spec-ref-validation.ts b/packages/core/src/rules/common/spec-strict-refs.ts
similarity index 90%
rename from packages/core/src/rules/common/spec-ref-validation.ts
rename to packages/core/src/rules/common/spec-strict-refs.ts
index af3bc9f8..e1d52261 100644
--- a/packages/core/src/rules/common/spec-ref-validation.ts
+++ b/packages/core/src/rules/common/spec-strict-refs.ts
@@ -1,7 +1,7 @@
 import { Oas2Rule, Oas3Rule } from '../../visitors';
 import { isRef } from '../../ref-utils';
 
-export const SpecRefValidation: Oas3Rule | Oas2Rule = () => {
+export const SpecStrictRefs: Oas3Rule | Oas2Rule = () => {
   const nodesToSkip = [
     'Schema',
     'Response',
diff --git a/packages/core/src/rules/oas2/index.ts b/packages/core/src/rules/oas2/index.ts
index b6cf8dbc..43ef2ab6 100644
--- a/packages/core/src/rules/oas2/index.ts
+++ b/packages/core/src/rules/oas2/index.ts
@@ -40,7 +40,7 @@ import { ResponseContainsHeader } from '../common/response-contains-header';
 import { ResponseContainsProperty } from './response-contains-property';
 import { ScalarPropertyMissingExample } from '../common/scalar-property-missing-example';
 import { RequiredStringPropertyMissingMinLength } from '../common/required-string-property-missing-min-length';
-import { SpecRefValidation } from '../common/spec-ref-validation';
+import { SpecStrictRefs } from '../common/spec-strict-refs';
 
 export const rules = {
   spec: OasSpec as Oas2Rule,
@@ -85,7 +85,7 @@ export const rules = {
   'response-contains-property': ResponseContainsProperty as Oas2Rule,
   'scalar-property-missing-example': ScalarPropertyMissingExample,
   'required-string-property-missing-min-length': RequiredStringPropertyMissingMinLength,
-  'spec-ref-validation': SpecRefValidation,
+  'spec-strict-refs': SpecStrictRefs,
 };
 
 export const preprocessors = {};
diff --git a/packages/core/src/rules/oas3/index.ts b/packages/core/src/rules/oas3/index.ts
index c9897667..49d77628 100644
--- a/packages/core/src/rules/oas3/index.ts
+++ b/packages/core/src/rules/oas3/index.ts
@@ -50,7 +50,7 @@ import { ScalarPropertyMissingExample } from '../common/scalar-property-missing-
 import { SpecComponentsInvalidMapName } from './spec-components-invalid-map-name';
 import { Operation4xxProblemDetailsRfc7807 } from './operation-4xx-problem-details-rfc7807';
 import { RequiredStringPropertyMissingMinLength } from '../common/required-string-property-missing-min-length';
-import { SpecRefValidation } from '../common/spec-ref-validation';
+import { SpecStrictRefs } from '../common/spec-strict-refs';
 
 export const rules = {
   spec: OasSpec,
@@ -105,7 +105,7 @@ export const rules = {
   'scalar-property-missing-example': ScalarPropertyMissingExample,
   'spec-components-invalid-map-name': SpecComponentsInvalidMapName,
   'required-string-property-missing-min-length': RequiredStringPropertyMissingMinLength,
-  'spec-ref-validation': SpecRefValidation,
+  'spec-strict-refs': SpecStrictRefs,
 } as Oas3RuleSet;
 
 export const preprocessors = {};
diff --git a/packages/core/src/types/redocly-yaml.ts b/packages/core/src/types/redocly-yaml.ts
index ddad57b9..31e003e5 100644
--- a/packages/core/src/types/redocly-yaml.ts
+++ b/packages/core/src/types/redocly-yaml.ts
@@ -54,7 +54,7 @@ const builtInRulesList = [
   'scalar-property-missing-example',
   'spec-components-invalid-map-name',
   'required-string-property-missing-min-length',
-  'spec-ref-validation',
+  'spec-strict-refs',
 ];
 const nodeTypesList = [
   'any',


Test patch:
diff --git a/__tests__/lint/spec-ref-validation/snapshot.js b/__tests__/lint/spec-ref-validation/snapshot.js
deleted file mode 100644
index af14460e..00000000
--- a/__tests__/lint/spec-ref-validation/snapshot.js
+++ /dev/null
@@ -1,40 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`E2E lint spec-ref-validation 1`] = `
-
-validating /openapi.yaml...
-[1] openapi.yaml:6:3 at #/info/$ref
-
-Field $ref is not expected here.
-
-4 |     description: Default server
-5 | info:
-6 |   $ref: './info.yaml'
-  |   ^^^^
-7 | paths:
-8 |   /pet:
-
-Error was generated by the spec-ref-validation rule.
-
-
-[2] openapi.yaml:20:19 at #/paths/~1pet/get/responses/200/content/application~1json/schema/properties/$ref
-
-Field $ref is not expected here.
-
-18 | type: object
-19 | properties:
-20 |   $ref: './props.yaml'
-   |   ^^^^
-21 |   name:
-22 |     type: string
-
-Error was generated by the spec-ref-validation rule.
-
-
-/openapi.yaml: validated in <test>ms
-
-❌ Validation failed with 2 errors.
-run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
-
-
-`;
diff --git a/__tests__/lint/spec-ref-validation/info.yaml b/__tests__/lint/spec-strict-refs/info.yaml
similarity index 100%
rename from __tests__/lint/spec-ref-validation/info.yaml
rename to __tests__/lint/spec-strict-refs/info.yaml
diff --git a/__tests__/lint/spec-ref-validation/openapi.yaml b/__tests__/lint/spec-strict-refs/openapi.yaml
similarity index 100%
rename from __tests__/lint/spec-ref-validation/openapi.yaml
rename to __tests__/lint/spec-strict-refs/openapi.yaml
diff --git a/__tests__/lint/spec-ref-validation/props.yaml b/__tests__/lint/spec-strict-refs/props.yaml
similarity index 100%
rename from __tests__/lint/spec-ref-validation/props.yaml
rename to __tests__/lint/spec-strict-refs/props.yaml
diff --git a/__tests__/lint/spec-ref-validation/redocly.yaml b/__tests__/lint/spec-strict-refs/redocly.yaml
similarity index 61%
rename from __tests__/lint/spec-ref-validation/redocly.yaml
rename to __tests__/lint/spec-strict-refs/redocly.yaml
index ebe4d374..96d12646 100644
--- a/__tests__/lint/spec-ref-validation/redocly.yaml
+++ b/__tests__/lint/spec-strict-refs/redocly.yaml
@@ -3,4 +3,4 @@ apis:
     root: ./openapi.yaml
 
 rules:
-  spec-ref-validation: error
+  spec-strict-refs: error
diff --git a/__tests__/lint/spec-strict-refs/snapshot.js b/__tests__/lint/spec-strict-refs/snapshot.js
new file mode 100644
index 00000000..21611529
--- /dev/null
+++ b/__tests__/lint/spec-strict-refs/snapshot.js
@@ -0,0 +1,79 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`E2E lint spec-ref-validation 1`] = `
+
+validating /openapi.yaml...
+[1] openapi.yaml:6:3 at #/info/$ref
+
+Field $ref is not expected here.
+
+4 |     description: Default server
+5 | info:
+6 |   $ref: './info.yaml'
+  |   ^^^^
+7 | paths:
+8 |   /pet:
+
+Error was generated by the spec-strict-refs rule.
+
+
+[2] openapi.yaml:20:19 at #/paths/~1pet/get/responses/200/content/application~1json/schema/properties/$ref
+
+Field $ref is not expected here.
+
+18 | type: object
+19 | properties:
+20 |   $ref: './props.yaml'
+   |   ^^^^
+21 |   name:
+22 |     type: string
+
+Error was generated by the spec-strict-refs rule.
+
+
+/openapi.yaml: validated in <test>ms
+
+❌ Validation failed with 2 errors.
+run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
+
+
+`;
+
+exports[`E2E lint spec-strict-refs 1`] = `
+
+validating /openapi.yaml...
+[1] openapi.yaml:6:3 at #/info/$ref
+
+Field $ref is not expected here.
+
+4 |     description: Default server
+5 | info:
+6 |   $ref: './info.yaml'
+  |   ^^^^
+7 | paths:
+8 |   /pet:
+
+Error was generated by the spec-strict-refs rule.
+
+
+[2] openapi.yaml:20:19 at #/paths/~1pet/get/responses/200/content/application~1json/schema/properties/$ref
+
+Field $ref is not expected here.
+
+18 | type: object
+19 | properties:
+20 |   $ref: './props.yaml'
+   |   ^^^^
+21 |   name:
+22 |     type: string
+
+Error was generated by the spec-strict-refs rule.
+
+
+/openapi.yaml: validated in <test>ms
+
+❌ Validation failed with 2 errors.
+run \`redocly lint --generate-ignore-file\` to add all problems to the ignore file.
+
+
+`;
diff --git a/packages/core/src/rules/common/__tests__/spec-ref-validation.test.ts b/packages/core/src/rules/common/__tests__/spec-strict-refs.test.ts
similarity index 90%
rename from packages/core/src/rules/common/__tests__/spec-ref-validation.test.ts
rename to packages/core/src/rules/common/__tests__/spec-strict-refs.test.ts
index 7b6d3c89..39c4379a 100644
--- a/packages/core/src/rules/common/__tests__/spec-ref-validation.test.ts
+++ b/packages/core/src/rules/common/__tests__/spec-strict-refs.test.ts
@@ -3,7 +3,7 @@ import { outdent } from 'outdent';
 import { lintDocument } from '../../../lint';
 import { BaseResolver } from '../../../resolve';
 
-describe('Oas3 spec-ref-validation', () => {
+describe('Oas3 spec-strict-refs', () => {
   it('should report about invalid usage of $ref', async () => {
     const document = parseYamlToDocument(
       outdent`
@@ -33,7 +33,7 @@ describe('Oas3 spec-ref-validation', () => {
     const results = await lintDocument({
       externalRefResolver: new BaseResolver(),
       document,
-      config: await makeConfig({ 'spec-ref-validation': 'error' }),
+      config: await makeConfig({ 'spec-strict-refs': 'error' }),
     });
     expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`
       Array [
@@ -46,7 +46,7 @@ describe('Oas3 spec-ref-validation', () => {
             },
           ],
           "message": "Field $ref is not expected here.",
-          "ruleId": "spec-ref-validation",
+          "ruleId": "spec-strict-refs",
           "severity": "error",
           "suggest": Array [],
         },
@@ -59,7 +59,7 @@ describe('Oas3 spec-ref-validation', () => {
             },
           ],
           "message": "Field $ref is not expected here.",
-          "ruleId": "spec-ref-validation",
+          "ruleId": "spec-strict-refs",
           "severity": "error",
           "suggest": Array [],
         },