Repository: Redocly/redocly-cli
Pull request #841 (2022-08-31 08:32:21)

Upcase "4XX" in error message of operation-4xx-response
## What/Why/How?

This changes the error message of `operation-4xx-response` to say "4XX" (upcase) instead of "4xx" (downcase). This is good, because it helps people to write their API description as defined in the standard. 

See also https://github.com/Redocly/redocly-cli/issues/840.

This also does the same for operation-2xx-response

## Reference
Solves https://github.com/Redocly/redocly-cli/issues/840

## Testing
✅ 

## Check yourself

- [x] Code is linted
- [ ] Tested with redoc/reference-docs/workflows
- [x] All new/updated code is covered with tests

## Security

This change is not security relevant


adamaltman: Thank you @ahx! 🎉 

@tatomyr can we include this in the next release?

Patch:
diff --git a/packages/core/src/rules/common/operation-2xx-response.ts b/packages/core/src/rules/common/operation-2xx-response.ts
index 62844e71..6f898d74 100644
--- a/packages/core/src/rules/common/operation-2xx-response.ts
+++ b/packages/core/src/rules/common/operation-2xx-response.ts
@@ -7,7 +7,7 @@ export const Operation2xxResponse: Oas3Rule | Oas2Rule = () => {
       const codes = Object.keys(responses);
       if (!codes.some((code) => code === 'default' || /2[Xx0-9]{2}/.test(code))) {
         report({
-          message: 'Operation must have at least one `2xx` response.',
+          message: 'Operation must have at least one `2XX` response.',
           location: { reportOnKey: true },
         });
       }
diff --git a/packages/core/src/rules/common/operation-4xx-response.ts b/packages/core/src/rules/common/operation-4xx-response.ts
index c03877da..e3022b21 100644
--- a/packages/core/src/rules/common/operation-4xx-response.ts
+++ b/packages/core/src/rules/common/operation-4xx-response.ts
@@ -8,7 +8,7 @@ export const Operation4xxResponse: Oas3Rule | Oas2Rule = () => {
 
       if (!codes.some((code) => /4[Xx0-9]{2}/.test(code))) {
         report({
-          message: 'Operation must have at least one `4xx` response.',
+          message: 'Operation must have at least one `4XX` response.',
           location: { reportOnKey: true },
         });
       }


Test patch:
diff --git a/__tests__/lint/deprecated-lint/snapshot.js b/__tests__/lint/deprecated-lint/snapshot.js
index 0e56c6d6..67edbfea 100644
--- a/__tests__/lint/deprecated-lint/snapshot.js
+++ b/__tests__/lint/deprecated-lint/snapshot.js
@@ -6,7 +6,7 @@ The lint field is deprecated. Use styleguide instead. Read more about this chang
 validating /openapi.yaml...
 [1] openapi.yaml:11:7 at #/paths/~1pet~1findByStatus/get/responses
 
-Operation must have at least one \`4xx\` response.
+Operation must have at least one \`4XX\` response.
 
  9 | operationId: example
 10 | summary: summary example
diff --git a/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js b/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js
index f2a6d80d..c555ec66 100644
--- a/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js
+++ b/__tests__/lint/no-undefined-server-variable-error-recommended-config/snapshot.js
@@ -33,7 +33,7 @@ Warning was generated by the info-license rule.
 
 [3] openapi.yaml:14:7 at #/paths/~1pet~1findByStatus/get/responses
 
-Operation must have at least one \`4xx\` response.
+Operation must have at least one \`4XX\` response.
 
 12 | operationId: example
 13 | summary: summary example
diff --git a/__tests__/lint/operation-2xx-response-warning/snapshot.js b/__tests__/lint/operation-2xx-response-warning/snapshot.js
index fffc21f5..a3131b37 100644
--- a/__tests__/lint/operation-2xx-response-warning/snapshot.js
+++ b/__tests__/lint/operation-2xx-response-warning/snapshot.js
@@ -5,7 +5,7 @@ exports[`E2E lint operation-2xx-response-warning 1`] = `
 validating /openapi.yaml...
 [1] openapi.yaml:11:7 at #/paths/~1ping/get/responses
 
-Operation must have at least one \`2xx\` response.
+Operation must have at least one \`2XX\` response.
 
  9 | operationId: gitPing
 10 | summary: example text
diff --git a/__tests__/lint/operation-4xx-response-warning/snapshot.js b/__tests__/lint/operation-4xx-response-warning/snapshot.js
index 20c995e1..6d0cae49 100644
--- a/__tests__/lint/operation-4xx-response-warning/snapshot.js
+++ b/__tests__/lint/operation-4xx-response-warning/snapshot.js
@@ -5,7 +5,7 @@ exports[`E2E lint operation-4xx-response-warning 1`] = `
 validating /openapi.yaml...
 [1] openapi.yaml:11:7 at #/paths/~1ping/get/responses
 
-Operation must have at least one \`4xx\` response.
+Operation must have at least one \`4XX\` response.
 
  9 | operationId: gitPing
 10 | summary: example text
diff --git a/__tests__/lint/turn-on-all-rules/snapshot.js b/__tests__/lint/turn-on-all-rules/snapshot.js
index 4f1255f6..ec60ddf3 100644
--- a/__tests__/lint/turn-on-all-rules/snapshot.js
+++ b/__tests__/lint/turn-on-all-rules/snapshot.js
@@ -112,7 +112,7 @@ Error was generated by the path-parameters-defined rule.
 
 [9] openapi.yaml:16:7 at #/paths/~1ping~1{id}~1{test}/get/responses
 
-Operation must have at least one \`4xx\` response.
+Operation must have at least one \`4XX\` response.
 
 14 |     schema:
 15 |       type: string
diff --git a/packages/core/src/rules/common/__tests__/operation-2xx-response.test.ts b/packages/core/src/rules/common/__tests__/operation-2xx-response.test.ts
index e26775b7..0328717a 100644
--- a/packages/core/src/rules/common/__tests__/operation-2xx-response.test.ts
+++ b/packages/core/src/rules/common/__tests__/operation-2xx-response.test.ts
@@ -34,7 +34,7 @@ describe('Oas3 operation-2xx-response', () => {
               "source": "foobar.yaml",
             },
           ],
-          "message": "Operation must have at least one \`2xx\` response.",
+          "message": "Operation must have at least one \`2XX\` response.",
           "ruleId": "operation-2xx-response",
           "severity": "error",
           "suggest": Array [],
diff --git a/packages/core/src/rules/common/__tests__/operation-4xx-response.test.ts b/packages/core/src/rules/common/__tests__/operation-4xx-response.test.ts
index 14626542..486d1610 100644
--- a/packages/core/src/rules/common/__tests__/operation-4xx-response.test.ts
+++ b/packages/core/src/rules/common/__tests__/operation-4xx-response.test.ts
@@ -34,7 +34,7 @@ describe('Oas3 operation-4xx-response', () => {
               "source": "foobar.yaml",
             },
           ],
-          "message": "Operation must have at least one \`4xx\` response.",
+          "message": "Operation must have at least one \`4XX\` response.",
           "ruleId": "operation-4xx-response",
           "severity": "error",
           "suggest": Array [],
@@ -43,7 +43,7 @@ describe('Oas3 operation-4xx-response', () => {
     `);
   });
 
