From d1b2758cb67d08052eb3fb7c7a26b3b254a85457 Mon Sep 17 00:00:00 2001 From: He Qian Wang Date: Wed, 8 May 2024 13:43:58 -0400 Subject: [PATCH] [IDP-1402] Enforce application/json return only on 200 responses --- .spectral.yaml | 4 ++-- TestSpecs/must-return-content-types-valid.yaml | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.spectral.yaml b/.spectral.yaml index 8fb1c9f..9632ffa 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -30,10 +30,10 @@ rules: - application/octet-stream must-return-content-types: - description: "All endpoint bodies MUST return the header with (one of) Content-Type: application/json, image/png, application/octet-stream." + description: "Endpoint bodies for 200 responses MUST return the header with (one of) Content-Type: application/json, image/png, application/octet-stream." message: "{{description}}" severity: warn - given: $.paths[*].*.responses.*.content + given: $.paths[*].*.responses['200'].content then: field: "@key" function: enumeration diff --git a/TestSpecs/must-return-content-types-valid.yaml b/TestSpecs/must-return-content-types-valid.yaml index de9b14e..fd9a66e 100644 --- a/TestSpecs/must-return-content-types-valid.yaml +++ b/TestSpecs/must-return-content-types-valid.yaml @@ -23,4 +23,10 @@ paths: maxLength: 200 minLength: 1 type: string - additionalProperties: false \ No newline at end of file + additionalProperties: false + '400': + description: Bad request + content: + text/plain: + schema: + type: string \ No newline at end of file