fix(middleware-io): don't throw an error if unknown tag was found
MODIFY
packages/middleware-io/src/io.json-schema.ts
packages/middleware-io/src/io.json-schema.ts
@@ -20,6 +20,7 @@ enum IoTag {
DICTIONARY = 'DictionaryType',
REFINEMENT = 'RefinementType',
CUSTOM_JSON_SCHEMA = 'CustomJsonSchemaType',
+ UNKNOWN = 'UnknownType',
}
type IoConverter = (type: any, supertypes: any[]) => any;
@@ -131,13 +132,13 @@ const IoTypes: Record<IoTag, IoConverter> = {
[IoTag.CUSTOM_JSON_SCHEMA]: (type: CustomJsonSchemaType<any, any>) =>
type.jsonSchema,
+
+ [IoTag.UNKNOWN]: () => ({ type: 'object' }),
};
export const getTag = (ioType: t.Any): IoTag => {
const tag = (ioType as any)._tag;
- if (!IoTypes[tag]) {
- throw new Error(`Unsupported type with tag: ${tag}\n${JSON.stringify(ioType, null, 2)}`);
- }
+ if (!IoTypes[tag]) return IoTag.UNKNOWN;
return tag;
};

MODIFY
packages/middleware-io/src/specs/io.json-schema.spec.ts
packages/middleware-io/src/specs/io.json-schema.spec.ts
@@ -187,10 +187,12 @@ describe('#ioTypeToJsonSchema', () => {
expect(ioTypeToJsonSchema(undefined)).toBe(undefined);
});
- test('throws an error on unknown io-ts type', () => {
- expect(() => ioTypeToJsonSchema({
- _tag: 'this is not a valid type'
- } as any)).toThrow('Unsupported type');
+ test('fallbacks to "object" if codec is not supported', () => {
+ expect(ioTypeToJsonSchema({
+ _tag: 'some custom type',
+ } as any)).toEqual({
+ type: 'object',
+ });
});
});

fix(middleware-io): don't throw an error if unknown tag was found