Skip to content

Commit cd4cdf7

Browse files
Merge pull request #543 from bitgopatmcl/handle-undefined-codec
Correctly handle `t.undefined` in openapi-generator
2 parents e7fee24 + 1991275 commit cd4cdf7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/openapi-generator/src/knownImports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const KNOWN_IMPORTS: KnownImports = {
3030
number: () => E.right({ type: 'primitive', value: 'number' }),
3131
boolean: () => E.right({ type: 'primitive', value: 'boolean' }),
3232
null: () => E.right({ type: 'primitive', value: 'null' }),
33+
undefined: () => E.right({ type: 'undefined' }),
3334
array: (_, innerSchema) => E.right({ type: 'array', items: innerSchema }),
3435
readonlyArray: (_, innerSchema) => E.right({ type: 'array', items: innerSchema }),
3536
type: (_, schema) => {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,15 @@ testCase('null literal type is parsed', NULL_LITERAL, {
322322
FOO: { type: 'literal', kind: 'null', value: null },
323323
});
324324

325+
const UNDEFINED_LITERAL = `
326+
import * as t from 'io-ts';
327+
export const FOO = t.undefined;
328+
`;
329+
330+
testCase('undefined literal type is parsed', UNDEFINED_LITERAL, {
331+
FOO: { type: 'undefined' },
332+
});
333+
325334
const KEYOF = `
326335
import * as t from 'io-ts';
327336
export const FOO = t.keyof({ foo: null, bar: null });

0 commit comments

Comments
 (0)