Skip to content

Commit 8c9707b

Browse files
author
Enda
authored
Improvements to rules (#7)
1 parent 5127b95 commit 8c9707b

File tree

5 files changed

+51
-201
lines changed

5 files changed

+51
-201
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
.env.test.local
1111
.env.production.local
1212

13+
# Editor settings
14+
.vscode
15+
1316
npm-debug.log*
1417
yarn-debug.log*
1518
yarn-error.log*

spectral/README.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rules:
1616

1717
The RHOAS ruleset extends the Spectral built-in "oas" ruleset (except `operation-tags`, `openapi-tags`). You can see the full list of rules from that ruleset [here](https://meta.stoplight.io/docs/spectral/docs/reference/openapi-rules.md)
1818

19-
### oas3minimum
19+
### rhoas-oas3minimum
2020

2121
OpenAPI schemas should be a minimum of v3.
2222

@@ -25,9 +25,10 @@ openapi: 3.0
2525
```
2626
2727
**Recommended**: Yes
28+
2829
**Severity**: warning
2930
30-
### servers-config
31+
### rhoas-servers-config
3132
3233
The `servers` OpenAPI object must be defined and must specify at minimum the following URLs:
3334

@@ -40,9 +41,10 @@ servers:
4041
```
4142

4243
**Recommended**: Yes
44+
4345
**Severity**: warning
4446

45-
### info-license-apache2.0:
47+
### rhoas-info-license-apache2.0:
4648

4749
The `info.license.name` field must be "Apache 2.0".
4850

@@ -55,7 +57,7 @@ info:
5557
**Recommended**: Yes
5658
**Severity**: warning
5759

58-
### info-license-apache2.0-url:
60+
### rhoas-info-license-apache2.0-url:
5961

6062
The `info.license.url` field must have the correct link for Apache 2.0.
6163

@@ -66,11 +68,12 @@ info:
6668
```
6769

6870
**Recommended**: Yes
71+
6972
**Severity**: warning
7073

71-
### invalid-path-regexp
74+
### rhoas-path-regexp
7275

73-
All paths must match the specified regular expression: `/api/([a-z_]*){1,}(/v[0-9]*(alpha|beta)?)(/{?[a-z_]*}?){1,}$"`.
76+
All paths must match the specified regular expression: `\/api\/([a-z_]*){1,}(\/v[0-9]*(alpha|beta)?)(\/{?[a-z_]*}?){0,}$`.
7477

7578
- The first segment must be `/api`
7679
- The second segment can only contain alphabetical characters and underscores "_"
@@ -80,21 +83,23 @@ All paths must match the specified regular expression: `/api/([a-z_]*){1,}(/v[0-
8083
**Recommended**: Yes
8184
**Severity**: warning
8285

83-
### invalid-response-media-type
86+
### rhoas-response-media-type
8487

8588
The content type for all responses must be `application/json`.
8689

8790
**Recommended**: Yes
91+
8892
**Severity**: error
8993

90-
### invalid-error-response-object
94+
### rhoas-error-response
9195

9296
All error response bodies must reference `#/components/Schemas/Error`
9397

9498
**Recommended**: Yes
99+
95100
**Severity**: error
96101

97-
### invalid-object-resource-schema
102+
### rhoas-object-resource-schema
98103

99104
All API response bodies must be an `object` with three required properties:
100105

@@ -111,22 +116,25 @@ properties:
111116
```
112117

113118
**Recommended**: Yes
119+
114120
**Severity**: error
115121

116-
### schema-name-camel-case
122+
### rhoas-schema-name-camel-case
117123

118124
All JSON schema objects defined in `components.schemas` must follow `CamelCase`.
119125

120126
**Recommended**: Yes
127+
121128
**Severity**: warning
122-
### properties-snake-case
129+
### rhoas-schema-properties-snake-case
123130

124131
All JSON schema properties defined must follow `camel_case`.
125132

126133
**Recommended**: Yes
134+
127135
**Severity**: error
128136

129-
### invalid-error-schema
137+
### rhoas-error-schema
130138

131139
`components.schema` MUST have a valid `Error` object.
132140

@@ -148,9 +156,10 @@ Error:
148156
```
149157

150158
**Recommended**: Yes
159+
151160
**Severity**: warning
152161

153-
### invalid-object-schema
162+
### rhoas-object-schema
154163

155164
`components.schema` MUST have a valid `ObjectReference` object.
156165

@@ -168,9 +177,10 @@ ObjectReference:
168177
```
169178

170179
**Recommended**: Yes
180+
171181
**Severity**: warning
172182

173-
### invalid-list-schema
183+
### rhoas-list-schema
174184

175185
`components.schema` MUST have a valid `List` object.
176186

@@ -197,6 +207,7 @@ List:
197207
```
198208

199209
**Recommended**: Yes
210+
200211
**Severity**: warning
201212

202213
## Development
@@ -217,8 +228,9 @@ yarn build
217228

218229
**Running examples**
219230

220-
Validate OpenAPI files using the uncompiled TypeScript CLI:
231+
Validate OpenAPI files using the uncompiled ruleset:
221232

222233
```shell
223-
yarn validate-dev ./examples/openapi-valid.yaml
234+
yarn build
235+
yarn spectral-lint ./examples/openapi-valid.yaml
224236
```

spectral/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
"lint": "eslint src/**/*.ts",
1111
"publish": "npm publish dist",
1212
"copy-ruleset": "cp ./ruleset.yaml ./dist/ruleset.yaml && cp ./package.json ./dist/package.json",
13-
"spectral-lint:local": "spectral lint --ruleset ./examples/.spectral-local.yaml",
14-
"spectral-lint": "spectral lint --ruleset ./examples/.spectral.yaml"
13+
"spectral-lint": "spectral lint --ruleset ./examples/.spectral-local.yaml"
1514
},
1615
"dependencies": {
1716
"@stoplight/spectral": "^5.3.0"
@@ -34,7 +33,7 @@
3433
},
3534
"keywords": [
3635
"openapi",
37-
"spectral",
36+
"spectral",
3837
"validator",
3938
"rhoas",
4039
"app-services-sdk"

spectral/ruleset.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rules:
99
openapi-tags: off
1010
operation-tags: off
1111

12-
oas3minimum:
12+
rhoas-oas3minimum:
1313
given: "$"
1414
description: OpenAPI version must be >= 3
1515
recommended: true
@@ -19,7 +19,7 @@ rules:
1919
function: pattern
2020
functionOptions:
2121
match: 3.[0-9]?.[0-9]
22-
servers-config:
22+
rhoas-servers-config:
2323
given: "$"
2424
severity: warn
2525
recommended: true
@@ -32,14 +32,14 @@ rules:
3232
- https://api.stage.openshift.com
3333
- http://localhost:8000
3434
- "/"
35-
info-license-apache2.0:
35+
rhoas-info-license-apache2.0:
3636
severity: warn
3737
recommended: true
3838
given: "$"
3939
then:
4040
function: infoLicenseApache2
4141
field: info.license
42-
invalid-path-regexp:
42+
rhoas-path-regexp:
4343
given: "$.paths[*]~"
4444
severity: warn
4545
description:
@@ -48,15 +48,15 @@ rules:
4848
then:
4949
function: pattern
5050
functionOptions:
51-
match: "/api/([a-z_]*){1,}(/v[0-9]*(alpha|beta)?)(/{?[a-z_]*}?){1,}$"
52-
invalid-response-media-type:
51+
match: "\/api\/([a-z_]*){1,}(\/v[0-9]*(alpha|beta)?)(\/{?[a-z_]*}?){0,}$"
52+
rhoas-response-media-type:
5353
given: "$.paths.*.*.responses.*.content"
5454
description: application/json is the only acceptable content type
5555
severity: error
5656
then:
5757
function: truthy
5858
field: application/json
59-
invalid-error-response-object:
59+
rhoas-error-response:
6060
given: "$.paths..responses[?( @property >= 300)].content.*"
6161
severity: error
6262
then:
@@ -65,7 +65,7 @@ rules:
6565
functionOptions:
6666
schema:
6767
"$ref": "#/components/schemas/Error"
68-
invalid-object-resource-schema:
68+
rhoas-object-resource-schema:
6969
given: "$.paths..responses[?( @property < 300)].content.*"
7070
severity: error
7171
then:
@@ -74,7 +74,7 @@ rules:
7474
functionOptions:
7575
schema:
7676
"$ref": "#/components/schemas/ObjectReference"
77-
schema-name-camel-case:
77+
rhoas-schema-name-camel-case:
7878
description: JSON Schema names should use CamelCase
7979
message: "`{{property}}` object name must follow CamelCase"
8080
severity: error
@@ -83,7 +83,7 @@ rules:
8383
function: pattern
8484
functionOptions:
8585
match: "^([A-Z]{1}[a-z]{1,}){1,}$"
86-
properties-snake-case:
86+
rhoas-schema-properties-snake-case:
8787
description:
8888
All JSON Schema properties MUST follow snake_case and be ASCII alphanumeric
8989
characters.
@@ -95,7 +95,7 @@ rules:
9595
function: pattern
9696
functionOptions:
9797
match: "/^[a-z0-9_]{1,}/"
98-
invalid-error-schema:
98+
rhoas-error-schema:
9999
severity: error
100100
recommended: true
101101
given: "$.components.schemas"
@@ -118,7 +118,7 @@ rules:
118118
reason:
119119
type: string
120120
required: true
121-
invalid-object-schema:
121+
rhoas-object-schema:
122122
severity: error
123123
recommended: true
124124
given: "$.components.schemas"
@@ -138,7 +138,7 @@ rules:
138138
href:
139139
type: string
140140
required: true
141-
invalid-list-schema:
141+
rhoas-list-schema:
142142
severity: error
143143
recommended: true
144144
given: "$.components.schemas"
@@ -163,4 +163,4 @@ rules:
163163
required: true
164164
total:
165165
type: integer
166-
required: true
166+
required: true

0 commit comments

Comments
 (0)