Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For each **source** (a named API, e.g. `atlas`), under `<apiRoot>/<source>/gener
| `functions/**/*.ts` | Typed callers (`getWidgets`, …) |
| `routes.ts` | `Routes` string map + `RouteTargets` enum (name configurable) |
| `runtime.ts` | Re-exports `HTTPFetch`, `httpFetch` (if singleton), routes |
| `base.ts` | `BaseResponse<T>` when the spec uses a response envelope |
| `base.ts` | `BaseResponse<T>` when the spec uses a response envelope (or `base.d.ts` for split declaration output) |

Optional:

Expand Down Expand Up @@ -65,7 +65,7 @@ Prefer the `package.json` script above. To invoke the binary directly:
| `init` | Scaffold `http.ts`, `source.ts`, `known-types.ts` |
| `generate` | Write generated files |
| `check` | Same as `generate --check` — exit 1 if output would change |
| `accept-base` | Update `generated/base.ts` and patch `models.ts` `BaseResponse` |
| `accept-base` | Update generated `base.ts` (`base.d.ts` for split declaration output) and patch `models.ts` `BaseResponse` |

`--check` and `--accept-base` cannot be combined. See [docs/cli.md](docs/cli.md) for the full command reference.

Expand Down Expand Up @@ -138,7 +138,7 @@ Re-exported types from the package root:
| --- | --- |
| `spec` | Project-relative spec path (used when no `--spec` / env override) |
| `functionsDir` | Project-relative function output directory (defaults to the source's `generated/functions`) |
| `typesDir` | Project-relative type output directory (defaults to the source's `generated/types`; a generated `base.ts` is placed beside this directory when customized) |
| `typesDir` | Project-relative type output directory (defaults to the source's `generated/types`; a generated `base.d.ts` is placed beside this directory when customized) |
| `pathPrefix` | Only generate operations under this prefix (e.g. `/api/acme/v3`) |
| `ignorePaths` | Extra paths to skip |
| `stripApiPrefix` | Strip a leading `/api` segment from route enum member names |
Expand Down Expand Up @@ -178,7 +178,8 @@ Adapters implement `HTTPFetch` from `@openmirai/openapi-codegen/http` (or the ax
### 6. Path-alias aware imports

Generated function files import types and `runtime`, and generated response
types import `base.ts`, using:
types import the generated base declaration (`base.ts` in monolith output, or
`base.d.ts` for split declaration output), using:

1. `importBase` in `source.ts`, if set
2. Else `compilerOptions.paths` from the nearest ancestor `tsconfig.json` with path aliases, starting at the corresponding `functionsDir` or `typesDir`
Expand Down
4 changes: 3 additions & 1 deletion src/emitters/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ export function emitTypeFiles(
const typeFile = `${options.typesDir}/${pathItem.cleanPath}/${operation.method.toUpperCase()}.d.ts`;
const baseImportPath = resolveAliasAwareImport({
fromAbsolutePath: typeFile,
toAbsolutePath: options.baseFile.replace(/\.ts$/, ""),
toAbsolutePath: options.baseFile
.replace(/\.d\.ts$/, "")
.replace(/\.ts$/, ""),
...(options.tsconfigPaths === undefined
? {}
: { tsconfigPaths: options.tsconfigPaths }),
Expand Down
2 changes: 1 addition & 1 deletion src/generate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function buildGenerateContext(
baseFile:
sourceConfig.typesDir === undefined
? join(generatedDir, "base.ts")
: join(dirname(typesDir), "base.ts"),
: join(dirname(typesDir), "base.d.ts"),
cwd,
functionsDir,
generatedDir,
Expand Down
3 changes: 2 additions & 1 deletion test/integration/generate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ describe("integration: monolith generate", () => {

await generateForSource({ cwd: root, sourceKey: "core" });

expect(existsSync(join(typesDir, "../base.ts"))).toBe(true);
expect(existsSync(join(typesDir, "../base.d.ts"))).toBe(true);
expect(existsSync(join(typesDir, "../base.ts"))).toBe(false);
expect(existsSync(join(typesDir, "api/acme/v3/widgets/GET.d.ts"))).toBe(
true
);
Expand Down
Loading