Skip to content

Commit edc41cf

Browse files
author
Ansh Chaturvedi
committed
fix: fix tests to match primitive field
Ticket: DX-614
1 parent eb71404 commit edc41cf

File tree

5 files changed

+85
-70
lines changed

5 files changed

+85
-70
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ testCase('simple api spec', SIMPLE, '/index.ts', {
8080
path: '/test',
8181
method: 'GET',
8282
parameters: [],
83-
response: { 200: { type: 'string' } },
83+
response: { 200: { type: 'string', primitive: true } },
8484
},
8585
],
8686
});
@@ -112,7 +112,7 @@ testCase('const route reference', ROUTE_REF, '/index.ts', {
112112
path: '/test',
113113
method: 'GET',
114114
parameters: [],
115-
response: { 200: { type: 'string' } },
115+
response: { 200: { type: 'string', primitive: true } },
116116
},
117117
],
118118
});
@@ -144,7 +144,7 @@ testCase('const action reference', ACTION_REF, '/index.ts', {
144144
path: '/test',
145145
method: 'GET',
146146
parameters: [],
147-
response: { 200: { type: 'string' } },
147+
response: { 200: { type: 'string', primitive: true } },
148148
},
149149
],
150150
});
@@ -182,7 +182,7 @@ testCase('spread api spec', SPREAD, '/index.ts', {
182182
path: '/test',
183183
method: 'GET',
184184
parameters: [],
185-
response: { 200: { type: 'string' } },
185+
response: { 200: { type: 'string', primitive: true } },
186186
},
187187
],
188188
});
@@ -216,7 +216,7 @@ testCase('computed property api spec', COMPUTED_PROPERTY, '/index.ts', {
216216
path: '/test',
217217
method: 'GET',
218218
parameters: [],
219-
response: { 200: { type: 'string' } },
219+
response: { 200: { type: 'string', primitive: true } },
220220
},
221221
],
222222
});

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

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const FOO = t.number;
4646
`;
4747

4848
testCase('simple codec is parsed', SIMPLE, {
49-
FOO: { type: 'number' },
49+
FOO: { type: 'number', primitive: true },
5050
});
5151

5252
const DIRECT = `
@@ -55,7 +55,7 @@ export const FOO = number;
5555
`;
5656

5757
testCase('direct import is parsed', DIRECT, {
58-
FOO: { type: 'number' },
58+
FOO: { type: 'number', primitive: true },
5959
});
6060

6161
const TYPE = `
@@ -66,7 +66,7 @@ export const FOO = t.type({ foo: t.number });
6666
testCase('type is parsed', TYPE, {
6767
FOO: {
6868
type: 'object',
69-
properties: { foo: { type: 'number' } },
69+
properties: { foo: { type: 'number', primitive: true } },
7070
required: ['foo'],
7171
},
7272
});
@@ -79,7 +79,7 @@ export const FOO = t.partial({ foo: t.number });
7979
testCase('partial type is parsed', PARTIAL, {
8080
FOO: {
8181
type: 'object',
82-
properties: { foo: { type: 'number' } },
82+
properties: { foo: { type: 'number', primitive: true } },
8383
required: [],
8484
},
8585
});
@@ -91,10 +91,10 @@ export const FOO = t.type({ bar });
9191
`;
9292

9393
testCase('shorthand property is parsed', SHORTHAND_PROPERTY, {
94-
bar: { type: 'number' },
94+
bar: { type: 'number', primitive: true },
9595
FOO: {
9696
type: 'object',
97-
properties: { bar: { type: 'number' } },
97+
properties: { bar: { type: 'number', primitive: true } },
9898
required: ['bar'],
9999
},
100100
});
@@ -110,14 +110,14 @@ export const TEST = t.type({ ...foo, bar: t.string });
110110
testCase('spread property is parsed', SPREAD_PROPERTY, {
111111
foo: {
112112
type: 'object',
113-
properties: { foo: { type: 'number' } },
113+
properties: { foo: { type: 'number', primitive: true } },
114114
required: ['foo'],
115115
},
116116
TEST: {
117117
type: 'object',
118118
properties: {
119-
foo: { type: 'number' },
120-
bar: { type: 'string' },
119+
foo: { type: 'number', primitive: true },
120+
bar: { type: 'string', primitive: true },
121121
},
122122
required: ['foo', 'bar'],
123123
},
@@ -132,12 +132,12 @@ export const FOO = t.type(props);
132132
testCase('const assertion is parsed', CONST_ASSERTION, {
133133
FOO: {
134134
type: 'object',
135-
properties: { foo: { type: 'number' } },
135+
properties: { foo: { type: 'number', primitive: true } },
136136
required: ['foo'],
137137
},
138138
props: {
139139
type: 'object',
140-
properties: { foo: { type: 'number' } },
140+
properties: { foo: { type: 'number', primitive: true } },
141141
required: ['foo'],
142142
},
143143
});
@@ -153,12 +153,12 @@ export const FOO = t.type({
153153
testCase('spread const assertion is parsed', SPREAD_CONST_ASSERTION, {
154154
FOO: {
155155
type: 'object',
156-
properties: { foo: { type: 'number' } },
156+
properties: { foo: { type: 'number', primitive: true } },
157157
required: ['foo'],
158158
},
159159
props: {
160160
type: 'object',
161-
properties: { foo: { type: 'number' } },
161+
properties: { foo: { type: 'number', primitive: true } },
162162
required: ['foo'],
163163
},
164164
});
@@ -172,12 +172,12 @@ export const FOO = t.type(props);
172172
testCase('as assertion is parsed', AS_ASSERTION, {
173173
FOO: {
174174
type: 'object',
175-
properties: { foo: { type: 'number' } },
175+
properties: { foo: { type: 'number', primitive: true } },
176176
required: ['foo'],
177177
},
178178
props: {
179179
type: 'object',
180-
properties: { foo: { type: 'number' } },
180+
properties: { foo: { type: 'number', primitive: true } },
181181
required: ['foo'],
182182
},
183183
});
@@ -193,12 +193,12 @@ export const FOO = t.type({
193193
testCase('spread const assertion is parsed', SPREAD_AS_ASSERTION, {
194194
FOO: {
195195
type: 'object',
196-
properties: { foo: { type: 'number' } },
196+
properties: { foo: { type: 'number', primitive: true } },
197197
required: ['foo'],
198198
},
199199
props: {
200200
type: 'object',
201-
properties: { foo: { type: 'number' } },
201+
properties: { foo: { type: 'number', primitive: true } },
202202
required: ['foo'],
203203
},
204204
});
@@ -209,7 +209,7 @@ export const FOO = t.array(t.number);
209209
`;
210210

