Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/json-schema-never-additional-properties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

Emit `additionalProperties: false` for records with string keys and `Schema.Never` values.
5 changes: 4 additions & 1 deletion packages/effect/src/JSONSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ function go(
const parameter = is.parameter
switch (parameter._tag) {
case "StringKeyword": {
output.additionalProperties = go(
const additionalProperties = go(
pruned,
$defs,
"handle-identifier",
Expand All @@ -852,6 +852,9 @@ function go(
"handle-annotation",
errors
)
output.additionalProperties = isNeverWithoutCustomAnnotations(additionalProperties)
? false
: additionalProperties
break
}
case "TemplateLiteral": {
Expand Down
12 changes: 12 additions & 0 deletions packages/effect/test/Schema/JSONSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2149,6 +2149,18 @@ details: Cannot encode Symbol(effect/Schema/test/a) key to JSON Schema`
})
})

it("Record(string, never)", () => {
const jsonSchema = expectJSONSchema(Schema.Record({ key: Schema.String, value: Schema.Never }), {
"type": "object",
"properties": {},
"required": [],
"additionalProperties": false
})
const validate = getAjvValidate(jsonSchema)
assertTrue(validate({}))
assertFalse(validate({ a: null }))
})

it("Record('a' | 'b', number)", () => {
expectJSONSchemaAnnotations(
Schema.Record(
Expand Down
Loading