11import * as E from 'fp-ts/lib/Either' ;
22import assert from 'node:assert/strict' ;
33import test from 'node:test' ;
4- import { OpenAPIV3_1 } from 'openapi-types' ;
54
65import {
76 convertRoutesToOpenAPI ,
@@ -17,11 +16,7 @@ import { SourceFile } from '../src/sourceFile';
1716async function testCase (
1817 description : string ,
1918 src : string ,
20- expected : OpenAPIV3_1 . Document < {
21- 'x-internal' ?: boolean ;
22- 'x-unstable' ?: boolean ;
23- 'x-unknown-tags' ?: object ;
24- } > ,
19+ expected : any ,
2520 expectedErrors : string [ ] = [ ] ,
2621) {
2722 test ( description , async ( ) => {
@@ -3940,13 +3935,162 @@ testCase("route with nested array examples", ROUTE_WITH_NESTED_ARRAY_EXAMPLES, {
39403935 }
39413936} ) ;
39423937
3943- const ROUTE_WITH_RECORD_TYPES = `
3938+ const ROUTE_WITH_PRIVATE_PROPERTIES = `
39443939import * as t from 'io-ts';
39453940import * as h from '@api-ts/io-ts-http';
39463941
3942+ const SampleType = t.type({
3943+ foo: t.string,
3944+ /** @private */
3945+ bar: t.string, // This should show up with x-internal,
3946+ /** @private */
3947+ privateObject: t.type({
3948+ privateFieldInObject: t.boolean
3949+ })
3950+ });
3951+
3952+ export const route = h.httpRoute({
3953+ path: '/foo',
3954+ method: 'GET',
3955+ request: h.httpRequest({
3956+ params: {
3957+ /** @private */
3958+ path: t.string
3959+ },
3960+ query: {
3961+ /** @private */
3962+ query: t.string
3963+ },
3964+ body: SampleType
3965+ }),
3966+ response: {
3967+ 200: SampleType
3968+ },
3969+ });
3970+ ` ;
3971+
3972+ testCase ( "route with private properties in request query, params, body, and response" , ROUTE_WITH_PRIVATE_PROPERTIES , {
3973+ openapi : "3.0.3" ,
3974+ info : {
3975+ title : "Test" ,
3976+ version : "1.0.0"
3977+ } ,
3978+ paths : {
3979+ '/foo' : {
3980+ get : {
3981+ parameters : [
3982+ {
3983+ 'x-internal' : true ,
3984+ description : '' ,
3985+ in : 'query' ,
3986+ name : 'query' ,
3987+ required : true ,
3988+ schema : {
3989+ type : 'string'
3990+ }
3991+ } ,
3992+ {
3993+ 'x-internal' : true ,
3994+ description : '' ,
3995+ in : 'path' ,
3996+ name : 'path' ,
3997+ required : true ,
3998+ schema : {
3999+ type : 'string'
4000+ }
4001+ }
4002+ ] ,
4003+ requestBody : {
4004+ content : {
4005+ 'application/json' : {
4006+ schema : {
4007+ properties : {
4008+ bar : {
4009+ 'x-internal' : true ,
4010+ type : 'string'
4011+ } ,
4012+ foo : {
4013+ type : 'string'
4014+ } ,
4015+ privateObject : {
4016+ 'x-internal' : true ,
4017+ properties : {
4018+ privateFieldInObject : {
4019+ type : 'boolean'
4020+ }
4021+ } ,
4022+ required : [
4023+ 'privateFieldInObject'
4024+ ] ,
4025+ type : 'object'
4026+ }
4027+ } ,
4028+ required : [
4029+ 'foo' ,
4030+ 'bar' ,
4031+ 'privateObject'
4032+ ] ,
4033+ type : 'object'
4034+ }
4035+ }
4036+ } ,
4037+ } ,
4038+ responses : {
4039+ '200' : {
4040+ content : {
4041+ 'application/json' : {
4042+ schema : {
4043+ '$ref' : '#/components/schemas/SampleType'
4044+ }
4045+ }
4046+ } ,
4047+ description : 'OK'
4048+ }
4049+ }
4050+ }
4051+ } ,
4052+ } ,
4053+ components : {
4054+ schemas : {
4055+ SampleType : {
4056+ properties : {
4057+ bar : {
4058+ 'x-internal' : true ,
4059+ type : 'string'
4060+ } ,
4061+ foo : {
4062+ type : 'string'
4063+ } ,
4064+ privateObject : {
4065+ 'x-internal' : true ,
4066+ properties : {
4067+ privateFieldInObject : {
4068+ type : 'boolean'
4069+ }
4070+ } ,
4071+ required : [
4072+ 'privateFieldInObject'
4073+ ] ,
4074+ type : 'object'
4075+ }
4076+ } ,
4077+ required : [
4078+ 'foo' ,
4079+ 'bar' ,
4080+ 'privateObject'
4081+ ] ,
4082+ title : 'SampleType' ,
4083+ type : 'object'
4084+ }
4085+ }
4086+ } ,
4087+ } ) ;
4088+
4089+ const ROUTE_WITH_RECORD_TYPES = `
4090+ import * as t from 'io-ts';
4091+ import * as h from '@api-ts/io-ts-http';
39474092const ValidKeys = t.keyof({ name: "name", age: "age", address: "address" });
39484093const PersonObject = t.type({ bigName: t.string, bigAge: t.number });
3949-
39504094export const route = h.httpRoute({
39514095 path: '/foo',
39524096 method: 'GET',
@@ -4076,4 +4220,4 @@ testCase("route with record types", ROUTE_WITH_RECORD_TYPES, {
40764220 }
40774221 }
40784222 }
4079- } ) ;
4223+ } ) ;
0 commit comments