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
9 changes: 9 additions & 0 deletions linter/testcases/servers-https/expected-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

/testcases/servers-https/openapi.json
15:20 error nlgov:servers-use-https Server URL http://example.com/api/v1 "http://example.com/api/v1" must not match the pattern "^http://.*". servers[0].url
64:32 error nlgov:servers-use-https Server URL http://example.com/api/v1 "http://example.com/api/v1" must not match the pattern "^http://.*". paths./openapi.json.get.servers[0].url
70:28 error nlgov:servers-use-https Server URL http://example.com/api/v1 "http://example.com/api/v1" must not match the pattern "^http://.*". paths./openapi.json.servers[0].url
119:44 error nlgov:servers-use-https Server URL http://example.com/callback "http://example.com/callback" must not match the pattern "^http://.*". paths./apis.get.callbacks.apiGewijzigd.{$request.query.callbackUrl}.servers[0].url
127:48 error nlgov:servers-use-https Server URL http://example.com/callback "http://example.com/callback" must not match the pattern "^http://.*". paths./apis.get.callbacks.apiGewijzigd.{$request.query.callbackUrl}.post.servers[0].url

✖ 5 problems (5 errors, 0 warnings, 0 infos, 0 hints)
251 changes: 251 additions & 0 deletions linter/testcases/servers-https/openapi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
{
"openapi": "3.0.3",
"info": {
"title": "Servers HTTPS",
"description": "Deze OpenAPI specification bevat servers zonder https op hoofd-, pad-, operatie- en callbackniveau, en een schema met een property genaamd servers die niet gevalideerd mag worden.",
"contact": {
"name": "Beheerder",
"url": "https://www.example.com",
"email": "mail@example.com"
},
"version": "1.0.0"
},
"servers": [
{
"url": "http://example.com/api/v1"
}
],
"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": []
}
],
"servers": [
{
"url": "http://example.com/api/v1"
}
]
},
"servers": [
{
"url": "http://example.com/api/v1"
}
]
},
"/apis": {
"get": {
"tags": [
"openapi"
],
"description": "Lijst van API's",
"operationId": "getApis",
"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"
}
}
},
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Api"
}
}
}
}
},
"security": [
{
"default": []
}
],
"callbacks": {
"apiGewijzigd": {
"{$request.query.callbackUrl}": {
"servers": [
{
"url": "http://example.com/callback"
}
],
"post": {
"description": "Notificatie van een gewijzigde API",
"operationId": "postApiGewijzigd",
"servers": [
{
"url": "http://example.com/callback"
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Api"
}
}
}
},
"responses": {
"204": {
"description": "No Content",
"headers": {
"API-Version": {
"description": "De huidige versie van de applicatie",
"style": "simple",
"schema": {
"type": "string"
}
}
}
},
"400": {
"description": "Bad Request",
"content": {
"application/problem+json": {
"schema": {
"type": "object",
"properties": {
"status": {
"type": "integer"
},
"title": {
"type": "string"
},
"detail": {
"type": "string"
},
"errors": {
"type": "object",
"properties": {
"in": {
"type": "string"
},
"location": {
"type": "object",
"properties": {
"pointer": {
"type": "string"
},
"name": {
"type": "string"
},
"index": {
"type": "integer"
}
}
},
"code": {
"type": "string"
},
"detail": {
"type": "string"
}
}
}
},
"required": [
"status",
"title",
"detail",
"errors"
],
"additionalProperties": false
}
}
}
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Api": {
"type": "object",
"properties": {
"servers": {
"type": "object",
"properties": {
"url": {
"type": "string"
},
"description": {
"type": "string"
}
},
"example": {
"url": "http://example.com/api/v1",
"description": "Voorbeeld van een server van een andere API"
}
}
}
}
},
"securitySchemes": {
"default": {
"type": "oauth2",
"flows": {
"implicit": {
"authorizationUrl": "https://test.com",
"scopes": {}
}
}
}
}
}
}
5 changes: 4 additions & 1 deletion media/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ rules:
message: "Server URL {{value}} {{error}}."
given:
- $.servers[*]
- $.paths..servers[*]
- $.paths[*].servers[*]
- $.paths[*][*].servers[*]
- $.paths[*][*].callbacks[*][*].servers[*]
- $.paths[*][*].callbacks[*][*][*].servers[*]
then:
field: url
function: pattern
Expand Down
Loading