@@ -303,4 +303,152 @@ testCase('request body nullable ref', SCHEMA_NULLABLE_REF, {
303303 } ,
304304 } ,
305305 } ,
306+ } ) ;
307+
308+
309+ const ROUTE_WITH_SCHEMA_WITH_COMMENT = `
310+ import * as t from 'io-ts';
311+ import * as h from '@api-ts/io-ts-http';
312+ /**
313+ * A simple route with type descriptions for references
314+ *
315+ * @operationId api.v1.test
316+ * @tag Test Routes
317+ */
318+ export const route = h.httpRoute({
319+ path: '/foo',
320+ method: 'GET',
321+ request: h.httpRequest({}),
322+ response: {
323+ 200: SimpleRouteResponse,
324+ 400: ApiError,
325+ 401: InvalidError
326+ },
327+ });
328+ /**
329+ * Human readable description of the Simple Route Response
330+ * @title Human Readable Simple Route Response
331+ */
332+ const SimpleRouteResponse = t.type({
333+ test: t.string,
334+ });
335+ /**
336+ * Human readable description of the InvalidError schema
337+ * @title Human Readable Invalid Error Schema
338+ */
339+ const InvalidError = t.intersection([
340+ ApiError,
341+ t.type({ error: t.literal('invalid') })]);
342+ /**
343+ * Human readable description of the ApiError schema
344+ * @title Human Readable Api Error Schema
345+ */
346+ const ApiError = t.type({
347+ error: t.string,
348+ });
349+ ` ;
350+
351+ testCase ( 'route with api error schema' , ROUTE_WITH_SCHEMA_WITH_COMMENT , {
352+ openapi : '3.0.3' ,
353+ info : {
354+ title : 'Test' ,
355+ version : '1.0.0'
356+ } ,
357+ paths : {
358+ '/foo' : {
359+ get : {
360+ summary : 'A simple route with type descriptions for references' ,
361+ operationId : 'api.v1.test' ,
362+ tags : [
363+ 'Test Routes'
364+ ] ,
365+ parameters : [ ] ,
366+ responses : {
367+ '200' : {
368+ description : 'OK' ,
369+ content : {
370+ 'application/json' : {
371+ schema : {
372+ '$ref' : '#/components/schemas/SimpleRouteResponse'
373+ }
374+ }
375+ }
376+ } ,
377+ '400' : {
378+ content : {
379+ 'application/json' : {
380+ schema : {
381+ '$ref' : '#/components/schemas/ApiError'
382+ }
383+ }
384+ } ,
385+ description : 'Bad Request'
386+ } ,
387+ '401' : {
388+ description : 'Unauthorized' ,
389+ content : {
390+ 'application/json' : {
391+ schema : {
392+ $ref : '#/components/schemas/InvalidError'
393+ }
394+ }
395+ }
396+ }
397+ }
398+ }
399+ } ,
400+ } ,
401+ components : {
402+ schemas : {
403+ ApiError : {
404+ properties : {
405+ error : {
406+ type : 'string'
407+ }
408+ } ,
409+ required : [
410+ 'error'
411+ ] ,
412+ title : 'Human Readable Api Error Schema' ,
413+ description : 'Human readable description of the ApiError schema' ,
414+ type : 'object'
415+ } ,
416+ SimpleRouteResponse : {
417+ description : 'Human readable description of the Simple Route Response' ,
418+ properties : {
419+ test : {
420+ type : 'string'
421+ }
422+ } ,
423+ required : [
424+ 'test'
425+ ] ,
426+ title : 'Human Readable Simple Route Response' ,
427+ type : 'object' ,
428+ } ,
429+ InvalidError : {
430+ title : 'Human Readable Invalid Error Schema' ,
431+ description : 'Human readable description of the InvalidError schema' ,
432+ allOf : [
433+ {
434+ type : 'object' ,
435+ properties : {
436+ error : {
437+ type : 'string' ,
438+ enum : [
439+ 'invalid'
440+ ]
441+ }
442+ } ,
443+ required : [
444+ 'error'
445+ ]
446+ } ,
447+ {
448+ $ref : '#/components/schemas/ApiError'
449+ }
450+ ] ,
451+ } ,
452+ }
453+ }
306454} ) ;
0 commit comments