Skip to content

Commit a3ed6c1

Browse files
authored
Merge pull request #903 from 0xthierry/fix/additional-properties-for-typebox-record
fix: typebox object schemas without properties key
2 parents 4db10c1 + 6806347 commit a3ed6c1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/compose.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const hasAdditionalProperties = (
7979
const properties = schema.properties as Record<string, TAnySchema>
8080

8181
if ('additionalProperties' in schema) return schema.additionalProperties
82+
if ('patternProperties' in schema) return false
8283

8384
for (const key of Object.keys(properties)) {
8485
const property = properties[key]

test/core/compose.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { describe, expect, it } from 'bun:test'
2+
import { Type } from '@sinclair/typebox'
3+
import { hasAdditionalProperties } from '../../src/compose'
4+
5+
describe('hasAdditionalProperties', () => {
6+
it('should handle object schemas without properties key', () => {
7+
const schema = Type.Intersect([
8+
Type.Object({ a: Type.String() }),
9+
// Record schemas does not have properties key, instead it has patternProperties
10+
Type.Record(Type.Number(), Type.String())
11+
])
12+
expect(hasAdditionalProperties(schema)).toBe(false)
13+
})
14+
})

0 commit comments

Comments
 (0)