Skip to content

Commit 15c8f74

Browse files
committed
fix: update servers generation
1 parent e4bb824 commit 15c8f74

5 files changed

Lines changed: 43 additions & 27 deletions

File tree

scripts/gen-client.ts

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ const OpenApiSchemaPaths = z.record(OpenApiSchemaPath, SchemaSchemaRef);
3838

3939
const 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+
4148
const 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

249251
const 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+
251272
const 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

313335
const 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

693706
function 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, {

src/client/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ export class Lichess {
558558
},
559559
{
560560
200: {
561-
kind: "json",
561+
kind: "ndjson",
562562
schema: z.union([schemas.GamePgn, schemas.GameJson]),
563563
},
564564
},

src/schemas/BroadcastGameEntry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const BroadcastGameEntry = z.object({
1515
customPoints: z.optional(BroadcastCustomPoints),
1616
ratingDiff: z.optional(z.int()),
1717
fideTC: FideTimeControl,
18+
ongoing: z.optional(z.boolean()),
1819
});
1920

2021
type BroadcastGameEntry = z.infer<typeof BroadcastGameEntry>;

src/schemas/BroadcastTour.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const BroadcastTour = z.object({
2727
image: z.optional(z.url()),
2828
description: z.optional(z.string()),
2929
teamTable: z.optional(z.boolean()),
30+
showTeamScores: z.optional(z.boolean()),
3031
url: z.url(),
3132
communityOwner: z.optional(LightUser),
3233
});

src/schemas/PuzzleAndGame.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const PuzzleAndGame = z.object({
4646
plays: z.int(),
4747
rating: z.int(),
4848
fen: z.optional(z.string()),
49+
lastMove: z.optional(z.string()),
4950
solution: z.array(z.string()),
5051
themes: z.array(z.string()),
5152
}),

0 commit comments

Comments
 (0)