API Reference
Complete API documentation for @powerduck/openapi-codegen v0.5.3.
Top-level functions
| Export | Signature | Description |
|---|---|---|
generate | (options: GenerateOptions) => string | Generate runnable source code for one operation |
register | (generator: Generator) => void | Register a custom generator |
get | (language: string, client: string) => Generator | undefined | Look up a generator |
list | () => Array<{ language: string; client: string }> | List all registered generators |
use | (plugin: Plugin) => void | Apply a plugin that registers generators |
registerBuiltins | () => void | Register all built-in generators (auto-called on import) |
normalize | (options) => NormalizedRequest | Turn a document + path + method into a normalized request |
builtinGenerators | Generator[] | The raw array of all built-in generator definitions |
Built-ins are registered automatically when the module loads, so calling
registerBuiltins() manually is optional.
generate(options)
generate(options: GenerateOptions): string
Returns generated source code as a string. Looks up the generator with
get(options.language, options.client); if options.request is absent, calls
normalize({ document, path, method, serverUrl, securityValues, softRefMode });
then calls generator.generate(request).
Throws:
TypeErrorwhenoptionsis not an object, or required inputs are missing.Error: Unsupported generator: <language>/<client>for an unknown combo.- Errors from
normalize()(unknown path/method, invalid document, broken/circular$refunlesssoftRefMode).
See Configuration for the full option table.
register(generator)
register({
language: "mylang",
client: "my-client",
generate(request) {
return `// ${request.method} ${request.path}`;
},
});
Registers into the internal case-insensitive store, keyed by
language\0client.
get(language, client)
const generator = get("javascript", "fetch");
Returns the Generator or undefined if not found.
list()
const combos = list();
// [{ language: "c", client: "libcurl" }, ...]
use(plugin)
use({
name: "my-plugin",
register({ register }) {
register(customGenerator);
},
});
Equivalent to calling plugin.register({ register }).
registerBuiltins()
registerBuiltins();
Idempotent (guarded by an internal flag). Registers every entry in
builtinGenerators.
normalize(options)
import { normalize } from "@powerduck/openapi-codegen";
const request = normalize({
document,
path: "/pets/{id}",
method: "get",
serverUrl: "https://example.com",
securityValues: { bearerAuth: "token" },
softRefMode: false,
});
Resolves $refs, merges path/operation parameters, picks a request body media
type, generates example values, resolves security, and computes baseUrl.
Throws for unknown paths/methods and unsupported methods.
Built-in generators (21 languages, 41 clients)
The exact language / client identifiers, as registered in
src/emitters/index.ts. Identifiers are case-sensitive.
| Language | language | client values |
|---|---|---|
| C | c | libcurl |
| C# | csharp | httpclient, restsharp |
| Clojure | clojure | clj-http |
| Dart | dart | http |
| F# | fsharp | httpclient |
| Go | go | new-request |
| HTTP request file | http | http1 |
| Java | java | asynchttp, java-net-http, okhttp, unirest |
| JavaScript | javascript | axios, fetch, jquery, ofetch, xhr |
| Kotlin | kotlin | okhttp |
| Node.js | node | axios, fetch, ofetch, undici |
| Objective-C | objc | nsurlsession |
| OCaml | ocaml | cohttp |
| PHP | php | curl, guzzle, laravel-http |
| PowerShell | powershell | invoke-restmethod, invoke-webrequest |
| Python | python | aiohttp, http-client, httpx-async, httpx-sync, requests |
| R | r | httr2 |
| Ruby | ruby | net-http |
| Rust | rust | reqwest |
| Shell | shell | curl, httpie, wget |
| Swift | swift | nsurlsession |
Count: 21 languages, 41 combinations.
Generator availability does not mean every client can represent every operation. For example,
shell/wgetcannot safely build arbitrarymultipart/form-datarequests; useshell/curlorshell/httpieinstead.
Core types
Re-exported from ./types:
type ParameterLocation = "path" | "query" | "querystring" | "header" | "cookie";
interface FileValue { __file: true; path?; name?; contentType?; data?; }
interface Parameter { name; in: ParameterLocation; value: unknown; style?; explode?; allowReserved?; }
interface Body { mediaType: string; value: unknown; encoding?: Record<string, unknown>; }
interface Security { name; type; scheme?; in?; paramName?; value: string; }
interface RequestIR { method; baseUrl; path; parameters: Parameter[]; headers: Parameter[]; body?; security: Security[]; }
interface GenerateResult { code: string; files?: Record<string, string>; metadata?: Record<string, unknown>; }
interface Generator { language: string; client: string; generate(request: RequestIR): string; }
interface Plugin { name: string; register(api: { register(g: Generator): void }): void; }
interface GenerateOptions { language; client; request?; document?; path?; method?; serverUrl?; securityValues?; softRefMode?; }
Core functions
All are re-exported from the package root.