diff --git a/linter/.spectral.yml b/linter/.spectral.yml index 9b8e8de..9a72d8a 100644 --- a/linter/.spectral.yml +++ b/linter/.spectral.yml @@ -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 @@ -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 diff --git a/linter/run-linter-tests.mjs b/linter/run-linter-tests.mjs index d440316..1867ec8 100644 --- a/linter/run-linter-tests.mjs +++ b/linter/run-linter-tests.mjs @@ -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) { diff --git a/linter/testcases/cor-api/expected-output.txt b/linter/testcases/cor-api/expected-output.txt index 3d53ff3..c690e2f 100644 --- a/linter/testcases/cor-api/expected-output.txt +++ b/linter/testcases/cor-api/expected-output.txt @@ -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) diff --git a/linter/testcases/homepage-failure/expected-output.txt b/linter/testcases/homepage-failure/expected-output.txt new file mode 100644 index 0000000..e16aa79 --- /dev/null +++ b/linter/testcases/homepage-failure/expected-output.txt @@ -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) diff --git a/linter/testcases/homepage-failure/openapi.json b/linter/testcases/homepage-failure/openapi.json new file mode 100644 index 0000000..df919c0 --- /dev/null +++ b/linter/testcases/homepage-failure/openapi.json @@ -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": "servicecentrum@logius.nl" + }, + "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": {} + } + } + } + } + } +} \ No newline at end of file diff --git a/linter/testcases/homepage-missing/expected-output.txt b/linter/testcases/homepage-missing/expected-output.txt new file mode 100644 index 0000000..f1bb4f8 --- /dev/null +++ b/linter/testcases/homepage-missing/expected-output.txt @@ -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) diff --git a/linter/testcases/homepage-missing/openapi.json b/linter/testcases/homepage-missing/openapi.json new file mode 100644 index 0000000..4117d06 --- /dev/null +++ b/linter/testcases/homepage-missing/openapi.json @@ -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": "servicecentrum@logius.nl" + }, + "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": {} + } + } + } + } + } +} \ No newline at end of file diff --git a/linter/testcases/homepage-no-get/expected-output.txt b/linter/testcases/homepage-no-get/expected-output.txt new file mode 100644 index 0000000..5d4ad6a --- /dev/null +++ b/linter/testcases/homepage-no-get/expected-output.txt @@ -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) diff --git a/linter/testcases/homepage-no-get/openapi.json b/linter/testcases/homepage-no-get/openapi.json new file mode 100644 index 0000000..7645113 --- /dev/null +++ b/linter/testcases/homepage-no-get/openapi.json @@ -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": "servicecentrum@logius.nl" + }, + "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": {} + } + } + } + } + } +} \ No newline at end of file diff --git a/linter/testcases/homepage/expected-output.txt b/linter/testcases/homepage/expected-output.txt new file mode 100644 index 0000000..95cc954 --- /dev/null +++ b/linter/testcases/homepage/expected-output.txt @@ -0,0 +1 @@ +No results with a severity of 'error' found! diff --git a/linter/testcases/homepage/openapi.json b/linter/testcases/homepage/openapi.json new file mode 100644 index 0000000..a5506fd --- /dev/null +++ b/linter/testcases/homepage/openapi.json @@ -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": "servicecentrum@logius.nl" + }, + "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": {} + } + } + } + } + } +} \ No newline at end of file