Skip to content

Commit 7b7518d

Browse files
authored
Merge pull request #1237 from modelix/feature/MODELIX-951-Include-a-linter-for-the-OpenAPI-specification
ci(model-server-openapi): lint the specification with spectral in GHA
2 parents 3bf7b08 + 22e1a45 commit 7b7518d

File tree

6 files changed

+4124
-195
lines changed

6 files changed

+4124
-195
lines changed

.github/workflows/linting.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ jobs:
2020
- uses: actions/setup-python@v5
2121
- uses: pre-commit/[email protected]
2222

23+
openapi-linting:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Clone repo
27+
uses: actions/checkout@v4
28+
- uses: stoplightio/[email protected]
29+
with:
30+
file_glob: 'model-server-openapi/specifications/model-server-*.yaml'
31+
spectral_ruleset: .spectral.yaml
32+
continue-on-error: true
33+
2334
openapi-breaking-changes:
2435
runs-on: ubuntu-latest
2536
permissions:

.spectral.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
extends:
2+
- https://raw.githubusercontent.com/baloise-incubator/spectral-ruleset/5b2386ffa4d0ab4ccef0e1fc87f3d00fefc81eea/zalando.yml
3+
- "spectral:oas"
4+
rules:
5+
# We don't need an API info for internal use
6+
must-have-info-contact-email: false
7+
must-have-info-contact-name: false
8+
must-have-info-contact-url: false
9+
must-have-info-x-api-id: false
10+
must-provide-api-audience: false
11+
12+
# The rule is based on an outdated problem specification
13+
must-use-valid-problem-json-schema: false
14+
15+
# We would lose enum support from openapi-generator
16+
should-use-x-extensible-enum: false
17+
18+
overrides:
19+
# Get error-free for what's present at the time of introducing the linter. New things should follow the conventions.
20+
- files:
21+
- 'model-server-v2.yaml'
22+
rules:
23+
must-use-lowercase-with-hypens-for-path-segements: warn
24+
- files:
25+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D/get/parameters/0/name'
26+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D~1poll/get/parameters/0/name'
27+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D~1pollHash/get/parameters/0/name'
28+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D~1pollHash/get/parameters/1/name'
29+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1init/post/parameters/0/name'
30+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1init/post/parameters/1/name'
31+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1versions~1%7BversionHash%7D/get/parameters/0/name'
32+
- 'model-server-v2.yaml#/paths/~1versions~1%7BversionHash%7D/get/parameters/0/name'
33+
rules:
34+
must-use-snake-case-for-query-parameters: warn
35+
- files:
36+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D/get/responses/200/content/application~1x-modelix-objects-v2/schema'
37+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D/get/responses/200/content/application~1x-modelix-objects/schema'
38+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1branches~1%7Bbranch%7D/get/responses/200/content/text~1plain/schema'
39+
- 'model-server-v2.yaml#/paths/~1repositories~1%7Brepository%7D~1delete/post/responses/204/content/text~1plain/schema'
40+
- 'model-server-v2.yaml#/components/responses/200/content/text~1plain/schema'
41+
- 'model-server-v2.yaml#/components/responses/200json/content/application~1json/schema'
42+
- 'model-server-v2.yaml#/components/responses/versionDelta/content/application~1x-modelix-objects/schema'
43+
- 'model-server-v2.yaml#/components/responses/versionDelta/content/application~1x-modelix-objects-v2/schema'
44+
- 'model-server-v2.yaml#/components/responses/versionDelta/content/text~1plain/schema'
45+
rules:
46+
must-always-return-json-objects-as-top-level-data-structures: warn
47+
- files:
48+
- 'model-server-v2.yaml#/components/responses/modelql-404'
49+
rules:
50+
must-use-problem-json-for-errors: warn
51+
- files:
52+
- 'model-server-v1.yaml#/paths/~1getAll'
53+
- 'model-server-v1.yaml#/paths/~1getEmail'
54+
- 'model-server-v1.yaml#/paths/~1getRecursively~1%7Bkey%7D'
55+
- 'model-server-v1.yaml#/paths/~1putAll'
56+
rules:
57+
must-use-lowercase-with-hypens-for-path-segements: warn
58+
- files:
59+
- 'model-server-v1.yaml#/paths/~1poll~1%7Bkey%7D/get/parameters/1/name'
60+
rules:
61+
must-use-snake-case-for-query-parameters: warn
62+
- files:
63+
- 'model-server-v1.yaml#/components/responses/200/content/text~1plain/schema'
64+
- 'model-server-v1.yaml#/components/responses/200json/content/application~1json/schema'
65+
rules:
66+
must-always-return-json-objects-as-top-level-data-structures: warn
67+
- files:
68+
- 'model-server-operative.yaml#/paths/~1metrics/get/responses'
69+
- 'model-server-operative.yaml#/paths/~1about/get/responses'
70+
rules:
71+
must-specify-default-response: warn
72+
- files:
73+
- 'model-server-operative.yaml#/components/responses/Healthy/content/text~1plain/schema'
74+
rules:
75+
must-always-return-json-objects-as-top-level-data-structures: warn
76+
77+
# Mandatory format for metrics
78+
- files:
79+
- 'model-server-operative.yaml#/components/responses/MetricsResponse/content/text~1plain/schema'
80+
rules:
81+
must-always-return-json-objects-as-top-level-data-structures: off
82+
- files:
83+
- 'model-server-operative.yaml#/components/responses/MetricsResponse/content/text~1plain'
84+
rules:
85+
should-prefer-standard-media-type-names: off

commitlint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
"model-client",
1616
"model-datastructure",
1717
"model-server",
18+
"model-server-openapi",
1819
"modelql",
1920
"mps-model-adapters",
2021
"mps-model-server",

model-server-openapi/specifications/model-server-v2.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ paths:
9494
responses:
9595
"200":
9696
$ref: '#/components/responses/200'
97+
default:
98+
$ref: '#/components/responses/GeneralError'
9799
/repositories/{repository}/branches:
98100
get:
99101
tags:
@@ -378,6 +380,8 @@ paths:
378380
type: string
379381
"404":
380382
$ref: '#/components/responses/404'
383+
default:
384+
$ref: '#/components/responses/GeneralError'
381385
/repositories/{repository}/versions/{versionHash}:
382386
get:
383387
tags:

0 commit comments

Comments
 (0)