211211
testCase('array type is parsed', ARRAY, {
212-
FOO: { type: 'array', items: { type: 'number' } },
212+
FOO: { type: 'array', items: { type: 'number', primitive: true } },
213213
});
214214

215215
const UNION = `
@@ -220,7 +220,7 @@ export const FOO = t.union([t.string, t.number]);
220220
testCase('union type is parsed', UNION, {
221221
FOO: {
222222
type: 'union',
223-
schemas: [{ type: 'string' }, { type: 'number' }],
223+
schemas: [{ type: 'string', primitive: true }, { type: 'number', primitive: true }],
224224
},
225225
});
226226

@@ -235,11 +235,11 @@ export const FOO = t.union([...common, t.number]);
235235
testCase('union type with spread is parsed', UNION_SPREAD, {
236236
FOO: {
237237
type: 'union',
238-
schemas: [{ type: 'string' }, { type: 'number' }],
238+
schemas: [{ type: 'string', primitive: true }, { type: 'number', primitive: true }],
239239
},
240240
common: {
241241
type: 'tuple',
242-
schemas: [{ type: 'string' }],
242+
schemas: [{ type: 'string', primitive: true }],
243243
},
244244
});
245245

@@ -252,7 +252,7 @@ export const FOO = t.union([...[t.string], t.number]);
252252
testCase('union type with inline spread is parsed', UNION_INLINE_SPREAD, {
253253
FOO: {
254254
type: 'union',
255-
schemas: [{ type: 'string' }, { type: 'number' }],
255+
schemas: [{ type: 'string', primitive: true }, { type: 'number', primitive: true }],
256256
},
257257
});
258258

@@ -267,12 +267,12 @@ testCase('intersection type is parsed', INTERSECTION, {
267267
schemas: [
268268
{
269269
type: 'object',
270-
properties: { foo: { type: 'number' } },
270+
properties: { foo: { type: 'number', primitive: true } },
271271
required: ['foo'],
272272
},
273273
{
274274
type: 'object',
275-
properties: { bar: { type: 'string' } },
275+
properties: { bar: { type: 'string', primitive: true } },
276276
required: [],
277277
},
278278
],
@@ -285,7 +285,7 @@ export const FOO = t.record(t.string, t.number);
285285
`;
286286

287287
testCase('record type is parsed', RECORD, {
288-
FOO: { type: 'record', codomain: { type: 'number' } },
288+
FOO: { type: 'record', codomain: { type: 'number', primitive: true } },
289289
});
290290

291291
const ENUM = `
@@ -381,7 +381,7 @@ export const FOO = test;
381381
`;
382382

383383
testCase('aliased import is parsed', ALIAS, {
384-
FOO: { type: 'string' },
384+
FOO: { type: 'string', primitive: true },
385385
});
386386

387387
const BRAND = `
@@ -394,7 +394,7 @@ export const FOO = t.brand(t.string, (s): s is FooBranded => s === 'foo', 'Foo')
394394
`;
395395

396396
testCase('brand type is parsed', BRAND, {
397-
FOO: { type: 'string' },
397+
FOO: { type: 'string', primitive: true },
398398
});
399399

