Skip to content

Commit 8d610ad

Browse files
author
Ansh Chaturvedi
committed
fix: add tests to test union optimize fn
1 parent edc41cf commit 8d610ad

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,39 @@ test('comments are exposed in objects', () => {
144144

145145
assert.deepEqual(optimize(input), expected);
146146
});
147+
148+
test('consolidatable unions are consolidated to single primitive type', () => {
149+
const input: Schema = {
150+
type: 'union',
151+
schemas: [
152+
{ type: 'string', enum: ['true', 'false'], decodedType: 'boolean' },
153+
{ type: 'boolean', primitive: true },
154+
],
155+
required: [],
156+
};
157+
158+
const expected: Schema = { type: 'boolean', };
159+
160+
assert.deepEqual(optimize(input), expected);
161+
});
162+
163+
test('non-consolidatable unions are not consolidated', () => {
164+
const input: Schema = {
165+
type: 'union',
166+
schemas: [
167+
{ type: 'string', enum: ['true', 'false'], decodedType: 'boolean' },
168+
{ type: 'string', primitive: true },
169+
],
170+
required: [],
171+
};
172+
173+
const expected: Schema = {
174+
type: 'union',
175+
schemas: [
176+
{ type: 'string', primitive: true },
177+
{ type: 'string', enum: [ 'true', 'false' ] },
178+
]
179+
};
180+
181+
assert.deepEqual(optimize(input), expected);
182+
});

0 commit comments

Comments
 (0)