Skip to content

Commit 535eff0

Browse files
TimvdLippesanderke
andauthored
Voeg regel toe voor informatie over talen (#333)
Hiermee standaardiseren we het gebruik van talen, welk formaat taal codes in geschreven moeten worden en in welke capitalisation deze codes moeten worden geschreven. Co-authored-by: Alexander Green <alexander.green@logius.nl>
1 parent 5bcb823 commit 535eff0

5 files changed

Lines changed: 404 additions & 1 deletion

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
/testcases/language-code/openapi.json
3+
92:52 error nlgov:specify-format-for-language-code Any field that represents a language must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.language
4+
98:54 error nlgov:correct-language-enum Values listed in enums must conform to RFC5646 with Primary Language subtag lowercase and Region subtag uppercase: nl-nl is not paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.enumLanguage.enum[0]
5+
98:72 error nlgov:correct-language-enum Values listed in enums must conform to RFC5646 with Primary Language subtag lowercase and Region subtag uppercase: NL-BE is not paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.enumLanguage.enum[2]
6+
98:81 error nlgov:correct-language-enum Values listed in enums must conform to RFC5646 with Primary Language subtag lowercase and Region subtag uppercase: EN-gb is not paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.enumLanguage.enum[3]
7+
100:65 error nlgov:specify-format-for-language-code Any field that represents a language must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.thoroughfare_language
8+
103:70 error nlgov:specify-format-for-language-code Any field that represents a language must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.railName_localNameLanguage
9+
106:48 error nlgov:specify-format-for-language-code Any field that represents a language must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.taal
10+
109:59 error nlgov:specify-format-for-language-code Any field that represents a language must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.organisatieTaal
11+
112:60 error nlgov:specify-format-for-language-code Any field that represents a language must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json.schema.properties.organisatie_taal
12+
132:55 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json+verkeerd-format.schema.properties.language.format
13+
136:55 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json+verkeerd-format.schema.properties.thoroughfare_language.format
14+
140:55 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json+verkeerd-format.schema.properties.railName_localNameLanguage.format
15+
144:55 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json+verkeerd-format.schema.properties.taal.format
16+
148:55 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json+verkeerd-format.schema.properties.organisatieTaal.format
17+
152:55 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' paths./resources-with-language-incorrect.get.responses[200].content.application/json+verkeerd-format.schema.properties.organisatie_taal.format
18+
246:27 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' components.schemas.LanguageIncorrect.format
19+
20+
✖ 16 problems (16 errors, 0 warnings, 0 infos, 0 hints)
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
{
2+
"openapi": "3.0.3",
3+
"info": {
4+
"title": "Baseline",
5+
"description": "Deze OpenAPI specification bevat het minimale om aan alle regels te voldoen.",
6+
"contact": {
7+
"name": "Beheerder",
8+
"url": "https://www.example.com",
9+
"email": "mail@example.com"
10+
},
11+
"version": "1.0.0"
12+
},
13+
"servers": [
14+
{
15+
"url": "https://example.com/api/v1"
16+
}
17+
],
18+
"security": [
19+
{
20+
"default": []
21+
}
22+
],
23+
"tags": [
24+
{
25+
"name": "openapi"
26+
},
27+
{
28+
"name": "language"
29+
}
30+
],
31+
"paths": {
32+
"/openapi.json": {
33+
"get": {
34+
"tags": [
35+
"openapi"
36+
],
37+
"description": "OpenAPI document",
38+
"operationId": "getOpenapiJSON",
39+
"parameters": [],
40+
"responses": {
41+
"200": {
42+
"description": "OK",
43+
"headers": {
44+
"API-Version": {
45+
"description": "De huidige versie van de applicatie",
46+
"style": "simple",
47+
"schema": {
48+
"type": "string"
49+
}
50+
},
51+
"access-control-allow-origin": {
52+
"description": "Alle origins mogen bij deze resource",
53+
"schema": {
54+
"type": "string"
55+
}
56+
}
57+
}
58+
}
59+
},
60+
"security": [
61+
{
62+
"default": []
63+
}
64+
]
65+
}
66+
},
67+
"/resources-with-language-incorrect": {
68+
"get": {
69+
"tags": [
70+
"language"
71+
],
72+
"description": "Resources with language incorrect",
73+
"operationId": "getLanguageIncorrect",
74+
"parameters": [],
75+
"responses": {
76+
"200": {
77+
"description": "OK",
78+
"headers": {
79+
"API-Version": {
80+
"description": "De huidige versie van de applicatie",
81+
"style": "simple",
82+
"schema": {
83+
"type": "string"
84+
}
85+
}
86+
},
87+
"content": {
88+
"application/json": {
89+
"schema": {
90+
"type": "object",
91+
"properties": {
92+
"language": {
93+
"type": "string"
94+
},
95+
"enumLanguage": {
96+
"type": "string",
97+
"format": "language",
98+
"enum": ["nl-nl", "fy-NL", "NL-BE", "EN-gb"]
99+
},
100+
"thoroughfare_language": {
101+
"type": "string"
102+
},
103+
"railName_localNameLanguage": {
104+
"type": "string"
105+
},
106+
"taal": {
107+
"type": "string"
108+
},
109+
"organisatieTaal": {
110+
"type": "string"
111+
},
112+
"organisatie_taal": {
113+
"type": "string"
114+
},
115+
"meerdereTaal": {
116+
"type": "string",
117+
"allOf": [
118+
{
119+
"$ref": "#/components/schemas/LanguageIncorrect"
120+
}
121+
]
122+
}
123+
}
124+
}
125+
},
126+
"application/json+verkeerd-format": {
127+
"schema": {
128+
"type": "object",
129+
"properties": {
130+
"language": {
131+
"type": "string",
132+
"format": "byte"
133+
},
134+
"thoroughfare_language": {
135+
"type": "string",
136+
"format": "byte"
137+
},
138+
"railName_localNameLanguage": {
139+
"type": "string",
140+
"format": "byte"
141+
},
142+
"taal": {
143+
"type": "string",
144+
"format": "byte"
145+
},
146+
"organisatieTaal": {
147+
"type": "string",
148+
"format": "byte"
149+
},
150+
"organisatie_taal": {
151+
"type": "string",
152+
"format": "byte"
153+
}
154+
}
155+
}
156+
}
157+
}
158+
}
159+
},
160+
"security": [
161+
{
162+
"default": []
163+
}
164+
]
165+
}
166+
},
167+
"/resources-with-language-correct": {
168+
"get": {
169+
"tags": [
170+
"language"
171+
],
172+
"description": "Resources with language correct",
173+
"operationId": "getLanguagesCorrect",
174+
"parameters": [],
175+
"responses": {
176+
"200": {
177+
"description": "OK",
178+
"headers": {
179+
"API-Version": {
180+
"description": "De huidige versie van de applicatie",
181+
"style": "simple",
182+
"schema": {
183+
"type": "string"
184+
}
185+
}
186+
},
187+
"content": {
188+
"application/json": {
189+
"schema": {
190+
"type": "object",
191+
"properties": {
192+
"language": {
193+
"type": "string",
194+
"format": "language"
195+
},
196+
"enumLanguage": {
197+
"type": "string",
198+
"format": "language",
199+
"enum": ["nl-NL", "nl-BE"]
200+
},
201+
"thoroughfare_language": {
202+
"type": "string",
203+
"format": "language"
204+
},
205+
"railName_localNameLanguage": {
206+
"type": "string",
207+
"format": "language"
208+
},
209+
"taal": {
210+
"type": "string",
211+
"format": "language"
212+
},
213+
"organisatieTaal": {
214+
"type": "string",
215+
"format": "language"
216+
},
217+
"organisatie_taal": {
218+
"type": "string",
219+
"format": "language"
220+
},
221+
"meerdereTaal": {
222+
"type": "string",
223+
"allOf": [
224+
{
225+
"$ref": "#/components/schemas/LanguageCorrect"
226+
}
227+
]
228+
}
229+
}
230+
}
231+
}
232+
}
233+
}
234+
},
235+
"security": [
236+
{
237+
"default": []
238+
}
239+
]
240+
}
241+
}
242+
},
243+
"components": {
244+
"schemas": {
245+
"LanguageIncorrect": {
246+
"format": "byte",
247+
"type": "string"
248+
},
249+
"LanguageCorrect": {
250+
"format": "language",
251+
"type": "string"
252+
}
253+
},
254+
"securitySchemes": {
255+
"default": {
256+
"type": "oauth2",
257+
"flows": {
258+
"implicit": {
259+
"authorizationUrl": "https://test.com",
260+
"scopes": {}
261+
}
262+
}
263+
}
264+
}
265+
}
266+
}

‎media/linter.yaml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,51 @@ rules:
282282
functionOptions:
283283
notMatch: "/^date-time$/"
284284

285+
#/core/lang-code
286+
nlgov:specify-format-for-language-code:
287+
severity: error
288+
given:
289+
- $..properties[taal,lang,language]
290+
- $..properties[?(@property && @property.match(/((\w+T)|(_[tT]))aal/))]
291+
- $..properties[?(@property && @property.match(/((\w+L)|(_[lL]))ang(uage)?/))]
292+
message: "Any field that represents a language must set 'format' to 'language'"
293+
then:
294+
function: schema
295+
functionOptions:
296+
schema:
297+
anyOf:
298+
- required: ["format"]
299+
- properties:
300+
allOf:
301+
type: array
302+
items:
303+
required: ["format"]
304+
required: ["allOf"]
305+
306+
nlgov:use-language-code:
307+
severity: error
308+
given:
309+
- $..properties[taal,lang,language]..format
310+
- $..properties[?(@property && @property.match(/((\w+T)|(_[tT]))aal/))]..format
311+
- $..properties[?(@property && @property.match(/((\w+L)|(_[lL]))ang(uage)?/))]..format
312+
message: "Field represents a language and therefore must set 'format' to 'language'"
313+
then:
314+
function: pattern
315+
functionOptions:
316+
match: "/^language$/"
317+
318+
nlgov:correct-language-enum:
319+
severity: error
320+
given:
321+
- $..properties[taal,lang,language]..enum[*]
322+
- $..properties[?(@property && @property.match(/((\w+T)|(_[tT]))aal/))]..enum[*]
323+
- $..properties[?(@property && @property.match(/((\w+L)|(_[lL]))ang(uage)?/))]..enum[*]
324+
message: "Values listed in enums must conform to RFC5646 with Primary Language subtag lowercase and Region subtag uppercase: {{value}} is not"
325+
then:
326+
function: pattern
327+
functionOptions:
328+
match: "/^[a-z]{2}-[A-Z]{2}$/"
329+
285330
nlgov:semver:
286331
severity: error
287332
message: "Version {{value}} is not in semver format."

0 commit comments

Comments
 (0)