diff --git a/api/codegen-runtime.api.txt b/api/codegen-runtime.api.txt index f765e91..4ffa5a5 100644 --- a/api/codegen-runtime.api.txt +++ b/api/codegen-runtime.api.txt @@ -8,6 +8,8 @@ ApiServer · interface · enum?: readonly string[]; ApiServer · interface · description?: string; ApiServer · interface · }>>; ApiServer · interface · } +Binding · type · export type Binding = HttpBinding | RpcBinding | GraphqlBinding; +Confidence · type · export type Confidence = "contract" | "example" | "inferred" | "override"; Effect · type · export type Effect = "read" | "write" | "destructive"; GraphqlBinding · interface · export interface GraphqlBinding { GraphqlBinding · interface · kind: "graphql"; @@ -16,6 +18,11 @@ GraphqlBinding · interface · field: string; GraphqlBinding · interface · variables: Readonly>; GraphqlBinding · interface · selection: string; GraphqlBinding · interface · } +HttpBinding · interface · export interface HttpBinding { +HttpBinding · interface · kind: "http"; +HttpBinding · interface · method: HttpMethod; +HttpBinding · interface · path: string; +HttpBinding · interface · } ManifestOperation · interface · export interface ManifestOperation { ManifestOperation · interface · id: string; ManifestOperation · interface · command: string; @@ -93,6 +100,10 @@ Pagination · type · style: "link"; Pagination · type · next: string; Pagination · type · items?: string; Pagination · type · }; +RpcBinding · interface · export interface RpcBinding { +RpcBinding · interface · kind: "rpc"; +RpcBinding · interface · name: string; +RpcBinding · interface · } SchemaNode · type · export type SchemaNode = SchemaCommon & ({ SchemaNode · type · type: "ref"; SchemaNode · type · ref: string; diff --git a/changes/fix-codegen-runtime-default.md b/changes/fix-codegen-runtime-default.md new file mode 100644 index 0000000..4524fb0 --- /dev/null +++ b/changes/fix-codegen-runtime-default.md @@ -0,0 +1,10 @@ +### Added + +- **`/codegen/runtime` exports `Binding`, `HttpBinding`, `RpcBinding` and `Confidence`.** A CLI that reads an + operation's binding or how far it is trusted no longer imports the experimental `/codegen` for the type. + +### Changed — experimental + +- **The generated manifest and definitions import their types from `@wirecat/cli-base/codegen/runtime`** when + `coreImport` is not given, not from `/codegen`. Every type they name is there, and `/codegen/runtime` is part of + the stable API, so a CLI no longer passes `coreImport` by hand. Regenerating changes that one import line. diff --git a/src/codegen/manifest.ts b/src/codegen/manifest.ts index cc4e650..f13ded3 100644 --- a/src/codegen/manifest.ts +++ b/src/codegen/manifest.ts @@ -92,7 +92,7 @@ export const manifestGenerator = ).filter(([, , , value]) => value !== undefined) const types = ["ManifestOperation", ...extras.map(([, type]) => type)].sort() const content = [ - `import type { ${types.join(", ")} } from "${options.coreImport ?? "@wirecat/cli-base/codegen"}"`, + `import type { ${types.join(", ")} } from "${options.coreImport ?? "@wirecat/cli-base/codegen/runtime"}"`, "", `export const operations: readonly ManifestOperation[] = ${JSON.stringify(operations, null, 2)}`, ...extras.flatMap(([name, , type, value]) => [ @@ -112,7 +112,7 @@ export const definitionsGenerator = return [ { path: options.path, - content: `import type { SchemaNode } from "${options.coreImport ?? "@wirecat/cli-base/codegen"}"\n\nexport const definitions: Readonly> = ${JSON.stringify(definitions, null, 2)}\n`, + content: `import type { SchemaNode } from "${options.coreImport ?? "@wirecat/cli-base/codegen/runtime"}"\n\nexport const definitions: Readonly> = ${JSON.stringify(definitions, null, 2)}\n`, }, ] } diff --git a/src/codegen/openapi.test.ts b/src/codegen/openapi.test.ts index d22aa24..76f3084 100644 --- a/src/codegen/openapi.test.ts +++ b/src/codegen/openapi.test.ts @@ -668,7 +668,7 @@ describe("adaptOpenApi reads what a CLI would otherwise write by hand", () => { expect(model.operations.find((candidate) => candidate.id === "open")?.security).toEqual([]) const [manifest] = generate(model, [manifestGenerator({ path: "manifest.ts" })], { banner: [] }) expect(manifest?.content).toContain( - 'import type { ApiServer, ManifestOperation, SecurityRequirement, SecurityScheme } from "@wirecat/cli-base/codegen"', + 'import type { ApiServer, ManifestOperation, SecurityRequirement, SecurityScheme } from "@wirecat/cli-base/codegen/runtime"', ) expect(manifest?.content).toContain('"security": []') }) diff --git a/src/codegen/runtime.ts b/src/codegen/runtime.ts index e74779e..6622362 100644 --- a/src/codegen/runtime.ts +++ b/src/codegen/runtime.ts @@ -78,12 +78,16 @@ export const unique = (items: readonly unknown[]): boolean => export type { ManifestOperation } from "./manifest.js" export type { ApiServer, + Binding, + Confidence, Effect, GraphqlBinding, + HttpBinding, OAuthFlow, OperationPermission, PageParameter, Pagination, + RpcBinding, SchemaNode, SecurityRequirement, SecurityScheme,