400400
const LOCAL_REF = `
@@ -406,7 +406,7 @@ export const BAR = t.type({ bar: FOO });
406406
testCase('local ref is parsed', LOCAL_REF, {
407407
FOO: {
408408
type: 'object',
409-
properties: { foo: { type: 'number' } },
409+
properties: { foo: { type: 'number', primitive: true } },
410410
required: ['foo'],
411411
},
412412
BAR: {
@@ -425,7 +425,7 @@ export const BAR = t.type({ bar: FOO });
425425
testCase('local exported ref is parsed', LOCAL_EXPORTED_REF, {
426426
FOO: {
427427
type: 'object',
428-
properties: { foo: { type: 'number' } },
428+
properties: { foo: { type: 'number', primitive: true } },
429429
required: ['foo'],
430430
},
431431
BAR: {
@@ -476,6 +476,7 @@ export const FOO = t.number;
476476
testCase('declaration comment is parsed', DECLARATION_COMMENT, {
477477
FOO: {
478478
type: 'number',
479+
primitive: true,
479480
comment: {
480481
description: 'Test codec',
481482
tags: [],
@@ -553,7 +554,8 @@ testCase(
553554
DECLARATION_COMMENT_WITHOUT_LINE_BREAK,
554555
{
555556
FOO: {
556-
type: 'number',
557+
type: 'number',
558+
primitive: true,
557559
comment: {
558560
description: 'Test codec',
559561
tags: [],
@@ -633,6 +635,7 @@ testCase('first property comment is parsed', FIRST_PROPERTY_COMMENT, {
633635
properties: {
634636
foo: {
635637
type: 'number',
638+
primitive: true,
636639
comment: {
637640
description: 'this is a comment',
638641
problems: [],
@@ -677,9 +680,10 @@ testCase('second property comment is parsed', SECOND_PROPERTY_COMMENT, {
677680
FOO: {
678681
type: 'object',
679682
properties: {
680-
foo: { type: 'number' },
683+
foo: { type: 'number', primitive: true },
681684
bar: {
682-
type: 'string',
685+
type: 'string',
686+
primitive: true,
683687
comment: {
684688
description: 'this is a comment',
685689
problems: [],
@@ -720,7 +724,7 @@ export const FOO = h.optional(t.string);
720724
testCase('optional combinator is parsed', OPTIONAL_COMBINATOR, {
721725
FOO: {
722726
type: 'union',
723-
schemas: [{ type: 'string' }, { type: 'undefined' }],
727+
schemas: [{ type: 'string', primitive: true }, { type: 'undefined' }],
724728
},
725729
});
726730

@@ -737,10 +741,10 @@ testCase('optionalized combinator is parsed', OPTIONALIZED_COMBINATOR, {
737741
FOO: {
738742
type: 'object',
739743
properties: {
740-
foo: { type: 'string' },
744+
foo: { type: 'string', primitive: true },
741745
bar: {
742746
type: 'union',
743-
schemas: [{ type: 'number' }, { type: 'undefined' }],
747+
schemas: [{ type: 'number', primitive: true }, { type: 'undefined' }],
744748
},
745749
},
746750
required: ['foo'],
@@ -766,15 +770,15 @@ testCase('httpRequest combinator is parsed', HTTP_REQUEST_COMBINATOR, {
766770
properties: {
767771
params: {
768772
type: 'object',
769-
properties: { foo: { type: 'string' } },
773+
properties: { foo: { type: 'string', primitive: true } },
770774
required: ['foo'],
771775
},
772776
query: {
773777
type: 'object',
774778
properties: {
775779
bar: {
776780
type: 'union',
777-
schemas: [{ type: 'number' }, { type: 'undefined' }],
781+
schemas: [{ type: 'number', primitive: true }, { type: 'undefined' }],
778782
},
779783
},
780784
required: [],
@@ -801,15 +805,15 @@ testCase('object property is parsed', OBJECT_PROPERTY, {
801805
FOO: {
802806
type: 'object',
803807
properties: {
804-
baz: { type: 'number' },
808+
baz: { type: 'number', primitive: true },
805809
},
806810
required: ['baz'],
807811
},
808812
props: {
809813
type: 'object',
810814
properties: {
811-
foo: { type: 'number' },
812-
bar: { type: 'string' },
815+
foo: { type: 'number', primitive: true },
816+
bar: { type: 'string', primitive: true },
813817
},
814818
required: ['foo', 'bar'],
815819
},
@@ -830,16 +834,16 @@ testCase('object assign is parsed', OBJECT_ASSIGN, {
830834
FOO: {
831835
type: 'object',
832836
properties: {
833-
foo: { type: 'number' },
834-
bar: { type: 'string' },
837+
foo: { type: 'number', primitive: true },
838+
bar: { type: 'string', primitive: true },
835839
},
836840
required: ['foo', 'bar'],
837841
},
838842
props: {
839843
type: 'object',
840844
properties: {
841-
foo: { type: 'number' },
842-
bar: { type: 'string' },
845+
foo: { type: 'number', primitive: true },
846+
bar: { type: 'string', primitive: true },
843847
},
844848
required: ['foo', 'bar'],
845849
},

0 commit comments

Comments
 (0)