Skip to content

Commit 12df131

Browse files
dinwwwhclaude
andauthored
feat(openapi)!: remove omitUndefinedProperties option from OpenAPI serializer (#2441)
## Summary The OpenAPI serializer now always omits object properties whose value is `undefined`. The `omitUndefinedProperties` option has been removed from `OpenAPIJsonSerializerOptions`, and therefore also from `OpenAPISerializer`, which passed it through. - `undefined` at the root or inside arrays still serializes to `null`, so array positions are preserved. - Removed the two tests that disabled the option, and renamed "omits undefined object properties by default" to "omits undefined object properties". ## Breaking change Passing `omitUndefinedProperties: false` is now a type error. Undefined properties that used to be serialized as `null` are now dropped. The RPC serializer (`RPCJsonSerializer`) still has its own option with the same name and is unchanged. ## Testing `pnpm format`, `pnpm check` and `pnpm test` pass. --- _Generated by [Claude Code](https://claude.ai/code/session_01VVaw7NURoYQTyieSmsdvMZ)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent ec2b626 commit 12df131

3 files changed

Lines changed: 2 additions & 22 deletions

File tree

‎packages/openapi/src/openapi-json-serializer.test.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('openAPIJsonSerializer', () => {
9999
})
100100
})
101101

102-
it('omits undefined object properties by default', () => {
102+
it('omits undefined object properties', () => {
103103
expect(serializer.serializeJson({ a: 1, b: undefined }).json).not.toHaveProperty('b')
104104
})
105105

@@ -352,11 +352,6 @@ describe('openAPIJsonSerializer', () => {
352352
])
353353
})
354354
})
355-
356-
it('can disable omitting undefined properties', () => {
357-
const custom = new OpenAPIJsonSerializer({ omitUndefinedProperties: false })
358-
expect(custom.serializeJson({ a: 1, b: undefined }).json).toEqual({ a: 1, b: null })
359-
})
360355
})
361356

362357
describe('security', () => {

‎packages/openapi/src/openapi-json-serializer.ts‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,6 @@ export interface OpenAPIJsonSerializerOptions {
133133
* Built-in type keys: `undefined`, `bigint`, `date`, `nan`, `infinity`, `url`, `set`, `map`.
134134
*/
135135
handlers?: Record<string, undefined | OpenAPIJsonSerializerHandler> | undefined
136-
137-
/**
138-
* If true, properties with undefined values will be omitted during serialization.
139-
*
140-
* @default true
141-
*/
142-
omitUndefinedProperties?: boolean | undefined
143136
}
144137

145138
/**
@@ -151,11 +144,8 @@ export interface OpenAPIJsonSerializerOptions {
151144
export class OpenAPIJsonSerializer {
152145
private readonly inlineBuiltInHandlers: boolean
153146
private readonly handlerEntries: OpenAPIJsonSerializerHandler[] | undefined
154-
private readonly omitUndefinedProperties: boolean
155147

156148
constructor(options: OpenAPIJsonSerializerOptions = {}) {
157-
this.omitUndefinedProperties = options.omitUndefinedProperties !== false
158-
159149
const customHandlers = options.handlers
160150

161151
if (customHandlers === undefined) {
@@ -323,7 +313,7 @@ export class OpenAPIJsonSerializer {
323313
continue
324314
}
325315

326-
if (v === undefined && this.omitUndefinedProperties) {
316+
if (v === undefined) {
327317
continue
328318
}
329319

‎packages/openapi/src/openapi-serializer.test.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,6 @@ describe('openAPISerializer', () => {
380380
expect(s.serialize({ value: date })).toEqual({ value: `___TEST___${date.getTime()}` })
381381
})
382382

383-
it('passes omitUndefinedProperties to OpenAPIJsonSerializer', () => {
384-
const s = new OpenAPISerializer({ omitUndefinedProperties: false })
385-
expect(s.serialize({ a: 1, b: undefined })).toEqual({ a: 1, b: null })
386-
})
387-
388383
it('passes BracketNotationSerializerOptions to BracketNotationSerializer', () => {
389384
const form = new FormData()
390385
form.append('tags[0]', 'a')

0 commit comments

Comments
 (0)