diff --git a/linter/run-linter-tests.mjs b/linter/run-linter-tests.mjs index 43975d37..c07d0779 100755 --- a/linter/run-linter-tests.mjs +++ b/linter/run-linter-tests.mjs @@ -14,7 +14,7 @@ const writeFile = utils.promisify(fs.writeFile); const LINTER_RULESET_LOCATION = path.join(__dirname, '..', 'media', 'linter.yaml'); function computeTestCommand(apiLocation) { - return `spectral lint -r ${LINTER_RULESET_LOCATION} ${apiLocation}/openapi.json || true` + return `spectral lint -r ${LINTER_RULESET_LOCATION} ${apiLocation}/*.json || true` } function removeProcessDir(output) { diff --git a/linter/testcases/openapi-root-missing-swagger-2/expected-output.txt b/linter/testcases/openapi-root-missing-swagger-2/expected-output.txt new file mode 100644 index 00000000..15195cda --- /dev/null +++ b/linter/testcases/openapi-root-missing-swagger-2/expected-output.txt @@ -0,0 +1,5 @@ + +/testcases/openapi-root-missing-swagger-2/swagger.json + 1:1 error nlgov:openapi-root-exists The root of the document must contain the `openapi` property. + +✖ 1 problem (1 error, 0 warnings, 0 infos, 0 hints) diff --git a/linter/testcases/openapi-root-missing-swagger-2/swagger.json b/linter/testcases/openapi-root-missing-swagger-2/swagger.json new file mode 100644 index 00000000..2439b270 --- /dev/null +++ b/linter/testcases/openapi-root-missing-swagger-2/swagger.json @@ -0,0 +1,71 @@ +{ + "swagger": "2.0", + "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" + }, + "host": "example.com", + "basePath": "/api/v1", + "schemes": [ + "https" + ], + "security": [ + { + "default": [] + } + ], + "tags": [ + { + "name": "swagger" + } + ], + "paths": { + "/swagger.json": { + "get": { + "tags": [ + "swagger" + ], + "description": "Swagger document", + "operationId": "getSwaggerJSON", + "parameters": [], + "responses": { + "200": { + "description": "OK", + "headers": { + "API-Version": { + "description": "De huidige versie van de applicatie", + "type": "string" + }, + "access-control-allow-origin": { + "description": "Alle origins mogen bij deze resource", + "type": "string" + } + } + } + }, + "security": [ + { + "default": [] + } + ] + } + } + }, + "definitions": { + }, + "securityDefinitions": { + "default": { + "type": "oauth2", + "flow": "implicit", + "authorizationUrl": "https://test.com", + "scopes": { + } + } + } +} \ No newline at end of file diff --git a/linter/testcases/openapi-versie-missing/expected-output.txt b/linter/testcases/openapi-versie-missing/expected-output.txt deleted file mode 100644 index 3cc27be0..00000000 --- a/linter/testcases/openapi-versie-missing/expected-output.txt +++ /dev/null @@ -1,6 +0,0 @@ - -/testcases/openapi-versie-missing/openapi.json - 1:1 error nlgov:openapi-root-exists The root of the document must contain the `openapi` property. - 1:1 warning unrecognized-format The provided document does not match any of the registered formats [OpenAPI 2.0 (Swagger), OpenAPI 3.x, OpenAPI 3.0.x, OpenAPI 3.1.x] - -✖ 2 problems (1 error, 1 warning, 0 infos, 0 hints) diff --git a/linter/testcases/unrecognized-format-arazzo/arazzo.json b/linter/testcases/unrecognized-format-arazzo/arazzo.json new file mode 100644 index 00000000..7d4eee07 --- /dev/null +++ b/linter/testcases/unrecognized-format-arazzo/arazzo.json @@ -0,0 +1,26 @@ +{ + "arazzo": "1.0.1", + "info": { + "title": "Minimale Arazzo-specificatie", + "description": "Deze Arazzo-specificatie bevat het minimale om geen errors te geven.", + "version": "1.0.0" + }, + "sourceDescriptions": [ + { + "name": "basis-api", + "url": "https://example.com/openapi.json", + "type": "openapi" + } + ], + "workflows": [ + { + "workflowId": "openapi-document-ophalen", + "steps": [ + { + "stepId": "openapi-document-ophalen", + "operationId": "getOpenapiJSON" + } + ] + } + ] +} \ No newline at end of file diff --git a/linter/testcases/unrecognized-format-arazzo/expected-output.txt b/linter/testcases/unrecognized-format-arazzo/expected-output.txt new file mode 100644 index 00000000..1e00d047 --- /dev/null +++ b/linter/testcases/unrecognized-format-arazzo/expected-output.txt @@ -0,0 +1,5 @@ + +/testcases/unrecognized-format-arazzo/arazzo.json + 1:1 warning unrecognized-format The provided document does not match any of the registered formats [OpenAPI 3.x, OpenAPI 2.0 (Swagger), OpenAPI 3.0.x, OpenAPI 3.1.x] + +✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints) diff --git a/linter/testcases/unrecognized-format-openapi/expected-output.txt b/linter/testcases/unrecognized-format-openapi/expected-output.txt new file mode 100644 index 00000000..77f13304 --- /dev/null +++ b/linter/testcases/unrecognized-format-openapi/expected-output.txt @@ -0,0 +1,5 @@ + +/testcases/unrecognized-format-openapi/openapi.json + 1:1 warning unrecognized-format The provided document does not match any of the registered formats [OpenAPI 3.x, OpenAPI 2.0 (Swagger), OpenAPI 3.0.x, OpenAPI 3.1.x] + +✖ 1 problem (0 errors, 1 warning, 0 infos, 0 hints) diff --git a/linter/testcases/openapi-versie-missing/openapi.json b/linter/testcases/unrecognized-format-openapi/openapi.json similarity index 100% rename from linter/testcases/openapi-versie-missing/openapi.json rename to linter/testcases/unrecognized-format-openapi/openapi.json diff --git a/media/linter.yaml b/media/linter.yaml index 15b99e93..d92267e0 100644 --- a/media/linter.yaml +++ b/media/linter.yaml @@ -20,6 +20,9 @@ extends: - ["spectral:oas", "off"] # extend spectral:oas maar zet standaard alle regels uit +formats: + - oas3 + rules: #/core/publish-openapi (deze error-rules valideren of OAS valid is) oas3-schema: error @@ -48,6 +51,7 @@ rules: field: openapi function: truthy message: "The root of the document must contain the `openapi` property." + formats: [oas2] #/core/version-header nlgov:missing-version-header: @@ -206,9 +210,9 @@ rules: properties: type: object required: - - status - - title - - detail + - status + - title + - detail #/core/error-handling/invalid-input nlgov:problem-invalid-input: @@ -226,7 +230,7 @@ rules: responses: type: object required: - - "400" + - "400" #/core/date-time/timezone nlgov:date-time-ensure-timezone: