Skip to content

Commit 6dfc168

Browse files
committed
chore: add test for non-object intersections
Ticket: dx-2181
1 parent c5000de commit 6dfc168

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

packages/openapi-generator/test/optimize.test.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,72 @@ test('non-consolidatable unions are not consolidated', () => {
180180

181181
assert.deepEqual(optimize(input), expected);
182182
});
183+
184+
test('intersection with non-object types removes empty object', () => {
185+
const input: Schema = {
186+
type: 'intersection',
187+
schemas: [
188+
{
189+
type: 'object',
190+
properties: {},
191+
required: [],
192+
},
193+
{
194+
type: 'ref',
195+
name: 'SomeType',
196+
location: '/path/to/file.ts',
197+
},
198+
],
199+
};
200+
201+
// The empty object should be removed, leaving just the ref
202+
const expected: Schema = {
203+
type: 'ref',
204+
name: 'SomeType',
205+
location: '/path/to/file.ts',
206+
};
207+
208+
assert.deepEqual(optimize(input), expected);
209+
});
210+
211+
test('intersection with multiple non-object types removes empty object', () => {
212+
const input: Schema = {
213+
type: 'intersection',
214+
schemas: [
215+
{
216+
type: 'object',
217+
properties: {},
218+
required: [],
219+
},
220+
{
221+
type: 'ref',
222+
name: 'TypeA',
223+
location: '/path/to/file.ts',
224+
},
225+
{
226+
type: 'ref',
227+
name: 'TypeB',
228+
location: '/path/to/file.ts',
229+
},
230+
],
231+
};
232+
233+
// The empty object should be removed, leaving the intersection of refs
234+
const expected: Schema = {
235+
type: 'intersection',
236+
schemas: [
237+
{
238+
type: 'ref',
239+
name: 'TypeA',
240+
location: '/path/to/file.ts',
241+
},
242+
{
243+
type: 'ref',
244+
name: 'TypeB',
245+
location: '/path/to/file.ts',
246+
},
247+
],
248+
};
249+
250+
assert.deepEqual(optimize(input), expected);
251+
});

0 commit comments

Comments
 (0)