From 3600fc7965ba8ff36a6a9847dcece64ed96fc06b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 25 Jul 2025 23:11:41 +0000 Subject: [PATCH] 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 <67922293+ericcrosson-bitgo@users.noreply.github.com> --- .../openapi-generator/src/knownImports.ts | 1 + .../test/openapi/knownImports.test.ts | 75 ++++++++++++++++++- 2 files changed, 74 insertions(+), 2 deletions(-) diff --git a/packages/openapi-generator/src/knownImports.ts b/packages/openapi-generator/src/knownImports.ts index fab630d0..d18e88aa 100644 --- a/packages/openapi-generator/src/knownImports.ts +++ b/packages/openapi-generator/src/knownImports.ts @@ -137,6 +137,7 @@ export const KNOWN_IMPORTS: KnownImports = { brand: (_, arg) => E.right(arg), UnknownRecord: () => E.right({ type: 'record', codomain: { type: 'any' } }), void: () => E.right({ type: 'undefined' }), + identity: (_, arg) => E.right(arg), }, 'io-ts-numbers': { NumberFromString: () => diff --git a/packages/openapi-generator/test/openapi/knownImports.test.ts b/packages/openapi-generator/test/openapi/knownImports.test.ts index f71af85b..c603e195 100644 --- a/packages/openapi-generator/test/openapi/knownImports.test.ts +++ b/packages/openapi-generator/test/openapi/knownImports.test.ts @@ -88,8 +88,8 @@ export const route = h.httpRoute({ }), response: { 200: { - /** - * Testing overridden metadata + /** + * Testing overridden metadata * @format string */ test: DateFromNumber @@ -145,3 +145,74 @@ testCase('route with schema with default metadata', ROUTE_WITH_OVERIDDEN_METADAT schemas: {}, }, }); + +const ROUTE_WITH_IDENTITY_CODEC = ` +import * as t from 'io-ts'; +import * as h from '@api-ts/io-ts-http'; + +export const route = h.httpRoute({ + path: '/identity', + method: 'POST', + request: h.httpRequest({ + body: { + data: t.identity(t.number) + }, + }), + response: { + 200: { + result: t.identity(t.number) + } + }, +}); +`; + +testCase('route with t.identity codec', ROUTE_WITH_IDENTITY_CODEC, { + openapi: '3.0.3', + info: { + title: 'Test', + version: '1.0.0', + }, + paths: { + '/identity': { + post: { + parameters: [], + requestBody: { + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + data: { + type: 'number', + }, + }, + required: ['data'], + }, + }, + }, + }, + responses: { + '200': { + description: 'OK', + content: { + 'application/json': { + schema: { + type: 'object', + properties: { + result: { + type: 'number', + }, + }, + required: ['result'], + }, + }, + }, + }, + }, + }, + }, + }, + components: { + schemas: {}, + }, +});