Skip to content

Commit 90a7c1e

Browse files
authored
fix(openapi): support strict object schema for dynamic params (#814)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of object schemas with the `additionalProperties` attribute, ensuring correct separation of properties while preserving the `additionalProperties` flag. * **Tests** * Added a new test case to verify correct behavior when separating object schemas that include `additionalProperties: true`. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 3beb06e commit 90a7c1e

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

packages/openapi/src/schema-utils.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,40 @@ describe('separateObjectSchema', () => {
7878
})
7979
})
8080

81+
it('can separate if contains additionalProperties', () => {
82+
const schema: ObjectSchema = {
83+
type: 'object',
84+
description: 'description',
85+
properties: {
86+
a: { type: 'string' },
87+
b: { type: 'string' },
88+
},
89+
required: ['a'],
90+
additionalProperties: true,
91+
}
92+
93+
const [matched, rest] = separateObjectSchema(schema, ['a'])
94+
95+
expect(matched).toEqual({
96+
type: 'object',
97+
description: 'description',
98+
properties: {
99+
a: { type: 'string' },
100+
},
101+
required: ['a'],
102+
additionalProperties: true,
103+
})
104+
expect(rest).toEqual({
105+
type: 'object',
106+
description: 'description',
107+
properties: {
108+
b: { type: 'string' },
109+
},
110+
required: [],
111+
additionalProperties: true,
112+
})
113+
})
114+
81115
it('not separate when contain not allow keyword', () => {
82116
const schema: ObjectSchema = {
83117
type: 'object',

packages/openapi/src/schema-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export function isAnySchema(schema: JSONSchema): boolean {
3535
* @internal
3636
*/
3737
export function separateObjectSchema(schema: ObjectSchema, separatedProperties: string[]): [matched: ObjectSchema, rest: ObjectSchema] {
38-
if (Object.keys(schema).some(k => k !== 'type' && k !== 'properties' && k !== 'required' && LOGIC_KEYWORDS.includes(k))) {
38+
if (Object.keys(schema).some(k => k !== 'type' && k !== 'properties' && k !== 'required' && k !== 'additionalProperties' && LOGIC_KEYWORDS.includes(k))) {
3939
return [{ type: 'object' }, schema]
4040
}
4141

0 commit comments

Comments
 (0)