@@ -167,10 +167,11 @@ testCase('simple route', SIMPLE, {
167167 ] ,
168168 responses : {
169169 200 : {
170- description : 'foo response ' ,
170+ description : 'OK ' ,
171171 content : {
172172 'application/json' : {
173173 schema : {
174+ description : 'foo response' ,
174175 type : 'string' ,
175176 } ,
176177 } ,
@@ -291,10 +292,11 @@ testCase('request body route', REQUEST_BODY, {
291292 } ,
292293 responses : {
293294 200 : {
294- description : 'foo response ' ,
295+ description : 'OK ' ,
295296 content : {
296297 'application/json' : {
297298 schema : {
299+ description : 'foo response' ,
298300 type : 'string' ,
299301 } ,
300302 } ,
@@ -377,10 +379,11 @@ testCase('request union route', UNION, {
377379 ] ,
378380 responses : {
379381 200 : {
380- description : 'foo response ' ,
382+ description : 'OK ' ,
381383 content : {
382384 'application/json' : {
383385 schema : {
386+ description : 'foo response' ,
384387 type : 'string' ,
385388 } ,
386389 } ,
@@ -442,10 +445,11 @@ testCase('nullable property route', NULLABLE_PROPERTY, {
442445 } ,
443446 responses : {
444447 200 : {
445- description : 'foo response ' ,
448+ description : 'OK ' ,
446449 content : {
447450 'application/json' : {
448451 schema : {
452+ description : 'foo response' ,
449453 type : 'string' ,
450454 } ,
451455 } ,
@@ -543,7 +547,10 @@ export const route = h.httpRoute({
543547 }),
544548 response: {
545549 /** foo response */
546- 200: t.partial({ foo: t.string })
550+ 200: t.partial({
551+ /** string called foo */
552+ foo: t.string
553+ })
547554 },
548555});
549556` ;
@@ -576,13 +583,15 @@ testCase('object with no required properties', EMPTY_REQUIRED, {
576583 } ,
577584 responses : {
578585 200 : {
579- description : 'foo response ' ,
586+ description : 'OK ' ,
580587 content : {
581588 'application/json' : {
582589 schema : {
583590 type : 'object' ,
591+ description : 'foo response' ,
584592 properties : {
585593 foo : {
594+ description : 'string called foo' ,
586595 type : 'string' ,
587596 } ,
588597 } ,
@@ -639,10 +648,11 @@ testCase('request body ref', SCHEMA_REF, {
639648 } ,
640649 responses : {
641650 200 : {
642- description : 'foo response ' ,
651+ description : 'OK ' ,
643652 content : {
644653 'application/json' : {
645654 schema : {
655+ description : 'foo response' ,
646656 type : 'string' ,
647657 } ,
648658 } ,
@@ -795,10 +805,11 @@ testCase('request body double ref', SCHEMA_DOUBLE_REF, {
795805 } ,
796806 responses : {
797807 200 : {
798- description : 'foo response ' ,
808+ description : 'OK ' ,
799809 content : {
800810 'application/json' : {
801811 schema : {
812+ description : 'foo response' ,
802813 type : 'string' ,
803814 } ,
804815 } ,
@@ -872,10 +883,11 @@ testCase('request body nullable ref', SCHEMA_NULLABLE_REF, {
872883 } ,
873884 responses : {
874885 200 : {
875- description : 'foo response ' ,
886+ description : 'OK ' ,
876887 content : {
877888 'application/json' : {
878889 schema : {
890+ description : 'foo response' ,
879891 type : 'string' ,
880892 } ,
881893 } ,
@@ -991,10 +1003,11 @@ testCase('schema parameter with title tag', TITLE_TAG, {
9911003 ] ,
9921004 responses : {
9931005 200 : {
994- description : 'foo response ' ,
1006+ description : 'OK ' ,
9951007 content : {
9961008 'application/json' : {
9971009 schema : {
1010+ description : 'foo response' ,
9981011 type : 'string' ,
9991012 } ,
10001013 } ,
@@ -1019,10 +1032,11 @@ testCase('schema parameter with title tag', TITLE_TAG, {
10191032 ] ,
10201033 responses : {
10211034 200 : {
1022- description : 'bar response ' ,
1035+ description : 'OK ' ,
10231036 content : {
10241037 'application/json' : {
10251038 schema : {
1039+ description : 'bar response' ,
10261040 type : 'string' ,
10271041 } ,
10281042 } ,
@@ -1076,10 +1090,11 @@ testCase('optional parameter', OPTIONAL_PARAM, {
10761090 ] ,
10771091 responses : {
10781092 200 : {
1079- description : 'foo response ' ,
1093+ description : 'OK ' ,
10801094 content : {
10811095 'application/json' : {
10821096 schema : {
1097+ description : 'foo response' ,
10831098 type : 'string' ,
10841099 } ,
10851100 } ,
@@ -3163,3 +3178,79 @@ testCase('route with schema with default metadata', ROUTE_WITH_OVERIDDEN_METADAT
31633178 schemas : { }
31643179 }
31653180} ) ;
3181+
3182+
3183+ const SCHEMA_WITH_MANY_RESPONSE_TYPES = `
3184+ import * as t from 'io-ts';
3185+ import * as h from '@api-ts/io-ts-http';
3186+
3187+ const ApiError = t.type({
3188+ /** error message */
3189+ error: t.string,
3190+ });
3191+
3192+ export const route = h.httpRoute({
3193+ path: '/foo',
3194+ method: 'GET',
3195+ request: h.httpRequest({}),
3196+ response: {
3197+ /** string response type */
3198+ 200: t.string,
3199+ 400: ApiError
3200+ },
3201+ })
3202+ `
3203+ testCase ( 'route with many response codes uses default status code descriptions' , SCHEMA_WITH_MANY_RESPONSE_TYPES , {
3204+ openapi : '3.0.3' ,
3205+ info : {
3206+ title : 'Test' ,
3207+ version : '1.0.0'
3208+ } ,
3209+ paths : {
3210+ '/foo' : {
3211+ get : {
3212+ parameters : [ ] ,
3213+ responses : {
3214+ '200' : {
3215+ description : 'OK' ,
3216+ content : {
3217+ 'application/json' : {
3218+ schema : {
3219+ description : 'string response type' ,
3220+ type : 'string'
3221+ }
3222+ }
3223+ }
3224+ } ,
3225+ '400' : {
3226+ description : 'Bad Request' ,
3227+ content : {
3228+ 'application/json' : {
3229+ schema : {
3230+ '$ref' : '#/components/schemas/ApiError'
3231+ }
3232+ }
3233+ }
3234+ }
3235+ }
3236+ }
3237+ }
3238+ } ,
3239+ components : {
3240+ schemas : {
3241+ ApiError : {
3242+ properties : {
3243+ error : {
3244+ type : 'string' ,
3245+ description : 'error message' ,
3246+ }
3247+ } ,
3248+ required : [
3249+ 'error'
3250+ ] ,
3251+ type : 'object' ,
3252+ title : 'ApiError'
3253+ } ,
3254+ }
3255+ }
3256+ } ) ;
0 commit comments