fork of hey-api/openapi-ts because I need some additional things
1import { deduplicateSchema } from '../schema';
2import type { IR } from '../types';
3
4describe('deduplicateSchema', () => {
5 const scenarios: ReadonlyArray<{
6 description: string;
7 detectFormat?: boolean;
8 result: IR.SchemaObject;
9 schema: IR.SchemaObject;
10 }> = [
11 {
12 description: 'keeps multiple strings if they have different formats',
13 result: {
14 items: [
15 {
16 format: 'uuid',
17 type: 'string',
18 },
19 {
20 type: 'string',
21 },
22 ],
23 logicalOperator: 'or',
24 },
25 schema: {
26 items: [
27 {
28 format: 'uuid',
29 type: 'string',
30 },
31 {
32 type: 'string',
33 },
34 ],
35 logicalOperator: 'or',
36 },
37 },
38 {
39 description:
40 'discards duplicate strings if they have different formats and `detectFormat` is `false`',
41 detectFormat: false,
42 result: {
43 format: 'uuid',
44 type: 'string',
45 },
46 schema: {
47 items: [
48 {
49 format: 'uuid',
50 type: 'string',
51 },
52 {
53 type: 'string',
54 },
55 ],
56 logicalOperator: 'or',
57 },
58 },
59 ];
60
61 it.each(scenarios)('$description', ({ detectFormat, result, schema }) => {
62 expect(deduplicateSchema({ detectFormat, schema })).toEqual(result);
63 });
64});