You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(spectral): introduce severity overrides and handle pygeoapi
- add overrideSeverity ruleset function and connect a pygeoapi-specific override rule
- add may-have-info-x-api-type rule with docs/examples and clearer downgrade messaging
- switch jest to swc-backed ts testing and align tsconfig and build outputs
- switch jest config to CommonJS/node16 to allow proper imports
Copy file name to clipboardExpand all lines: docs/spectral-rules/index.md
+58-15Lines changed: 58 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,25 +15,67 @@ As well as the rules described herein, the UKHSA ruleset includes the [recommend
15
15
16
16
Where rules been adopted from from existing open source API rulesets a link is supplied on the relevant rule page.
17
17
18
+
## Pygeoapi severity overrides
19
+
20
+
Some definitions (for example, produced by pygeoapi) cannot yet meet every **MUST** requirement in the ruleset. When an OpenAPI document is marked with `info.x-api-type: pygeoapi`, the ruleset automatically downgrades the following error-level rules to `warn`:
21
+
22
+
-`must-define-a-format-for-integer-types`
23
+
-`must-define-a-format-for-number-types`
24
+
-`must-define-security-schemes`
25
+
-`must-have-info-api-audience`
26
+
-`must-have-info-contact-email`
27
+
-`must-have-info-value-chain`
28
+
-`must-have-info-version`
29
+
-`must-specify-default-response`
30
+
-`must-use-camel-case-for-property-names`
31
+
-`must-use-camel-case-for-query-parameters`
32
+
-`must-use-https-protocol-only`
33
+
-`must-use-problem-json-as-default-response`
34
+
-`must-use-problem-json-for-errors`
35
+
-`must-use-valid-version-info-schema`
36
+
37
+
Other rules continue to run normally, so pygeoapi definitions should still be linted and improved where possible. Rules already at `warn` are not changed.
38
+
39
+
### `info.x-api-type` values
40
+
41
+
To make intent explicit, the `info.x-api-type` field can be treated as an enum in API definitions to indicate the API category:
42
+
43
+
-`standard` – default behavior; no overrides applied.
44
+
-`pygeoapi` – pygeoapi-based definitions; error-level rules listed above are downgraded to `warn`.
45
+
46
+
If you omit `info.x-api-type`, the ruleset assumes the API is `standard`.
47
+
48
+
See also: [MAY have info.x-api-type][6].
49
+
50
+
When generating a definition from a local pygeoapi instance, you can inject the `info.x-api-type` flag during export so relaxed severities will be applied. The example below wraps the `pygeoapi openapi generate` command in Docker, binds your local configuration, and uses `yq` to add `info.x-api-type: pygeoapi` before writing the result to `openapi-pygeoapi.yml`.
[Spectral][6] is a flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
64
+
[Spectral][7] is a flexible JSON/YAML linter for creating automated style guides, with baked in support for OpenAPI (v3.1, v3.0, and v2.0), Arazzo v1.0, as well as AsyncAPI v2.x.
23
65
24
66
Install Spectral globally or as a dev dependency.
25
67
26
68
```sh
27
69
npm install @stoplight/spectral-cli --save-dev
28
70
```
29
71
30
-
Read the [official spectral documentation][7] for more installation options.
72
+
Read the [official spectral documentation][8] for more installation options.
31
73
32
74
### Run Spectral against your OpenAPI definition
33
75
34
76
Run Spectral against your OpenAPI definition, referencing the spectral ruleset.
35
77
36
-
You must install the ruleset as via [npm package][8] and then reference that, bear in mind the UKHSA ruleset npm package is hosted in github so please read Github's documentation [Installing a GitHub npm package][9].
78
+
You must install the ruleset as via [npm package][9] and then reference that, bear in mind the UKHSA ruleset npm package is hosted in github so please read Github's documentation [Installing a GitHub npm package][10].
Spectral rules categorised as **MAY** highlight optional practices. They can be adopted when they add value or context, and teams should weigh them based on preference, consumer needs, or implementation constraints.
APIs **MAY** include an `info.x-api-type` field to indicate the API category. When present, the value **MUST** be either `standard` or `pygeoapi`. If the field is omitted, the ruleset assumes the API is `standard`.
4
+
5
+
> [!IMPORTANT]
6
+
> Using `info.x-api-type: pygeoapi` signals pygeoapi-based definitions and enables conditional severity downgrades for certain rules. See [1].
Copy file name to clipboardExpand all lines: docs/spectral-rules/must/must-define-a-format-for-integer-types.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
3
3
`integer` properties **MUST** have a format defined (`int32`, `int64`, or `bigint`).
4
4
5
+
> [!IMPORTANT]
6
+
> For openapi definitions marked with `info.x-api-type: pygeoapi`, this rule’s severity is automatically set to `warn` by the `override-severity-pygeoapi` rule. See [1].
Copy file name to clipboardExpand all lines: docs/spectral-rules/must/must-define-a-format-for-number-types.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
3
3
`number` properties **MUST** have a format defined (`float`, `double`, or `decimal`).
4
4
5
+
> [!IMPORTANT]
6
+
> For openapi definitions marked with `info.x-api-type: pygeoapi`, this rule’s severity is automatically set to `warn` by the `override-severity-pygeoapi` rule. See [1].
Copy file name to clipboardExpand all lines: docs/spectral-rules/must/must-define-security-schemes.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
3
3
All APIs **MUST** have a security scheme defined.
4
4
5
+
> [!IMPORTANT]
6
+
> For openapi definitions marked with `info.x-api-type: pygeoapi`, this rule’s severity is automatically set to `warn` by the `override-severity-pygeoapi` rule. See [1].
7
+
5
8
If an API doesn't have a security scheme defined, it means the entire API is open to the public. That's probably not what you want, even if all the data is read-only. Setting lower rate limits for the public and letting known consumers use more resources is a handy path to monetization, and helps know who your power users are when changes need feedback or migration, even if not just good practice.
Copy file name to clipboardExpand all lines: docs/spectral-rules/must/must-have-info-api-audience.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,9 @@
2
2
3
3
The `info` object **MUST** have an `x-audience` that matches at least one of these values:
4
4
5
+
> [!IMPORTANT]
6
+
> For openapi definitions marked with `info.x-api-type: pygeoapi`, this rule’s severity is automatically set to `warn` by the `override-severity-pygeoapi` rule. See [1].
7
+
5
8
| audience | Use case |
6
9
| - | - |
7
10
|`company-internal`| for internal use only with UKHSA |
0 commit comments