Skip to content

Commit

Permalink
Feature/idp-1051_Update_spectral_rules_2 (#14)
Browse files Browse the repository at this point in the history
* Replace security scheme by spectral equivalent rule

* Remove default result rule

* Fix exit code
  • Loading branch information
decarufe authored Mar 20, 2024
1 parent e4013f9 commit 7854d03
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 109 deletions.
19 changes: 1 addition & 18 deletions .spectral.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
13 changes: 0 additions & 13 deletions TestSpecs/must-have-security-schemes-invalid.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions TestSpecs/must-have-security-schemes-valid.yaml

This file was deleted.

26 changes: 0 additions & 26 deletions TestSpecs/unexpected-error-default-response-invalid.yaml

This file was deleted.

27 changes: 0 additions & 27 deletions TestSpecs/unexpected-error-default-response-valid.yaml

This file was deleted.

7 changes: 2 additions & 5 deletions test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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
Expand Down Expand Up @@ -70,3 +66,4 @@ foreach ($test in $tests) {
}

Write-Host -ForegroundColor Green "All tests passed"
exit 0

0 comments on commit 7854d03

Please sign in to comment.