-  it('should not report for present 4xx response', async () => {
+  it('should not report for present 400 response', async () => {
     const document = parseYamlToDocument(
       outdent`
           openapi: 3.0.0
@@ -66,6 +66,29 @@ describe('Oas3 operation-4xx-response', () => {
     expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
   });
 
+  it('should not report for present 4XX response', async () => {
+    const document = parseYamlToDocument(
+      outdent`
+          openapi: 3.0.0
+          paths:
+            '/test/':
+              put:
+                responses:
+                  4XX:
+                    description: error response
+        `,
+      'foobar.yaml'
+    );
+
+    const results = await lintDocument({
+      externalRefResolver: new BaseResolver(),
+      document,
+      config: await makeConfig({ 'operation-4xx-response': 'error' }),
+    });
+
+    expect(replaceSourceWithRef(results)).toMatchInlineSnapshot(`Array []`);
+  });
+
   it('should report if default is present but missing 4xx response', async () => {
     const document = parseYamlToDocument(
       outdent`
@@ -96,7 +119,7 @@ describe('Oas3 operation-4xx-response', () => {
               "source": "foobar.yaml",
             },
           ],
-          "message": "Operation must have at least one \`4xx\` response.",
+          "message": "Operation must have at least one \`4XX\` response.",
           "ruleId": "operation-4xx-response",
           "severity": "error",
           "suggest": Array [],