Skip to content

Commit

Permalink
restrict arrays as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Oct 29, 2024
1 parent 000bc0d commit 40082b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,20 @@ class V1Validator {
}


if (prop.items) this.validateTypedInterface(prop.items)
if (prop.items) {
this.validateTypedInterface(prop.items)

// here we are adding some extra constraints on the value type
// we can relax these later when we can ensure we can cast these properly
this.location.push('items')
if (prop.items.items) {
this.recordError("Arrays are currently not supported as element types of arrays")
}
if (prop.items.additionalProperties) {
this.recordError("Maps are currently not supported as element types of arrays")
}
this.location.pop()
}

if (prop.additionalProperties) {
this.validateTypedInterface(prop.additionalProperties)
Expand All @@ -131,12 +144,11 @@ class V1Validator {
// we can relax these later when we can ensure we can cast these properly
this.location.push('additionalProperties')
if (prop.additionalProperties.items) {
this.recordError("Arrays are currently not supported for value types of maps")
this.recordError("Arrays are currently not supported as value types of maps")
}
if (prop.additionalProperties.additionalProperties) {
this.recordError("Maps are currently not supported for value types of maps")
this.recordError("Maps are currently not supported as value types of maps")
}

this.location.pop()
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ test("parse-invalid-v1-document", () => {
expect(errors).toBeInstanceOf(Array)

const paths = errors!.map(e => e.path)
//console.log(JSON.stringify(errors!, null, 4))
expect(paths).toStrictEqual([
"#/exports/invalidFunc1/input",
"#/exports/invalidFunc1/output",
Expand All @@ -27,6 +28,7 @@ test("parse-invalid-v1-document", () => {
"#/components/schemas/ComplexObject/properties/aMapOfMapsOfNullableDateArrays/additionalProperties",
"#/components/schemas/ComplexObject/properties/aMapOfMapsOfNullableDateArrays/additionalProperties",
"#/components/schemas/ComplexObject/properties/aMapOfMapsOfNullableDateArrays/additionalProperties/additionalProperties",
"#/components/schemas/ComplexObject/properties/anArrayOfMaps/items",
])
})

Expand Down
6 changes: 6 additions & 0 deletions tests/schemas/v1-invalid-doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ components:
nullable: true
type: string
format: date-time
anArrayOfMaps:
description: an illegal array of maps
items:
additionalProperties:
type: string
format: date-time

0 comments on commit 40082b9

Please sign in to comment.