Skip to content
Open
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
45 changes: 42 additions & 3 deletions linter/spectral.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,55 @@ rules:
char: ""

nlgov:servers-use-https:
severity: warn
message: "Server URL {{value}} {{error}}."
severity: error
message: "Server URL {{value}} must start with https:// instead of http://."
given:
- $.servers[*]
- $.paths..servers[*]
then:
field: url
function: pattern
functionOptions:
match: ^https://.*
notMatch: ^http://.*

nlgov:servers-at-most-one-relative:
severity: error
message: "At most one relative URL may be specified as server."
given:
- $.servers
- $.paths..servers
then:
function: schema
functionOptions:
dialect: draft2020-12
schema:
type: array
contains:
type: object
properties:
url:
pattern: ^(?!https:).+
minContains: 0
maxContains: 1

nlgov:servers-at-least-one-absolute:
severity: error
message: "At least one absolute URL must be specified as server."
given:
- $.servers
- $.paths..servers
then:
function: schema
functionOptions:
dialect: draft2020-12
schema:
type: array
contains:
type: object
properties:
url:
pattern: ^https://.*
minContains: 1

nlgov:use-problem-schema:
severity: warn
Expand Down
5 changes: 3 additions & 2 deletions linter/testcases/servers-empty/expected-output.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

/testcases/servers-empty/openapi.json
13:15 error oas3-api-servers OpenAPI "servers" must be present and non-empty array. servers
13:15 error nlgov:servers-at-least-one-absolute At least one absolute URL must be specified as server. servers
13:15 error oas3-api-servers OpenAPI "servers" must be present and non-empty array. servers

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

/testcases/servers-no-absolute/openapi.json
13:15 error nlgov:servers-at-least-one-absolute At least one absolute URL must be specified as server. servers

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)
81 changes: 81 additions & 0 deletions linter/testcases/servers-no-absolute/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"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": "/api/v1",
"description": "API location on the origin that the openapi.json is served"
}
],
"security": [
{
"default": []
}
],
"tags": [
{
"name": "openapi"
}
],
"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": []
}
]
}
}
},
"components": {
"schemas": {
},
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions linter/testcases/servers-no-https/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/testcases/servers-no-https/openapi.json
15:20 error nlgov:servers-use-https Server URL http://production.example.com/api/v1 must start with https:// instead of http://. servers[0].url

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)
85 changes: 85 additions & 0 deletions linter/testcases/servers-no-https/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"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": "http://production.example.com/api/v1",
"description": "Production server"
},
{
"url": "https://staging.example.com/api/v1",
"description": "Pre-production server"
}
],
"security": [
{
"default": []
}
],
"tags": [
{
"name": "openapi"
}
],
"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": []
}
]
}
}
},
"components": {
"schemas": {
},
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions linter/testcases/servers-relative-one/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
No results with a severity of 'error' found!
89 changes: 89 additions & 0 deletions linter/testcases/servers-relative-one/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{
"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://production.example.com/api/v1",
"description": "Production server"
},
{
"url": "https://staging.example.com/api/v1",
"description": "Pre-production server"
},
{
"url": "/api/v1",
"description": "API location on the origin that the openapi.json is served"
}
],
"security": [
{
"default": []
}
],
"tags": [
{
"name": "openapi"
}
],
"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": []
}
]
}
}
},
"components": {
"schemas": {
},
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
5 changes: 5 additions & 0 deletions linter/testcases/servers-relative-two/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

/testcases/servers-relative-two/openapi.json
13:15 error nlgov:servers-at-most-one-relative At most one relative URL may be specified as server. servers

✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints)
Loading
Loading