Skip to content

Commit

Permalink
Voeg linter regels toe voor homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Mar 7, 2025
1 parent 79b5742 commit ae74c4f
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 4 deletions.
30 changes: 28 additions & 2 deletions linter/.spectral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,36 @@ rules:
then:
function: pattern
functionOptions:
notMatch: "\\/$"
notMatch: ".+\\/$"
field: "@key"
message: "/core/no-trailing-slash: Leave off trailing slashes from URIs: https://logius-standaarden.github.io/API-Design-Rules/#/core/no-trailing-slash"

missing-home-page:
severity: error
given:
- "$.paths"
then:
field: "/"
function: truthy
message: "There does not exist a resource `/` that should resolve to the homepage"

home-page-successful-response:
severity: error
given:
- "$.paths[/].responses[?(@property && @property.match(/(2|3)\d\d/))]"
then:
function: truthy
message: "There should be a 2XX or 3XX response for the `/` resource"

home-page-no-get-response:
severity: error
given:
- "$.paths[/]"
then:
field: "get"
function: truthy
message: "There should be a GET endpoint for the `/` resource"

#/core/http-methods
http-methods:
severity: error
Expand All @@ -76,7 +102,7 @@ rules:
then:
function: pattern
functionOptions:
match: "^(\/[a-z0-9-.]+|\/{[a-zA-Z0-9_]+})+$"
match: /^(\/|[a-z0-9\-\.]+|{[a-zA-Z0-9]+})+$/

schema-camel-case:
severity: warn
Expand Down
2 changes: 1 addition & 1 deletion linter/run-linter-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const readdir = utils.promisify(fs.readdir);
const SPECTRAL_RULESET_LOCATION = path.join(__dirname, '.spectral.yml');

function computeTestCommand(apiLocation) {
return `spectral lint -r ${SPECTRAL_RULESET_LOCATION} ${apiLocation}/openapi.json`
return `spectral lint -r ${SPECTRAL_RULESET_LOCATION} ${apiLocation}/openapi.json || true`
}

function removeProcessDir(output) {
Expand Down
3 changes: 2 additions & 1 deletion linter/testcases/cor-api/expected-output.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

/testcases/cor-api/openapi.json
37:13 error missing-home-page There does not exist a resource `/` that should resolve to the homepage paths
181:29 warning paths-kebab-case /laatsteWijziging is not kebab-case. paths./laatsteWijziging
774:30 warning use-problem-schema Your schema doesn't seem to match RFC7807. Are you sure it is ok? #/components/schemas/HealthCheckResponse/properties components.schemas.HealthCheckResponse.properties

2 problems (0 errors, 2 warnings, 0 infos, 0 hints)
3 problems (1 error, 2 warnings, 0 infos, 0 hints)
5 changes: 5 additions & 0 deletions linter/testcases/homepage-failure/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/testcases/homepage-failure/openapi.json
31:29 warning operation-success-response Operation must have at least one "2xx" or "3xx" response. paths./.get.responses

✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints)
57 changes: 57 additions & 0 deletions linter/testcases/homepage-failure/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"openapi": "3.0.3",
"info": {
"title": "COR API Services",
"description": "Deze Logius REST API's bieden de openbare informatie voor organisaties",
"contact": {
"name": "Logius",
"url": "https://www.logius.nl/diensten/digikoppeling/",
"email": "[email protected]"
},
"version": "1.2.9-SNAPSHOT"
},
"servers": [
{
"url": "https://oinregister.logius.nl/api/v1"
}
],
"security": [
{
"default": []
}
],
"tags": [{"name": "Homepage"}],
"paths": {
"/": {
"get": {
"tags": ["Homepage"],
"summary": "Homepage",
"description": "Homepage with a description",
"operationId": "getHomepage",
"responses": {
"403": {
"description": "Unauthorized"
}
},
"security": [
{
"default": []
}
]
}
}
},
"components": {
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions linter/testcases/homepage-missing/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/testcases/homepage-missing/openapi.json
24:13 error missing-home-page There does not exist a resource `/` that should resolve to the homepage paths

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)
66 changes: 66 additions & 0 deletions linter/testcases/homepage-missing/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"openapi": "3.0.3",
"info": {
"title": "COR API Services",
"description": "Deze Logius REST API's bieden de openbare informatie voor organisaties",
"contact": {
"name": "Logius",
"url": "https://www.logius.nl/diensten/digikoppeling/",
"email": "[email protected]"
},
"version": "1.2.9-SNAPSHOT"
},
"servers": [
{
"url": "https://oinregister.logius.nl/api/v1"
}
],
"security": [
{
"default": []
}
],
"tags": [{"name": "Homepage"}],
"paths": {
"/no-homepage": {
"get": {
"tags": ["Homepage"],
"summary": "Homepage",
"description": "Homepage with a description",
"operationId": "getHomepage",
"responses": {
"200": {
"description": "Homepage content",
"headers": {
"API-Version": {
"description": "Current version",
"style": "simple",
"schema": {
"type": "string"
}
}
}
}
},
"security": [
{
"default": []
}
]
}
}
},
"components": {
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions linter/testcases/homepage-no-get/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/testcases/homepage-no-get/openapi.json
25:13 error home-page-no-get-response There should be a GET endpoint for the `/` resource paths./

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)
66 changes: 66 additions & 0 deletions linter/testcases/homepage-no-get/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"openapi": "3.0.3",
"info": {
"title": "COR API Services",
"description": "Deze Logius REST API's bieden de openbare informatie voor organisaties",
"contact": {
"name": "Logius",
"url": "https://www.logius.nl/diensten/digikoppeling/",
"email": "[email protected]"
},
"version": "1.2.9-SNAPSHOT"
},
"servers": [
{
"url": "https://oinregister.logius.nl/api/v1"
}
],
"security": [
{
"default": []
}
],
"tags": [{"name": "Homepage"}],
"paths": {
"/": {
"post": {
"tags": ["Homepage"],
"summary": "Homepage",
"description": "Homepage with a description",
"operationId": "getHomepage",
"responses": {
"200": {
"description": "Homepage content",
"headers": {
"API-Version": {
"description": "Current version",
"style": "simple",
"schema": {
"type": "string"
}
}
}
}
},
"security": [
{
"default": []
}
]
}
}
},
"components": {
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions linter/testcases/homepage/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No results with a severity of 'error' found!
66 changes: 66 additions & 0 deletions linter/testcases/homepage/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"openapi": "3.0.3",
"info": {
"title": "COR API Services",
"description": "Deze Logius REST API's bieden de openbare informatie voor organisaties",
"contact": {
"name": "Logius",
"url": "https://www.logius.nl/diensten/digikoppeling/",
"email": "[email protected]"
},
"version": "1.2.9-SNAPSHOT"
},
"servers": [
{
"url": "https://oinregister.logius.nl/api/v1"
}
],
"security": [
{
"default": []
}
],
"tags": [{"name": "Homepage"}],
"paths": {
"/": {
"get": {
"tags": ["Homepage"],
"summary": "Homepage",
"description": "Homepage with a description",
"operationId": "getHomepage",
"responses": {
"200": {
"description": "Homepage content",
"headers": {
"API-Version": {
"description": "Current version",
"style": "simple",
"schema": {
"type": "string"
}
}
}
}
},
"security": [
{
"default": []
}
]
}
}
},
"components": {
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}

0 comments on commit ae74c4f

Please sign in to comment.