66 OperationParameterBase ,
77 OperationQueryParameterSchema ,
88 type QueryParamSchemaSchema ,
9+ recordToObject ,
10+ refToName ,
911 type Schema ,
1012 SchemaSchema ,
1113 SchemaSchemaBoolean ,
@@ -334,7 +336,7 @@ const TagSchemaSchemaPut = BaseTagSchemaOperation.extend({
334336
335337const TagSchemaSchema = z
336338 . object ( {
337- // servers: LichessServersSchema.optional(),
339+ servers : LichessServersSchema . optional ( ) ,
338340 parameters : z
339341 . array ( OperationPathParameterSchema )
340342 . transform ( ( s ) => ( { parameters : s , __id : "__parameters" as const } ) )
@@ -464,13 +466,13 @@ function schemaToTypescriptTypes(
464466 case "$ref" :
465467 case "notverified:reftoprimitive" : {
466468 const ref = schema . $ref ;
467- const name = ref . split ( "/" ) . pop ( ) ! . replace ( ".yaml" , "" ) ;
469+ const name = refToName ( ref ) ;
468470 const typescriptSchema = `schemas.${ name } ` as const ;
469471 return typescriptSchema ;
470472 }
471473 case "notverified:reftoprimitive:nullable" : {
472474 const ref = schema . allOf [ 0 ] . $ref ;
473- const name = ref . split ( "/" ) . pop ( ) ! . replace ( ".yaml" , "" ) ;
475+ const name = refToName ( ref ) ;
474476 const typescriptSchema = `schemas.${ name } | null` as const ;
475477 return typescriptSchema ;
476478 }
@@ -485,15 +487,7 @@ function schemaToTypescriptTypes(
485487 : ( `?: ${ typescriptSchema } ` as const ) ;
486488 objectRecord [ k ] = propStr ;
487489 }
488- const entries = Object . entries ( objectRecord ) ;
489- if ( entries . length === 1 ) {
490- return `{ "${ entries [ 0 ] ! [ 0 ] } " ${ entries [ 0 ] ! [ 1 ] } }` as const ;
491- }
492- return (
493- "{\n" +
494- entries . map ( ( [ k , v ] ) => ` "${ k } " ${ v } ,` as const ) . join ( "\n" ) +
495- "\n}"
496- ) ;
490+ return recordToObject ( objectRecord , { colon : false } ) ;
497491 }
498492 case "boolean" :
499493 case "boolean-like" : {
@@ -535,7 +529,7 @@ function schemaToTypescriptTypes(
535529 }
536530 case "array:notverified:reftoprimitive" : {
537531 const ref = schema . items . $ref ;
538- const name = ref . split ( "/" ) . pop ( ) ! . replace ( ".yaml" , "" ) ;
532+ const name = refToName ( ref ) ;
539533 const typescriptSchema = `schemas.${ name } ` as const ;
540534 return `(${ typescriptSchema } )[]` as const ;
541535 }
@@ -563,32 +557,15 @@ function extractQueryParams(queryParams: OperationQueryParameter[]) {
563557 ? `: ${ typescriptSchema } `
564558 : `?: ${ typescriptSchema } ` ;
565559 }
566- const entries = Object . entries ( params ) ;
567- if ( entries . length === 1 ) {
568- return `{ "${ entries [ 0 ] ! [ 0 ] } " ${ entries [ 0 ] ! [ 1 ] } }` as const ;
569- }
570- return (
571- "{\n" +
572- entries . map ( ( [ k , v ] ) => ` "${ k } " ${ v } ,` as const ) . join ( "\n" ) +
573- "\n}"
574- ) ;
560+ return recordToObject ( params , { colon : false } ) ;
575561}
576562
577563function extractPathParams ( pathParams : OperationPathParameter [ ] ) {
578564 const params : Record < string , string > = { } ;
579565 for ( const param of pathParams ) {
580- const typescriptSchema = schemaToTypescriptTypes ( param . schema ) ;
581- params [ param . name ] = `: ${ typescriptSchema } ` as const ;
582- }
583- const entries = Object . entries ( params ) ;
584- if ( entries . length === 1 ) {
585- return `{ "${ entries [ 0 ] ! [ 0 ] } " ${ entries [ 0 ] ! [ 1 ] } }` as const ;
566+ params [ param . name ] = schemaToTypescriptTypes ( param . schema ) ;
586567 }
587- return (
588- "{\n" +
589- entries . map ( ( [ k , v ] ) => ` "${ k } " ${ v } ,` as const ) . join ( "\n" ) +
590- "\n}"
591- ) ;
568+ return recordToObject ( params ) ;
592569}
593570
594571function extractBodyTypes ( bodySchema : Schema ) {
@@ -614,10 +591,10 @@ function processOperation(
614591 return { parameters, __type : "__parameters" } as const ;
615592 }
616593
617- // if (operation.__id === "__servers") {
618- // const baseUrl = operation.url;
619- // return { baseUrl, __type: "__servers" } as const;
620- // }
594+ if ( operation . __id === "__servers" ) {
595+ const baseUrl = operation . url ;
596+ return { baseUrl, __type : "__servers" } as const ;
597+ }
621598
622599 const { processedPath, hasPathParams } = processRawPath ( rawApiPath ) ;
623600 const pathLiteral = hasPathParams
0 commit comments