@@ -4085,3 +4085,139 @@ testCase("route with private properties in request query, params, body, and resp
40854085 }
40864086 } ,
40874087} ) ;
4088+
4089+ const ROUTE_WITH_RECORD_TYPES = `
4090+ import * as t from 'io-ts';
4091+ import * as h from '@api-ts/io-ts-http';
4092+ const ValidKeys = t.keyof({ name: "name", age: "age", address: "address" });
4093+ const PersonObject = t.type({ bigName: t.string, bigAge: t.number });
4094+ export const route = h.httpRoute({
4095+ path: '/foo',
4096+ method: 'GET',
4097+ request: h.httpRequest({
4098+ query: {
4099+ name: t.string,
4100+ },
4101+ }),
4102+ response: {
4103+ 200: {
4104+ person: t.record(ValidKeys, t.string),
4105+ anotherPerson: t.record(ValidKeys, PersonObject),
4106+ bigPerson: t.record(t.string, t.string),
4107+ anotherBigPerson: t.record(t.string, PersonObject),
4108+ }
4109+ },
4110+ });
4111+ ` ;
4112+
4113+ testCase ( "route with record types" , ROUTE_WITH_RECORD_TYPES , {
4114+ openapi : '3.0.3' ,
4115+ info : {
4116+ title : 'Test' ,
4117+ version : '1.0.0'
4118+ } ,
4119+ paths : {
4120+ '/foo' : {
4121+ get : {
4122+ parameters : [
4123+ {
4124+ name : 'name' ,
4125+ in : 'query' ,
4126+ required : true ,
4127+ schema : {
4128+ type : 'string'
4129+ }
4130+ }
4131+ ] ,
4132+ responses : {
4133+ '200' : {
4134+ description : 'OK' ,
4135+ content : {
4136+ 'application/json' : {
4137+ schema : {
4138+ type : 'object' ,
4139+ properties : {
4140+ // becomes t.type()
4141+ person : {
4142+ type : 'object' ,
4143+ properties : {
4144+ name : { type : 'string' } ,
4145+ age : { type : 'string' } ,
4146+ address : { type : 'string' }
4147+ } ,
4148+ required : [ 'name' , 'age' , 'address' ]
4149+ } ,
4150+ // becomes t.type()
4151+ anotherPerson : {
4152+ type : 'object' ,
4153+ properties : {
4154+ name : {
4155+ type : 'object' ,
4156+ properties : {
4157+ bigName : { type : 'string' } ,
4158+ bigAge : { type : 'number' }
4159+ } ,
4160+ required : [ 'bigName' , 'bigAge' ]
4161+ } ,
4162+ age : {
4163+ type : 'object' ,
4164+ properties : {
4165+ bigName : { type : 'string' } ,
4166+ bigAge : { type : 'number' }
4167+ } ,
4168+ required : [ 'bigName' , 'bigAge' ]
4169+ } ,
4170+ address : {
4171+ type : 'object' ,
4172+ properties : {
4173+ bigName : { type : 'string' } ,
4174+ bigAge : { type : 'number' }
4175+ } ,
4176+ required : [ 'bigName' , 'bigAge' ]
4177+ }
4178+ } ,
4179+ required : [ 'name' , 'age' , 'address' ]
4180+ } ,
4181+ bigPerson : {
4182+ // stays as t.record()
4183+ type : 'object' ,
4184+ additionalProperties : { type : 'string' }
4185+ } ,
4186+ anotherBigPerson : {
4187+ // stays as t.record()
4188+ type : 'object' ,
4189+ additionalProperties : {
4190+ type : 'object' ,
4191+ properties : {
4192+ bigName : { type : 'string' } ,
4193+ bigAge : { type : 'number' }
4194+ } ,
4195+ required : [ 'bigName' , 'bigAge' ]
4196+ }
4197+ }
4198+ } ,
4199+ required : [ 'person' , 'anotherPerson' , 'bigPerson' , 'anotherBigPerson' ]
4200+ }
4201+ }
4202+ }
4203+ }
4204+ }
4205+ }
4206+ }
4207+ } ,
4208+ components : {
4209+ schemas : {
4210+ ValidKeys : {
4211+ title : 'ValidKeys' ,
4212+ type : 'string' ,
4213+ enum : [ 'name' , 'age' , 'address' ]
4214+ } ,
4215+ PersonObject : {
4216+ title : 'PersonObject' ,
4217+ type : 'object' ,
4218+ properties : { bigName : { type : 'string' } , bigAge : { type : 'number' } } ,
4219+ required : [ 'bigName' , 'bigAge' ]
4220+ }
4221+ }
4222+ }
4223+ } ) ;
0 commit comments