Skip to content

Commit 6a1c5e1

Browse files
authored
Merge pull request #15 from istreamlabs/errors-details
Errors need to be problem+json not json
2 parents 6957fde + 171ebd3 commit 6a1c5e1

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

fixtures/lint/error-detail-pass.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
openapi: '3.0.0'
1+
openapi: "3.0.0"
22
info:
33
version: 1.0.0
44
title: API Fixture
@@ -21,12 +21,12 @@ paths:
2121
tags:
2222
- Test
2323
responses:
24-
'204':
24+
"204":
2525
description: Response description
26-
'401':
26+
"401":
2727
description: Response description
2828
content:
29-
application/json:
29+
application/problem+json:
3030
schema:
3131
type: object
3232
properties:

isp-rules.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
formats:
2-
- 'oas3'
2+
- "oas3"
33
extends: spectral:oas
44
functionsDir: isp-functions
55
functions:
@@ -17,15 +17,15 @@ rules:
1717
# Use JSON as much as possible
1818
json-responses:
1919
severity: error
20-
message: '{{description}}: {{error}}'
20+
message: "{{description}}: {{error}}"
2121
given: $..responses.[?(@property == '200' || @ == '201' || @ == '202' || @ == '400' || @ == '401' || @ == '403' || @ == '404' || @ == '422' || @ == '500')].content
2222
then:
2323
function: contains
2424
functionOptions:
25-
match: 'json'
25+
match: "json"
2626
patch-request-content-type:
2727
severity: error
28-
description: '`PATCH` requests cannot use `application/json`'
28+
description: "`PATCH` requests cannot use `application/json`"
2929
given: $.paths.*.[?(@property == 'patch')].requestBody.content[?(@property == 'application/json')]^
3030
then:
3131
function: falsy
@@ -47,7 +47,7 @@ rules:
4747
then:
4848
function: pattern
4949
functionOptions:
50-
match: 'localhost|/v[0-9]+$'
50+
match: "localhost|/v[0-9]+$"
5151
# Use ISO 8601 for dates
5252
iso8601:
5353
severity: warn
@@ -132,19 +132,19 @@ rules:
132132
description: Delete should return an HTTP 204
133133
given: $.paths.*[?(@property === 'delete')].responses
134134
then:
135-
field: '204'
135+
field: "204"
136136
function: truthy
137137
# Errors must include a `detail` field
138138
error-detail:
139139
severity: error
140-
description: Errors must be JSON and include a "detail" field
140+
description: Errors must be problem+JSON and include a "detail" field
141141
given: $..responses.[?(@property.toString().startsWith("4") || @property.toString() === "500")]
142142
then:
143143
- field: content
144144
function: truthy
145-
- field: content.application/json.schema
145+
- field: content.application/problem+json.schema
146146
function: truthy
147-
- field: content.application/json.schema.properties.detail
147+
- field: content.application/problem+json.schema.properties.detail
148148
function: truthy
149149
# Header & parameter casing
150150
headers-hyphenated-pascal-case:

0 commit comments

Comments
 (0)