Skip to content

Commit 3600fc7

Browse files
feat(openapi-generator): add support for t.identity codec
This PR adds support for the `t.identity` codec from io-ts in the openapi-generator package, resolving the issue where consumers could not use `t.identity` in their API specifications without breaking OpenAPI spec generation. Closes Ticket: DX-1606 Co-authored-by: ericcrosson-bitgo <[email protected]>
1 parent c75b51b commit 3600fc7

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

packages/openapi-generator/src/knownImports.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export const KNOWN_IMPORTS: KnownImports = {
137137
brand: (_, arg) => E.right(arg),
138138
UnknownRecord: () => E.right({ type: 'record', codomain: { type: 'any' } }),
139139
void: () => E.right({ type: 'undefined' }),
140+
identity: (_, arg) => E.right(arg),
140141
},
141142
'io-ts-numbers': {
142143
NumberFromString: () =>

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

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ export const route = h.httpRoute({
8888
}),
8989
response: {
9090
200: {
91-
/**
92-
* Testing overridden metadata
91+
/**
92+
* Testing overridden metadata
9393
* @format string
9494
*/
9595
test: DateFromNumber
@@ -145,3 +145,74 @@ testCase('route with schema with default metadata', ROUTE_WITH_OVERIDDEN_METADAT
145145
schemas: {},
146146
},
147147
});
148+
149+
const ROUTE_WITH_IDENTITY_CODEC = `
150+
import * as t from 'io-ts';
151+
import * as h from '@api-ts/io-ts-http';
152+
153+
export const route = h.httpRoute({
154+
path: '/identity',
155+
method: 'POST',
156+
request: h.httpRequest({
157+
body: {
158+
data: t.identity(t.number)
159+
},
160+
}),
161+
response: {
162+
200: {
163+
result: t.identity(t.number)
164+
}
165+
},
166+
});
167+
`;
168+
169+
testCase('route with t.identity codec', ROUTE_WITH_IDENTITY_CODEC, {
170+
openapi: '3.0.3',
171+
info: {
172+
title: 'Test',
173+
version: '1.0.0',
174+
},
175+
paths: {
176+
'/identity': {
177+
post: {
178+
parameters: [],
179+
requestBody: {
180+
content: {
181+
'application/json': {
182+
schema: {
183+
type: 'object',
184+
properties: {
185+
data: {
186+
type: 'number',
187+
},
188+
},
189+
required: ['data'],
190+
},
191+
},
192+
},
193+
},
194+
responses: {
195+
'200': {
196+
description: 'OK',
197+
content: {
198+
'application/json': {
199+
schema: {
200+
type: 'object',
201+
properties: {
202+
result: {
203+
type: 'number',
204+
},
205+
},
206+
required: ['result'],
207+
},
208+
},
209+
},
210+
},
211+
},
212+
},
213+
},
214+
},
215+
components: {
216+
schemas: {},
217+
},
218+
});

0 commit comments

Comments
 (0)