@@ -29,7 +29,6 @@ async function testCase(
2929 throw new Error ( 'Failed to parse source file' ) ;
3030 }
3131
32-
3332 const project = new Project ( ) ;
3433 const routes : Route [ ] = [ ] ;
3534 const schemas : Record < string , Schema > = { } ;
@@ -1619,143 +1618,143 @@ export const route = h.httpRoute({
16191618});
16201619` ;
16211620
1622- testCase ( 'route with mixed types and descriptions' , ROUTE_WITH_MIXED_TYPES_AND_DESCRIPTIONS ,
1623- {
1624- openapi : "3.0.3" ,
1625- info : {
1626- title : "Test" ,
1627- version : "1.0.0"
1628- } ,
1629- paths : {
1630- '/foo' : {
1631- get : {
1632- summary : "A simple route with type descriptions" ,
1633- operationId : "api.v1.test" ,
1634- tags : [
1635- "Test Routes"
1636- ] ,
1637- parameters : [
1638- {
1639- name : "bar" ,
1640- description : "bar param" ,
1641- in : "query" ,
1642- required : true ,
1643- schema : {
1644- type : "string"
1645- }
1646- }
1647- ] ,
1648- requestBody : {
1649- content : {
1650- 'application/json' : {
1621+ testCase ( 'route with mixed types and descriptions' , ROUTE_WITH_MIXED_TYPES_AND_DESCRIPTIONS ,
1622+ {
1623+ openapi : "3.0.3" ,
1624+ info : {
1625+ title : "Test" ,
1626+ version : "1.0.0"
1627+ } ,
1628+ paths : {
1629+ '/foo' : {
1630+ get : {
1631+ summary : "A simple route with type descriptions" ,
1632+ operationId : "api.v1.test" ,
1633+ tags : [
1634+ "Test Routes"
1635+ ] ,
1636+ parameters : [
1637+ {
1638+ name : "bar" ,
1639+ description : "bar param" ,
1640+ in : "query" ,
1641+ required : true ,
16511642 schema : {
1652- type : "object" ,
1653- properties : {
1654- foo : {
1655- type : "string" ,
1656- description : "description to describe an optional string"
1657- } ,
1658- bar : {
1659- oneOf : [
1660- {
1661- type : "number"
1662- } ,
1663- {
1664- type : "string"
1665- }
1666- ] ,
1667- description : "description to describe an optional union of number and string"
1668- } ,
1669- child : {
1670- type : "object" ,
1671- description : "description to describe an object" ,
1672- properties : {
1673- child : {
1674- type : "object" ,
1675- description : "dsecription to describe an intersection of a type and a partial" ,
1676- properties : {
1677- foo : {
1678- type : "string"
1679- } ,
1680- bar : {
1681- type : "number"
1682- }
1643+ type : "string"
1644+ }
1645+ }
1646+ ] ,
1647+ requestBody : {
1648+ content : {
1649+ 'application/json' : {
1650+ schema : {
1651+ type : "object" ,
1652+ properties : {
1653+ foo : {
1654+ type : "string" ,
1655+ description : "description to describe an optional string"
1656+ } ,
1657+ bar : {
1658+ oneOf : [
1659+ {
1660+ type : "number"
16831661 } ,
1684- required : [
1685- "foo"
1686- ]
1687- }
1662+ {
1663+ type : "string"
1664+ }
1665+ ] ,
1666+ description : "description to describe an optional union of number and string"
16881667 } ,
1689- required : [
1690- "child"
1691- ]
1692- } ,
1693- error : {
1694- type : "object" ,
1695- description : "description to describe a t.type" ,
1696- properties : {
1697- error : {
1698- type : "string"
1699- }
1668+ child : {
1669+ type : "object" ,
1670+ description : "description to describe an object" ,
1671+ properties : {
1672+ child : {
1673+ type : "object" ,
1674+ description : "dsecription to describe an intersection of a type and a partial" ,
1675+ properties : {
1676+ foo : {
1677+ type : "string"
1678+ } ,
1679+ bar : {
1680+ type : "number"
1681+ }
1682+ } ,
1683+ required : [
1684+ "foo"
1685+ ]
1686+ }
1687+ } ,
1688+ required : [
1689+ "child"
1690+ ]
17001691 } ,
1701- required : [
1702- "error"
1703- ]
1704- } ,
1705- obj : {
1706- type : "object" ,
1707- description : "description to describe an optional t.object" ,
1708- properties : { }
1692+ error : {
1693+ type : "object" ,
1694+ description : "description to describe a t.type" ,
1695+ properties : {
1696+ error : {
1697+ type : "string"
1698+ }
1699+ } ,
1700+ required : [
1701+ "error"
1702+ ]
1703+ } ,
1704+ obj : {
1705+ type : "object" ,
1706+ description : "description to describe an optional t.object" ,
1707+ properties : { }
1708+ } ,
1709+ exact : {
1710+ type : "object" ,
1711+ description : "description to describe a t.exact" ,
1712+ properties : {
1713+ foo : {
1714+ type : "string"
1715+ }
1716+ } ,
1717+ required : [
1718+ "foo"
1719+ ]
1720+ }
17091721 } ,
1710- exact : {
1722+ required : [
1723+ "child" ,
1724+ "error" ,
1725+ "exact"
1726+ ]
1727+ }
1728+ }
1729+ }
1730+ } ,
1731+ responses : {
1732+ 200 : {
1733+ description : "OK" ,
1734+ content : {
1735+ 'application/json' : {
1736+ schema : {
17111737 type : "object" ,
1712- description : "description to describe a t.exact" ,
17131738 properties : {
1714- foo : {
1739+ test : {
17151740 type : "string"
17161741 }
17171742 } ,
17181743 required : [
1719- "foo "
1744+ "test "
17201745 ]
17211746 }
1722- } ,
1723- required : [
1724- "child" ,
1725- "error" ,
1726- "exact"
1727- ]
1728- }
1729- }
1730- }
1731- } ,
1732- responses : {
1733- 200 : {
1734- description : "OK" ,
1735- content : {
1736- 'application/json' : {
1737- schema : {
1738- type : "object" ,
1739- properties : {
1740- test : {
1741- type : "string"
1742- }
1743- } ,
1744- required : [
1745- "test"
1746- ]
17471747 }
17481748 }
17491749 }
17501750 }
17511751 }
17521752 }
1753+ } ,
1754+ components : {
1755+ schemas : { }
17531756 }
1754- } ,
1755- components : {
1756- schemas : { }
1757- }
1758- } ) ;
1757+ } ) ;
17591758
17601759const ROUTE_WITH_ARRAY_TYPES_AND_DESCRIPTIONS = `
17611760import * as t from 'io-ts';
@@ -2826,3 +2825,112 @@ testCase('route with array union of null and undefined', ROUTE_WITH_ARRAY_UNION_
28262825 schemas : { }
28272826 }
28282827} ) ;
2828+
2829+ const ROUTE_WITH_SCHEMA_WITH_COMMENT = `
2830+ import * as t from 'io-ts';
2831+ import * as h from '@api-ts/io-ts-http';
2832+
2833+ /**
2834+ * A simple route with type descriptions for references
2835+ *
2836+ * @operationId api.v1.test
2837+ * @tag Test Routes
2838+ */
2839+ export const route = h.httpRoute({
2840+ path: '/foo',
2841+ method: 'GET',
2842+ request: h.httpRequest({}),
2843+ response: {
2844+ 200: SimpleRouteResponse,
2845+ 400: ApiError
2846+ },
2847+ });
2848+
2849+ /**
2850+ * Human readable description of the Simple Route Response
2851+ * @title Human Readable Simple Route Response
2852+ */
2853+ const SimpleRouteResponse = t.type({
2854+ test: t.string,
2855+ });
2856+
2857+ /**
2858+ * Human readable description of the ApiError schema
2859+ * @title Human Readable Api Error Schema
2860+ */
2861+ const ApiError = t.type({
2862+ error: t.string,
2863+ });
2864+ `
2865+
2866+ testCase ( 'route with api error schema' , ROUTE_WITH_SCHEMA_WITH_COMMENT , {
2867+ openapi : '3.0.3' ,
2868+ info : {
2869+ title : 'Test' ,
2870+ version : '1.0.0'
2871+ } ,
2872+ paths : {
2873+ '/foo' : {
2874+ get : {
2875+ summary : 'A simple route with type descriptions for references' ,
2876+ operationId : 'api.v1.test' ,
2877+ tags : [
2878+ 'Test Routes'
2879+ ] ,
2880+ parameters : [ ] ,
2881+ responses : {
2882+ '200' : {
2883+ description : 'OK' ,
2884+ content : {
2885+ 'application/json' : {
2886+ schema : {
2887+ '$ref' : '#/components/schemas/SimpleRouteResponse'
2888+ }
2889+ }
2890+ }
2891+ } ,
2892+ '400' : {
2893+ content : {
2894+ 'application/json' : {
2895+ schema : {
2896+ '$ref' : '#/components/schemas/ApiError'
2897+ }
2898+ }
2899+ } ,
2900+ description : 'Bad Request'
2901+ }
2902+ }
2903+ }
2904+ } ,
2905+ } ,
2906+ components : {
2907+ schemas : {
2908+ ApiError : {
2909+ properties : {
2910+ error : {
2911+ type : 'string'
2912+ }
2913+ } ,
2914+ required : [
2915+ 'error'
2916+ ] ,
2917+ title : 'Human Readable Api Error Schema' ,
2918+ description : 'Human readable description of the ApiError schema' ,
2919+ type : 'object'
2920+ } ,
2921+ SimpleRouteResponse : {
2922+ description : 'Human readable description of the Simple Route Response' ,
2923+ properties : {
2924+ test : {
2925+ type : 'string'
2926+ }
2927+ } ,
2928+ required : [
2929+ 'test'
2930+ ] ,
2931+ title : 'Human Readable Simple Route Response' ,
2932+ type : 'object'
2933+ }
2934+ } ,
2935+ } ,
2936+ } ) ;
0 commit comments