Skip to content

Commit a94cbed

Browse files
fubhygcanti
andauthored
Ignore uniqueItems when set to false while importing JSON Schema documents (#6924)
Co-authored-by: Giulio Canti <[email protected]>
1 parent 9344742 commit a94cbed

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"effect": patch
3+
---
4+
5+
Ignore `uniqueItems` when set to `false` while importing JSON Schema documents.

‎packages/effect/src/internal/schema/fromJsonSchemaDocument.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ function translateJsonSchemaMultiDocument(
814814
addNumberCheck(checks, schema.minItems, "effect/schema/isMinLength", "minLength")
815815
addNumberCheck(checks, schema.maxItems, "effect/schema/isMaxLength", "maxLength")
816816
}
817-
if (typeof schema.uniqueItems === "boolean") {
817+
if (schema.uniqueItems === true) {
818818
checks.push(jsonSchemaFilter("effect/schema/isUnique", null))
819819
}
820820
return checks

‎packages/effect/test/schema/representation/fromJsonSchemaDocument.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,14 @@ describe("fromJsonSchemaDocument", () => {
17371737
}
17381738
)
17391739
})
1740+
1741+
it("does not require uniqueness when uniqueItems is false", () => {
1742+
const schema = toSchemaFromJsonSchemaDocument(
1743+
JsonSchema.fromSchemaDraft2020_12({ type: "array", uniqueItems: false })
1744+
)
1745+
1746+
assertTrue(Schema.is(schema)(["a", "a"]))
1747+
})
17401748
})
17411749
})
17421750

0 commit comments

Comments
 (0)