refactor(httpapi): fork server startup by flag (#24799)

This commit is contained in:
Kit Langton
2026-04-28 11:02:35 -04:00
committed by GitHub
parent 3fa78a8b01
commit 7739cc53b4
23 changed files with 190 additions and 371 deletions

View File

@@ -1,15 +1,26 @@
import { Server } from "../../server/server"
import { PublicApi } from "../../server/routes/instance/httpapi/public"
import type { CommandModule } from "yargs"
import { OpenApi } from "effect/unstable/httpapi"
type Args = {
httpapi: boolean
}
export const GenerateCommand = {
command: "generate",
handler: async () => {
const specs = await Server.openapi()
builder: (yargs) =>
yargs.option("httpapi", {
type: "boolean",
default: false,
description: "Generate OpenAPI from the experimental Effect HttpApi contract",
}),
handler: async (args) => {
const specs = args.httpapi ? OpenApi.fromApi(PublicApi) : await Server.openapi()
for (const item of Object.values(specs.paths)) {
for (const method of ["get", "post", "put", "delete", "patch"] as const) {
const operation = item[method]
if (!operation?.operationId) continue
// @ts-expect-error
operation["x-codeSamples"] = [
{
lang: "js",
@@ -47,4 +58,4 @@ export const GenerateCommand = {
})
})
},
} satisfies CommandModule
} satisfies CommandModule<object, Args>