diff --git a/.spectral.yaml b/.spectral.yaml index 98e0100..047649a 100644 --- a/.spectral.yaml +++ b/.spectral.yaml @@ -11,6 +11,7 @@ rules: path-params: true typed-enum: true oas3-schema: true + oas3-operation-security-defined: true must-accept-content-types: description: "All endpoint bodies MUST accept the header with (one of) Content-Type: application/json, multipart/form-data, application/octet-stream." @@ -40,15 +41,6 @@ rules: - image/png - application/octet-stream - unexpected-error-default-response: - description: "All endpoints must return a default response." - message: "{{description}}" - severity: warn - given: $.paths..responses - then: - - field: "default" - function: truthy - schema-ids-must-have-alphanumeric-characters-only: description: 'All schema ids must only contain alphanumeric characters.' given: "$.components.schemas" @@ -59,15 +51,6 @@ rules: functionOptions: match: '^[a-zA-Z0-9]+$' - must-have-security-schemes: - description: "Contract must have a security scheme." - recommended: true - severity: warn - given: $.components - then: - field: securitySchemes - function: truthy - must-support-client-credentials-oauth2: description: "Contract must support client credentials with oauth2." recommended: true diff --git a/TestSpecs/must-have-security-schemes-invalid.yaml b/TestSpecs/must-have-security-schemes-invalid.yaml deleted file mode 100644 index e934fc3..0000000 --- a/TestSpecs/must-have-security-schemes-invalid.yaml +++ /dev/null @@ -1,13 +0,0 @@ -openapi: 3.0.1 -info: - title: V1 API General - version: v1 -components: - schemas: - BuyItemError: - type: object - properties: - message: - type: string - nullable: true - additionalProperties: false diff --git a/TestSpecs/must-have-security-schemes-valid.yaml b/TestSpecs/must-have-security-schemes-valid.yaml deleted file mode 100644 index 7605a56..0000000 --- a/TestSpecs/must-have-security-schemes-valid.yaml +++ /dev/null @@ -1,20 +0,0 @@ -openapi: 3.0.1 -info: - title: V1 API General - version: v1 -components: - schemas: - BuyItemError: - type: object - properties: - message: - type: string - nullable: true - additionalProperties: false - securitySchemes: - oauth2: - type: oauth2 - description: This API uses OAuth 2 with the client credential flow. - flows: - clientCredentials: - tokenUrl: https://localhost:8000/oauth2/token diff --git a/TestSpecs/unexpected-error-default-response-invalid.yaml b/TestSpecs/unexpected-error-default-response-invalid.yaml deleted file mode 100644 index 8ad68c4..0000000 --- a/TestSpecs/unexpected-error-default-response-invalid.yaml +++ /dev/null @@ -1,26 +0,0 @@ -openapi: 3.0.1 -info: - title: V1 API General - version: v1 -paths: - /buy-item: - post: - tags: - - Shop - summary: Buy an item - operationId: BuyItem - responses: - '200': - description: Success - content: - application/json: - schema: - required: - - itemName - type: object - properties: - itemName: - maxLength: 200 - minLength: 1 - type: string - additionalProperties: false diff --git a/TestSpecs/unexpected-error-default-response-valid.yaml b/TestSpecs/unexpected-error-default-response-valid.yaml deleted file mode 100644 index 8cf271b..0000000 --- a/TestSpecs/unexpected-error-default-response-valid.yaml +++ /dev/null @@ -1,27 +0,0 @@ -openapi: 3.0.1 -info: - title: V1 API General - version: v1 -paths: - /buy-item: - post: - tags: - - Shop - summary: Buy an item - operationId: BuyItem - responses: - '200': - description: Success - content: - application/json: - schema: - required: - - itemName - type: object - properties: - itemName: - maxLength: 200 - minLength: 1 - type: string - additionalProperties: false - default: '201' \ No newline at end of file diff --git a/test.ps1 b/test.ps1 index 8a0c029..8a10e66 100644 --- a/test.ps1 +++ b/test.ps1 @@ -14,8 +14,6 @@ $tests = @( @{ rule = "items-must-have-a-type"; expectError = $true; filename = "items-must-have-a-type-invalid.yaml" }, @{ rule = "must-accept-content-types"; expectError = $false; filename = "must-accept-content-types-valid.yaml" }, @{ rule = "must-accept-content-types"; expectError = $true; filename = "must-accept-content-types-invalid.yaml" }, - @{ rule = "must-have-security-schemes"; expectError = $false; filename = "must-have-security-schemes-valid.yaml" }, - @{ rule = "must-have-security-schemes"; expectError = $true; filename = "must-have-security-schemes-invalid.yaml" }, @{ rule = "must-return-content-types"; expectError = $false; filename = "must-return-content-types-valid.yaml" }, @{ rule = "must-return-content-types"; expectError = $true; filename = "must-return-content-types-invalid.yaml" }, @{ rule = "must-support-client-credentials-oauth2"; expectError = $false; filename = "must-support-client-credentials-oauth2-valid.yaml" }, @@ -27,9 +25,7 @@ $tests = @( @{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $false; filename = "schema-ids-must-have-alphanumeric-characters-only-valid.yaml" }, @{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $true; filename = "schema-ids-must-have-alphanumeric-characters-only-invalid.yaml" }, @{ rule = "schema-object-must-have-a-type"; expectError = $false; filename = "schema-object-must-have-a-type-valid.yaml" }, - @{ rule = "schema-object-must-have-a-type"; expectError = $true; filename = "schema-object-must-have-a-type-invalid.yaml" }, - @{ rule = "unexpected-error-default-response"; expectError = $false; filename = "unexpected-error-default-response-valid.yaml" }, - @{ rule = "unexpected-error-default-response"; expectError = $true; filename = "unexpected-error-default-response-invalid.yaml" } + @{ rule = "schema-object-must-have-a-type"; expectError = $true; filename = "schema-object-must-have-a-type-invalid.yaml" } ) $fileCount = Get-ChildItem (Join-Path $PSScriptRoot "TestSpecs") | Measure-Object | Select-Object -ExpandProperty Count @@ -70,3 +66,4 @@ foreach ($test in $tests) { } Write-Host -ForegroundColor Green "All tests passed" +exit 0 \ No newline at end of file