@luxass/spectral-ruleset 0.0.4 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +70 -0
- package/dist/ruleset.cjs +32 -0
- package/dist/ruleset.js +32 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,6 +35,76 @@ You can also use it directly from unpkg:
|
|
|
35
35
|
echo 'extends: ["https://unpkg.com/@luxass/spectral-ruleset"]' > .spectral.yml
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
+
## Rules
|
|
39
|
+
|
|
40
|
+
This ruleset extends the official OpenAPI and AsyncAPI rulesets from `@stoplight/spectral-rulesets`, with some built-in rules modified (`operation-tags` and `operation-operationId` are disabled, `operation-success-response` is set to error level).
|
|
41
|
+
|
|
42
|
+
### Custom Rules
|
|
43
|
+
|
|
44
|
+
<details>
|
|
45
|
+
<summary><strong>General Rules</strong></summary>
|
|
46
|
+
|
|
47
|
+
##### `luxass/api-homepage` ⚠️
|
|
48
|
+
Ensures that APIs have a root path (`/`) defined. This helps with API discoverability and provides a clear entry point for consumers.
|
|
49
|
+
|
|
50
|
+
##### `luxass/api-homepage-get` ⚠️
|
|
51
|
+
Ensures that the API root path (`/`) has a GET operation defined. This allows consumers to discover what the API offers.
|
|
52
|
+
|
|
53
|
+
##### `luxass/version-in-info` ⚠️
|
|
54
|
+
Enforces semantic versioning format for the `info.version` field (e.g., `1.0.0`).
|
|
55
|
+
|
|
56
|
+
</details>
|
|
57
|
+
|
|
58
|
+
<details>
|
|
59
|
+
<summary><strong>Path Rules</strong></summary>
|
|
60
|
+
|
|
61
|
+
##### `luxass/paths-kebab-case` ⚠️
|
|
62
|
+
Enforces kebab-case naming convention for all API paths (e.g., `/user-profiles` instead of `/userProfiles`).
|
|
63
|
+
|
|
64
|
+
##### `luxass/no-file-extensions-in-paths` ❌
|
|
65
|
+
Prevents file extensions (`.json`, `.xml`, `.html`, `.txt`) in API paths. Use the `content` field to specify media types instead.
|
|
66
|
+
|
|
67
|
+
##### `luxass/no-trailing-slash` ⚠️
|
|
68
|
+
Prevents trailing slashes in paths (except for the root path `/`), avoiding confusion about resource identity.
|
|
69
|
+
|
|
70
|
+
##### `luxass/plural-resource-names` ⚠️
|
|
71
|
+
Encourages using plural nouns for resource collections (e.g., `/users` instead of `/user`).
|
|
72
|
+
|
|
73
|
+
</details>
|
|
74
|
+
|
|
75
|
+
<details>
|
|
76
|
+
<summary><strong>Header Rules</strong></summary>
|
|
77
|
+
|
|
78
|
+
##### `luxass/no-x-headers` ❌
|
|
79
|
+
Prevents usage of headers starting with `X-` prefix. Encourages using standardized headers instead of the deprecated X- convention.
|
|
80
|
+
|
|
81
|
+
##### `luxass/headers-hyphenated-pascal-case` ❌
|
|
82
|
+
Enforces `Hyphenated-Pascal-Case` notation for HTTP headers (e.g., `Content-Type`, `Accept-Language`).
|
|
83
|
+
|
|
84
|
+
</details>
|
|
85
|
+
|
|
86
|
+
<details>
|
|
87
|
+
<summary><strong>OpenAPI 2.0 Specific Rules</strong></summary>
|
|
88
|
+
|
|
89
|
+
##### `luxass/oas2/protocol-https-only` ❌
|
|
90
|
+
Ensures that only HTTPS protocol is used in the `schemes` array.
|
|
91
|
+
|
|
92
|
+
##### `luxass/oas2/get-request-no-body` ❌
|
|
93
|
+
Prevents GET requests from having request bodies, following HTTP best practices.
|
|
94
|
+
|
|
95
|
+
</details>
|
|
96
|
+
|
|
97
|
+
<details>
|
|
98
|
+
<summary><strong>OpenAPI 3.x Specific Rules</strong></summary>
|
|
99
|
+
|
|
100
|
+
##### `luxass/oas3/protocol-https-only` ❌
|
|
101
|
+
Ensures that all server URLs use HTTPS protocol only.
|
|
102
|
+
|
|
103
|
+
##### `luxass/oas3/get-request-no-body` ❌
|
|
104
|
+
Prevents GET requests from having `requestBody` defined, following HTTP best practices.
|
|
105
|
+
|
|
106
|
+
</details>
|
|
107
|
+
|
|
38
108
|
## 📄 License
|
|
39
109
|
|
|
40
110
|
Published under [MIT License](./LICENSE).
|
package/dist/ruleset.cjs
CHANGED
|
@@ -261,6 +261,38 @@ var ruleset_default = {
|
|
|
261
261
|
},
|
|
262
262
|
severity: DiagnosticSeverity.Error
|
|
263
263
|
},
|
|
264
|
+
"luxass/paths-kebab-case": {
|
|
265
|
+
description: "All YAML/JSON paths MUST follow kebab-case",
|
|
266
|
+
severity: DiagnosticSeverity.Warning,
|
|
267
|
+
recommended: true,
|
|
268
|
+
message: "{{property}} is not kebab-case: {{error}}",
|
|
269
|
+
given: "$.paths[*]~",
|
|
270
|
+
then: {
|
|
271
|
+
function: __stoplight_spectral_functions.pattern,
|
|
272
|
+
functionOptions: { match: "^/([a-z0-9]+(-[a-z0-9]+)*)?(/[a-z0-9]+(-[a-z0-9]+)*|/{.+})*$" }
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
"luxass/headers-hyphenated-pascal-case": {
|
|
276
|
+
description: "All `HTTP` headers MUST use `Hyphenated-Pascal-Case` notation",
|
|
277
|
+
severity: DiagnosticSeverity.Error,
|
|
278
|
+
recommended: true,
|
|
279
|
+
message: "{{property}} is not hyphenated-pascal-case: {{error}}",
|
|
280
|
+
given: "$..parameters[?(@.in == 'header')].name",
|
|
281
|
+
then: {
|
|
282
|
+
function: __stoplight_spectral_functions.pattern,
|
|
283
|
+
functionOptions: { match: "^[A-Z][a-z0-9]*(-[A-Z][a-z0-9]*)*$" }
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
"luxass/version-in-info": {
|
|
287
|
+
message: "API version should follow semantic versioning.",
|
|
288
|
+
description: "The info.version field should follow semantic versioning (e.g., 1.0.0).",
|
|
289
|
+
given: "$.info.version",
|
|
290
|
+
then: {
|
|
291
|
+
function: __stoplight_spectral_functions.pattern,
|
|
292
|
+
functionOptions: { match: "^\\d+\\.\\d+\\.\\d+" }
|
|
293
|
+
},
|
|
294
|
+
severity: DiagnosticSeverity.Warning
|
|
295
|
+
},
|
|
264
296
|
...oas2_default,
|
|
265
297
|
...oas3_default
|
|
266
298
|
}
|
package/dist/ruleset.js
CHANGED
|
@@ -237,6 +237,38 @@ var ruleset_default = {
|
|
|
237
237
|
},
|
|
238
238
|
severity: DiagnosticSeverity.Error
|
|
239
239
|
},
|
|
240
|
+
"luxass/paths-kebab-case": {
|
|
241
|
+
description: "All YAML/JSON paths MUST follow kebab-case",
|
|
242
|
+
severity: DiagnosticSeverity.Warning,
|
|
243
|
+
recommended: true,
|
|
244
|
+
message: "{{property}} is not kebab-case: {{error}}",
|
|
245
|
+
given: "$.paths[*]~",
|
|
246
|
+
then: {
|
|
247
|
+
function: pattern,
|
|
248
|
+
functionOptions: { match: "^/([a-z0-9]+(-[a-z0-9]+)*)?(/[a-z0-9]+(-[a-z0-9]+)*|/{.+})*$" }
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
"luxass/headers-hyphenated-pascal-case": {
|
|
252
|
+
description: "All `HTTP` headers MUST use `Hyphenated-Pascal-Case` notation",
|
|
253
|
+
severity: DiagnosticSeverity.Error,
|
|
254
|
+
recommended: true,
|
|
255
|
+
message: "{{property}} is not hyphenated-pascal-case: {{error}}",
|
|
256
|
+
given: "$..parameters[?(@.in == 'header')].name",
|
|
257
|
+
then: {
|
|
258
|
+
function: pattern,
|
|
259
|
+
functionOptions: { match: "^[A-Z][a-z0-9]*(-[A-Z][a-z0-9]*)*$" }
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
"luxass/version-in-info": {
|
|
263
|
+
message: "API version should follow semantic versioning.",
|
|
264
|
+
description: "The info.version field should follow semantic versioning (e.g., 1.0.0).",
|
|
265
|
+
given: "$.info.version",
|
|
266
|
+
then: {
|
|
267
|
+
function: pattern,
|
|
268
|
+
functionOptions: { match: "^\\d+\\.\\d+\\.\\d+" }
|
|
269
|
+
},
|
|
270
|
+
severity: DiagnosticSeverity.Warning
|
|
271
|
+
},
|
|
240
272
|
...oas2_default,
|
|
241
273
|
...oas3_default
|
|
242
274
|
}
|