Skip to content

Commit b7b4418

Browse files
Copilotsalliegsoft
andauthored
Fix type-checking rules to accept $ref as valid type specification (#42)
* Initial plan * Fix items-must-have-a-type rule to accept $ref as valid type specification Co-authored-by: salliegsoft <[email protected]> * Apply same fix to schemas-properties and path-schema-properties rules Co-authored-by: salliegsoft <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: salliegsoft <[email protected]>
1 parent 6379116 commit b7b4418

File tree

5 files changed

+80
-9
lines changed

5 files changed

+80
-9
lines changed

.workleap.rules.yaml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,32 @@ rules:
2626
match: '^[a-zA-Z0-9]+$'
2727

2828
schemas-properties-must-have-a-type:
29-
description: "All schemas properties must have a type. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#schemas-properties-must-have-a-type-and-path-schema-properties-must-have-a-type"
29+
description: "All schemas properties must have a type or schema reference. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#schemas-properties-must-have-a-type-and-path-schema-properties-must-have-a-type"
3030
recommended: true
3131
severity: warn
3232
given: $..schemas.*.properties.*
3333
then:
34-
field: type
35-
function: truthy
34+
- function: truthy
35+
- function: schema
36+
functionOptions:
37+
schema:
38+
anyOf:
39+
- required: ["type"]
40+
- required: ["$ref"]
3641

3742
path-schema-properties-must-have-a-type:
38-
description: "All path schema properties must have a type. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#schemas-properties-must-have-a-type-and-path-schema-properties-must-have-a-type"
43+
description: "All path schema properties must have a type or schema reference. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#schemas-properties-must-have-a-type-and-path-schema-properties-must-have-a-type"
3944
recommended: true
4045
severity: warn
4146
given: $..schema.properties.*
4247
then:
43-
field: type
44-
function: truthy
48+
- function: truthy
49+
- function: schema
50+
functionOptions:
51+
schema:
52+
anyOf:
53+
- required: ["type"]
54+
- required: ["$ref"]
4555

4656
schema-object-must-have-a-type:
4757
description: "All properties must have a type. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#schema-object-must-have-a-type"
@@ -53,13 +63,18 @@ rules:
5363
function: truthy
5464

5565
items-must-have-a-type:
56-
description: "All items must have a type. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#items-must-have-a-type"
66+
description: "All items must have a type or schema reference. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#items-must-have-a-type"
5767
recommended: true
5868
severity: warn
5969
given: $.components.schemas..items
6070
then:
61-
field: type
62-
function: truthy
71+
- function: truthy
72+
- function: schema
73+
functionOptions:
74+
schema:
75+
anyOf:
76+
- required: ["type"]
77+
- required: ["$ref"]
6378

6479
schema-name-length-must-be-short:
6580
description: "Schema name must not be too long to support client generation. Current limitation comes from Ruby packages which uses tar and has a limit of 100 characters. Refer to: https://gsoftdev.atlassian.net/wiki/spaces/TEC/pages/3858235678/IDP+OpenAPI+Rulesets#schema-name-length-must-be-short"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
openapi: 3.0.1
2+
info:
3+
title: dummy
4+
components:
5+
schemas:
6+
ExploreGoalsQueryResult:
7+
type: object
8+
properties:
9+
id:
10+
type: string
11+
SubGoalsContainer:
12+
type: array
13+
items:
14+
$ref: '#/components/schemas/ExploreGoalsQueryResult'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
openapi: 3.0.1
2+
info:
3+
title: dummy
4+
paths:
5+
/test:
6+
get:
7+
operationId: getTest
8+
responses:
9+
'200':
10+
description: Success
11+
content:
12+
application/json:
13+
schema:
14+
type: object
15+
properties:
16+
refProperty:
17+
$ref: '#/components/schemas/ReferencedSchema'
18+
components:
19+
schemas:
20+
ReferencedSchema:
21+
type: object
22+
properties:
23+
id:
24+
type: string
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
openapi: 3.0.1
2+
info:
3+
title: dummy
4+
components:
5+
schemas:
6+
ReferencedSchema:
7+
type: object
8+
properties:
9+
id:
10+
type: string
11+
SampleObject:
12+
type: object
13+
properties:
14+
refProperty:
15+
$ref: '#/components/schemas/ReferencedSchema'

test.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ $ruleset = Join-Path $PSScriptRoot ".workleap.rules.yaml"
99

1010
$testSpecs = @(
1111
@{ rule = "items-must-have-a-type"; expectError = $false; filename = "items-must-have-a-type-valid.yaml" },
12+
@{ rule = "items-must-have-a-type"; expectError = $false; filename = "items-must-have-a-type-valid-ref.yaml" },
1213
@{ rule = "items-must-have-a-type"; expectError = $true; filename = "items-must-have-a-type-invalid.yaml" },
1314
@{ rule = "must-accept-content-types"; expectError = $false; filename = "must-accept-content-types-valid.yaml" },
1415
@{ rule = "must-accept-content-types"; expectError = $true; filename = "must-accept-content-types-invalid.yaml" },
@@ -21,8 +22,10 @@ $testSpecs = @(
2122
@{ rule = "must-use-get-post-methods"; expectError = $false; filename = "must-use-get-post-methods-valid.yaml" },
2223
@{ rule = "must-use-get-post-methods"; expectError = $true; filename = "must-use-get-post-methods-invalid.yaml" },
2324
@{ rule = "path-schema-properties-must-have-a-type"; expectError = $false; filename = "path-schema-properties-must-have-a-type-valid.yaml" },
25+
@{ rule = "path-schema-properties-must-have-a-type"; expectError = $false; filename = "path-schema-properties-must-have-a-type-valid-ref.yaml" },
2426
@{ rule = "path-schema-properties-must-have-a-type"; expectError = $true; filename = "path-schema-properties-must-have-a-type-invalid.yaml" },
2527
@{ rule = "schemas-properties-must-have-a-type"; expectError = $false; filename = "schemas-properties-must-have-a-type-valid.yaml" },
28+
@{ rule = "schemas-properties-must-have-a-type"; expectError = $false; filename = "schemas-properties-must-have-a-type-valid-ref.yaml" },
2629
@{ rule = "schemas-properties-must-have-a-type"; expectError = $true; filename = "schemas-properties-must-have-a-type-invalid.yaml" },
2730
@{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $false; filename = "schema-ids-must-have-alphanumeric-characters-only-valid.yaml" },
2831
@{ rule = "schema-ids-must-have-alphanumeric-characters-only"; expectError = $true; filename = "schema-ids-must-have-alphanumeric-characters-only-invalid.yaml" },

0 commit comments

Comments
 (0)