@@ -38,15 +38,17 @@ const OpenApiSchemaPaths = z.record(OpenApiSchemaPath, SchemaSchemaRef);
3838
3939const OpenApiSchemaComponents = z . object ( ) ;
4040
41+ const OpenApiServersSchema = z . tuple ( [
42+ z . object ( { url : z . literal ( "https://lichess.org" ) } ) ,
43+ z . object ( { url : z . literal ( "https://lichess.dev" ) } ) ,
44+ z . object ( { url : z . literal ( "http://localhost:{port}" ) } ) ,
45+ z . object ( { url : z . literal ( "http://l.org" ) } ) ,
46+ ] ) ;
47+
4148const OpenApiSchemaSchema = z . object ( {
4249 openapi : z . literal ( "3.1.0" ) ,
4350 info : OpenApiSchemaInfo ,
44- servers : z . tuple ( [
45- z . object ( { url : z . literal ( "https://lichess.org" ) } ) ,
46- z . object ( { url : z . literal ( "https://lichess.dev" ) } ) ,
47- z . object ( { url : z . literal ( "http://localhost:{port}" ) } ) ,
48- z . object ( { url : z . literal ( "http://l.org" ) } ) ,
49- ] ) ,
51+ servers : OpenApiServersSchema ,
5052 tags : z . array ( z . object ( { name : z . string ( ) , description : z . string ( ) } ) ) ,
5153 paths : OpenApiSchemaPaths ,
5254 components : OpenApiSchemaComponents ,
@@ -248,10 +250,30 @@ const ResponseStatus = z.string();
248250
249251const OperationResponses = z . record ( ResponseStatus , ResponseSchema ) ;
250252
253+ const LichessServerSchema = z . union ( [
254+ z . object ( {
255+ url : z . literal ( [
256+ "https://engine.lichess.ovh" ,
257+ "https://explorer.lichess.org" ,
258+ "https://tablebase.lichess.org" ,
259+ ] ) ,
260+ } ) ,
261+ z . object ( {
262+ url : z . literal ( "http://localhost:{port}" ) ,
263+ variables : z . object ( { port : z . object ( { default : z . string ( ) } ) } ) ,
264+ } ) ,
265+ ] ) ;
266+
267+ const LichessServersSchema = z
268+ . tuple ( [ LichessServerSchema ] )
269+ . rest ( LichessServerSchema )
270+ . transform ( ( s ) => ( { url : s [ 0 ] . url , __id : "__servers" as const } ) ) ;
271+
251272const BaseTagSchemaOperation = z . object ( {
252273 operationId : z . string ( ) ,
253274 summary : z . string ( ) ,
254275 description : z . string ( ) ,
276+ servers : LichessServersSchema . optional ( ) ,
255277 tags : z . array ( z . string ( ) ) ,
256278 security : SecuritySchema ,
257279 parameters : OperationParameters ,
@@ -312,18 +334,7 @@ const TagSchemaSchemaPut = BaseTagSchemaOperation.extend({
312334
313335const TagSchemaSchema = z
314336 . object ( {
315- servers : z
316- . tuple ( [
317- z . object ( {
318- url : z . literal ( [
319- "https://engine.lichess.ovh" ,
320- "https://explorer.lichess.org" ,
321- "https://tablebase.lichess.org" ,
322- ] ) ,
323- } ) ,
324- ] )
325- . transform ( ( s ) => ( { url : s [ 0 ] . url , __id : "__servers" as const } ) )
326- . optional ( ) ,
337+ // servers: LichessServersSchema.optional(),
327338 parameters : z
328339 . array ( OperationPathParameterSchema )
329340 . transform ( ( s ) => ( { parameters : s , __id : "__parameters" as const } ) )
@@ -603,10 +614,10 @@ function processOperation(
603614 return { parameters, __type : "__parameters" } as const ;
604615 }
605616
606- if ( operation . __id === "__servers" ) {
607- const baseUrl = operation . url ;
608- return { baseUrl, __type : "__servers" } as const ;
609- }
617+ // if (operation.__id === "__servers") {
618+ // const baseUrl = operation.url;
619+ // return { baseUrl, __type: "__servers" } as const;
620+ // }
610621
611622 const { processedPath, hasPathParams } = processRawPath ( rawApiPath ) ;
612623 const pathLiteral = hasPathParams
@@ -665,10 +676,12 @@ function processOperation(
665676 requestObjCode = `${ requestPieces . join ( ", " ) } ` ;
666677 }
667678
679+ const baseUrl = options ?. baseUrl || operation . servers ?. url ;
680+
668681 let baseUrlLine = "" ;
669682 let baseUrlArg = "" ;
670- if ( options ?. baseUrl ) {
671- baseUrlLine = ` const baseUrl = "${ options . baseUrl } ";\n` ;
683+ if ( baseUrl ) {
684+ baseUrlLine = ` const baseUrl = "${ baseUrl } ";\n` ;
672685 baseUrlArg = ", baseUrl" ;
673686 }
674687
@@ -692,8 +705,8 @@ ${baseUrlLine}\
692705
693706function processTag ( tagSchema : TagSchema , rawApiPath : string ) {
694707 const methodsCode : string [ ] = [ ] ;
695- let sharedPathParams : OperationPathParameter [ ] | undefined = undefined ;
696- let baseUrl : string | undefined = undefined ;
708+ let sharedPathParams : OperationPathParameter [ ] | undefined ;
709+ let baseUrl : string | undefined ;
697710
698711 for ( const operation of Object . values ( tagSchema ) ) {
699712 const processedOperation = processOperation ( operation , rawApiPath , {
0 commit comments