Skip to content

Commit 6ef9454

Browse files
committed
chore(api): fix sync generation output
1 parent 11a2950 commit 6ef9454

6 files changed

Lines changed: 9061 additions & 4849 deletions

File tree

.github/workflows/api-package-sync.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ jobs:
7979
run: pnpm generate
8080
working-directory: packages/api
8181

82+
- name: Format API package
83+
run: pnpm exec nx run @supabase/api:fmt:fix
84+
8285
- name: Check for generated changes
8386
id: check
8487
run: |

packages/api/scripts/generate.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ function normalizeJsonSchemaValue(value: unknown): unknown {
311311
return isRecord(value) ? normalizeNullableJsonSchema(value) : value;
312312
}
313313

314-
function normalizeNullableJsonSchema(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
314+
export function normalizeNullableJsonSchema(schema: JsonSchema.JsonSchema): JsonSchema.JsonSchema {
315315
const normalized: JsonSchema.JsonSchema = {};
316316
for (const [key, value] of Object.entries(schema)) {
317317
normalized[key] = normalizeJsonSchemaValue(value);
@@ -330,10 +330,6 @@ function normalizeNullableJsonSchema(schema: JsonSchema.JsonSchema): JsonSchema.
330330
if (nonNullTypes.length === 0) {
331331
return { type: "null" };
332332
}
333-
if (!nonNullTypes.includes("object") && !nonNullTypes.includes("array")) {
334-
return normalized;
335-
}
336-
337333
const nonNullSchema = { ...normalized };
338334
delete nonNullSchema.type;
339335
return {
@@ -900,4 +896,6 @@ function main() {
900896
console.log(`Generated ${operations.length} API operations in ${generatedDir}`);
901897
}
902898

903-
main();
899+
if (import.meta.main) {
900+
main();
901+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as JsonSchema from "effect/JsonSchema";
2+
import * as SchemaRepresentation from "effect/SchemaRepresentation";
3+
import { describe, expect, test } from "vitest";
4+
5+
import { normalizeNullableJsonSchema } from "./generate.ts";
6+
7+
function renderOpenApiSchema(schema: Parameters<typeof JsonSchema.fromSchemaOpenApi3_0>[0]) {
8+
const normalized = normalizeNullableJsonSchema(JsonSchema.fromSchemaOpenApi3_0(schema).schema);
9+
const multiDocument = SchemaRepresentation.fromJsonSchemaMultiDocument({
10+
dialect: "draft-2020-12",
11+
definitions: {},
12+
schemas: [normalized],
13+
});
14+
return SchemaRepresentation.toCodeDocument(multiDocument).codes[0]!.runtime;
15+
}
16+
17+
describe("generate", () => {
18+
test("preserves nullable formatted strings in generated schemas", () => {
19+
expect(renderOpenApiSchema({ type: "string", format: "email", nullable: true })).toBe(
20+
'Schema.Union([Schema.String.annotate({ "format": "email" }), Schema.Null])',
21+
);
22+
expect(renderOpenApiSchema({ type: "string", format: "date-time", nullable: true })).toBe(
23+
'Schema.Union([Schema.String.annotate({ "format": "date-time" }), Schema.Null])',
24+
);
25+
});
26+
});

0 commit comments

Comments
 (0)