Skip to content

Commit e5b276f

Browse files
PrincessMadMathMathieu Gamache
andauthored
Tweak properties type validation to exclude a property call properties (#16)
Co-authored-by: Mathieu Gamache <[email protected]>
1 parent 8ce7be8 commit e5b276f

6 files changed

+21
-8
lines changed

.spectral.yaml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,20 @@ rules:
6565
values:
6666
- oauth2
6767

68-
properties-must-have-a-type:
69-
description: "All properties must have a type."
68+
schemas-properties-must-have-a-type:
69+
description: "All schemas properties must have a type."
70+
recommended: true
71+
severity: warn
72+
given: $..schemas.*.properties.*
73+
then:
74+
field: type
75+
function: truthy
76+
77+
path-schema-properties-must-have-a-type:
78+
description: "All path schema properties must have a type."
7079
recommended: true
7180
severity: warn
72-
given: $..properties.*
81+
given: $..schema.properties.*
7382
then:
7483
field: type
7584
function: truthy

TestSpecs/properties-must-have-a-type-in-schema-valid.yaml renamed to TestSpecs/schemas-properties-must-have-a-type-valid.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ components:
77
type: object
88
properties:
99
sampleProperty:
10-
type: string
10+
type: string
11+
properties:
12+
type: object
13+
additionalProperties: { }
14+
nullable: true

test.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ $tests = @(
1818
@{ rule = "must-return-content-types"; expectError = $true; filename = "must-return-content-types-invalid.yaml" },
1919
@{ rule = "must-support-client-credentials-oauth2"; expectError = $false; filename = "must-support-client-credentials-oauth2-valid.yaml" },
2020
@{ rule = "must-support-client-credentials-oauth2"; expectError = $true; filename = "must-support-client-credentials-oauth2-invalid.yaml" },
21-
@{ rule = "properties-must-have-a-type"; expectError = $false; filename = "properties-must-have-a-type-in-path-valid.yaml" },
22-
@{ rule = "properties-must-have-a-type"; expectError = $false; filename = "properties-must-have-a-type-in-schema-valid.yaml" },
23-
@{ rule = "properties-must-have-a-type"; expectError = $true; filename = "properties-must-have-a-type-in-path-invalid.yaml" },
24-
@{ rule = "properties-must-have-a-type"; expectError = $true; filename = "properties-must-have-a-type-in-schema-invalid.yaml" },
21+
@{ rule = "path-schema-properties-must-have-a-type"; expectError = $false; filename = "path-schema-properties-must-have-a-type-valid.yaml" },
22+
@{ rule = "path-schema-properties-must-have-a-type"; expectError = $true; filename = "path-schema-properties-must-have-a-type-invalid.yaml" },
23+
@{ rule = "schemas-properties-must-have-a-type"; expectError = $false; filename = "schemas-properties-must-have-a-type-valid.yaml" },
24+
@{ rule = "schemas-properties-must-have-a-type"; expectError = $true; filename = "schemas-properties-must-have-a-type-invalid.yaml" },
2525
@{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $false; filename = "schema-ids-must-have-alphanumeric-characters-only-valid.yaml" },
2626
@{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $true; filename = "schema-ids-must-have-alphanumeric-characters-only-invalid.yaml" },
2727
@{ rule = "schema-object-must-have-a-type"; expectError = $false; filename = "schema-object-must-have-a-type-valid.yaml" },

0 commit comments

Comments
 (0)