Skip to content

Commit 942cc2f

Browse files
committed
fix: pass default openapi object to any case
Ticket: DX-2582 This commit passes the defaultOpenAPIObject to the any case. This allows for us to not drop the jsdoc information on t.any types. It is valid openapi to have descriptions and other metadata on any types: https://swagger.io/docs/specification/v3_0/data-models/data-types/#any-type From the following slack thread: https://bitgo.slack.com/archives/C057BHBRG4B/p1765481932730759 \# Test Tested in `entity-validation`: ``` $ > diff test.json test2.json 3123,3137c3123,3125 < "frontPhoto": { < "description": "Front photo of the identity document", < "example": "\"passport-front.jpg\"", < "format": "binary" < }, < "backPhoto": { < "description": "Back photo of the identity document", < "example": "\"drivers-license-back.png\"", < "format": "binary" < }, < "proofOfResidency": { < "description": "Proof of residency", < "example": "\"rental-lease.pdf\"", < "format": "binary" < } --- > "frontPhoto": {}, > "backPhoto": {}, > "proofOfResidency": {} 3264,3278c3252,3254 < "frontPhoto": { < "description": "Front photo of the identity document", < "example": "\"passport-front.jpg\"", < "format": "binary" < }, < "backPhoto": { < "description": "Back photo of the identity document", < "example": "\"drivers-license-back.png\"", < "format": "binary" < }, < "proofOfResidency": { < "description": "Proof of residency", < "example": "\"rental-lease.pdf\"", < "format": "binary" < } --- > "frontPhoto": {}, > "backPhoto": {}, > "proofOfResidency": {} ```
1 parent 71e7be9 commit 942cc2f

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

packages/openapi-generator/src/openapi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export function schemaToOpenAPI(
234234
case 'undefined':
235235
return undefined;
236236
case 'any':
237-
return {};
237+
return { ...defaultOpenAPIObject };
238238
default:
239239
return {};
240240
}

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

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,3 +1232,131 @@ testCase(
12321232
},
12331233
},
12341234
);
1235+
1236+
const ROUTE_WITH_ANY_AND_DESCRIPTION = `
1237+
import * as t from 'io-ts';
1238+
import * as h from '@api-ts/io-ts-http';
1239+
1240+
/**
1241+
* A simple route
1242+
*
1243+
* @operationId api.v1.test
1244+
* @tag Test Routes
1245+
*/
1246+
export const route = h.httpRoute({
1247+
path: '/foo',
1248+
method: 'GET',
1249+
request: h.httpRequest({}),
1250+
response: {
1251+
200: {
1252+
/**
1253+
* Test description
1254+
*/
1255+
test: t.any
1256+
}
1257+
},
1258+
});
1259+
`;
1260+
1261+
testCase('route with example object', ROUTE_WITH_ANY_AND_DESCRIPTION, {
1262+
openapi: '3.0.3',
1263+
info: {
1264+
title: 'Test',
1265+
version: '1.0.0',
1266+
},
1267+
paths: {
1268+
'/foo': {
1269+
get: {
1270+
summary: 'A simple route',
1271+
operationId: 'api.v1.test',
1272+
tags: ['Test Routes'],
1273+
parameters: [],
1274+
responses: {
1275+
200: {
1276+
description: 'OK',
1277+
content: {
1278+
'application/json': {
1279+
schema: {
1280+
type: 'object',
1281+
properties: {
1282+
test: {
1283+
description: 'Test description',
1284+
},
1285+
},
1286+
required: ['test'],
1287+
},
1288+
},
1289+
},
1290+
},
1291+
},
1292+
},
1293+
},
1294+
},
1295+
components: {
1296+
schemas: {},
1297+
},
1298+
});
1299+
1300+
const ROUTE_WITH_ANY_AND_FORMAT = `
1301+
import * as t from 'io-ts';
1302+
import * as h from '@api-ts/io-ts-http';
1303+
1304+
/**
1305+
* A simple route
1306+
*
1307+
* @operationId api.v1.test
1308+
* @tag Test Routes
1309+
*/
1310+
export const route = h.httpRoute({
1311+
path: '/foo',
1312+
method: 'GET',
1313+
request: h.httpRequest({}),
1314+
response: {
1315+
200: {
1316+
/**
1317+
* @format binary
1318+
*/
1319+
test: t.any
1320+
}
1321+
},
1322+
});
1323+
`;
1324+
1325+
testCase('route with example object', ROUTE_WITH_ANY_AND_FORMAT, {
1326+
openapi: '3.0.3',
1327+
info: {
1328+
title: 'Test',
1329+
version: '1.0.0',
1330+
},
1331+
paths: {
1332+
'/foo': {
1333+
get: {
1334+
summary: 'A simple route',
1335+
operationId: 'api.v1.test',
1336+
tags: ['Test Routes'],
1337+
parameters: [],
1338+
responses: {
1339+
200: {
1340+
description: 'OK',
1341+
content: {
1342+
'application/json': {
1343+
schema: {
1344+
type: 'object',
1345+
properties: {
1346+
test: {
1347+
format: 'binary',
1348+
},
1349+
},
1350+
required: ['test'],
1351+
},
1352+
},
1353+
},
1354+
},
1355+
},
1356+
},
1357+
},
1358+
},
1359+
components: {
1360+
schemas: {},
1361+
},
1362+
});

0 commit comments

Comments
 (0)