Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions linter/testcases/language-code/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

/testcases/language-code/openapi.json
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
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]
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]
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]
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
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
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
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
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
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
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
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
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
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
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
246:27 error nlgov:use-language-code Field represents a language and therefore must set 'format' to 'language' components.schemas.LanguageIncorrect.format

✖ 16 problems (16 errors, 0 warnings, 0 infos, 0 hints)
266 changes: 266 additions & 0 deletions linter/testcases/language-code/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"openapi": "3.0.3",
"info": {
"title": "Baseline",
"description": "Deze OpenAPI specification bevat het minimale om aan alle regels te voldoen.",
"contact": {
"name": "Beheerder",
"url": "https://www.example.com",
"email": "mail@example.com"
},
"version": "1.0.0"
},
"servers": [
{
"url": "https://example.com/api/v1"
}
],
"security": [
{
"default": []
}
],
"tags": [
{
"name": "openapi"
},
{
"name": "language"
}
],
"paths": {
"/openapi.json": {
"get": {
"tags": [
"openapi"
],
"description": "OpenAPI document",
"operationId": "getOpenapiJSON",
"parameters": [],
"responses": {
"200": {
"description": "OK",
"headers": {
"API-Version": {
"description": "De huidige versie van de applicatie",
"style": "simple",
"schema": {
"type": "string"
}
},
"access-control-allow-origin": {
"description": "Alle origins mogen bij deze resource",
"schema": {
"type": "string"
}
}
}
}
},
"security": [
{
"default": []
}
]
}
},
"/resources-with-language-incorrect": {
"get": {
"tags": [
"language"
],
"description": "Resources with language incorrect",
"operationId": "getLanguageIncorrect",
"parameters": [],
"responses": {
"200": {
"description": "OK",
"headers": {
"API-Version": {
"description": "De huidige versie van de applicatie",
"style": "simple",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"language": {
"type": "string"
},
"enumLanguage": {
"type": "string",
"format": "language",
"enum": ["nl-nl", "fy-NL", "NL-BE", "EN-gb"]
},
"thoroughfare_language": {
"type": "string"
},
"railName_localNameLanguage": {
"type": "string"
},
"taal": {
"type": "string"
},
"organisatieTaal": {
"type": "string"
},
"organisatie_taal": {
"type": "string"
},
"meerdereTaal": {
"type": "string",
"allOf": [
{
"$ref": "#/components/schemas/LanguageIncorrect"
}
]
}
}
}
},
"application/json+verkeerd-format": {
"schema": {
"type": "object",
"properties": {
"language": {
"type": "string",
"format": "byte"
},
"thoroughfare_language": {
"type": "string",
"format": "byte"
},
"railName_localNameLanguage": {
"type": "string",
"format": "byte"
},
"taal": {
"type": "string",
"format": "byte"
},
"organisatieTaal": {
"type": "string",
"format": "byte"
},
"organisatie_taal": {
"type": "string",
"format": "byte"
}
}
}
}
}
}
},
"security": [
{
"default": []
}
]
}
},
"/resources-with-language-correct": {
"get": {
"tags": [
"language"
],
"description": "Resources with language correct",
"operationId": "getLanguagesCorrect",
"parameters": [],
"responses": {
"200": {
"description": "OK",
"headers": {
"API-Version": {
"description": "De huidige versie van de applicatie",
"style": "simple",
"schema": {
"type": "string"
}
}
},
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"language": {
"type": "string",
"format": "language"
},
"enumLanguage": {
"type": "string",
"format": "language",
"enum": ["nl-NL", "nl-BE"]
},
"thoroughfare_language": {
"type": "string",
"format": "language"
},
"railName_localNameLanguage": {
"type": "string",
"format": "language"
},
"taal": {
"type": "string",
"format": "language"
},
"organisatieTaal": {
"type": "string",
"format": "language"
},
"organisatie_taal": {
"type": "string",
"format": "language"
},
"meerdereTaal": {
"type": "string",
"allOf": [
{
"$ref": "#/components/schemas/LanguageCorrect"
}
]
}
}
}
}
}
}
},
"security": [
{
"default": []
}
]
}
}
},
"components": {
"schemas": {
"LanguageIncorrect": {
"format": "byte",
"type": "string"
},
"LanguageCorrect": {
"format": "language",
"type": "string"
}
},
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
45 changes: 45 additions & 0 deletions media/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,51 @@ rules:
functionOptions:
notMatch: "/^date-time$/"

#/core/lang-code
nlgov:specify-format-for-language-code:
severity: error
given:
- $..properties[taal,lang,language]
- $..properties[?(@property && @property.match(/((\w+T)|(_[tT]))aal/))]
- $..properties[?(@property && @property.match(/((\w+L)|(_[lL]))ang(uage)?/))]
message: "Any field that represents a language must set 'format' to 'language'"
then:
function: schema
functionOptions:
schema:
anyOf:
- required: ["format"]
- properties:
allOf:
type: array
items:
required: ["format"]
required: ["allOf"]

nlgov:use-language-code:
severity: error
given:
- $..properties[taal,lang,language]..format
- $..properties[?(@property && @property.match(/((\w+T)|(_[tT]))aal/))]..format
- $..properties[?(@property && @property.match(/((\w+L)|(_[lL]))ang(uage)?/))]..format
message: "Field represents a language and therefore must set 'format' to 'language'"
then:
function: pattern
functionOptions:
match: "/^language$/"

nlgov:correct-language-enum:
severity: error
given:
- $..properties[taal,lang,language]..enum[*]
- $..properties[?(@property && @property.match(/((\w+T)|(_[tT]))aal/))]..enum[*]
- $..properties[?(@property && @property.match(/((\w+L)|(_[lL]))ang(uage)?/))]..enum[*]
message: "Values listed in enums must conform to RFC5646 with Primary Language subtag lowercase and Region subtag uppercase: {{value}} is not"
then:
function: pattern
functionOptions:
match: "/^[a-z]{2}-[A-Z]{2}$/"

nlgov:semver:
severity: error
message: "Version {{value}} is not in semver format."
Expand Down
Loading
Loading