@codewithagents/openapi-server 1.3.1 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/cli-args.d.ts +23 -0
- package/dist/cli-args.d.ts.map +1 -0
- package/dist/cli-args.js +37 -0
- package/dist/cli-args.js.map +1 -0
- package/dist/cli.cjs +787 -321
- package/dist/plugins/router.d.ts.map +1 -1
- package/dist/plugins/router.js +406 -111
- package/dist/plugins/router.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
Generate a typed service interface from your OpenAPI 3.x spec. Framework-agnostic by design: wire it to Hono, Express, Fastify, or any router you already use.
|
|
11
11
|
|
|
12
12
|
- **Framework-agnostic service interface**: `service.ts` is a plain TypeScript interface with no framework imports. Implement it however you want: Hono, Express, Fastify, Koa, plain `http`, Bun, Deno, or anything else.
|
|
13
|
-
- **Optional router scaffolding**: set `"framework"
|
|
13
|
+
- **Optional router scaffolding**: set `"framework"` to `"hono"`, `"express"`, or `"fastify"` and get a ready-to-mount router as a starting point. Set `"framework": "none"` (the default) and wire the interface yourself. The generated code only ever imports what you already have.
|
|
14
14
|
- **Type-safe contract**: the compiler tells you if your implementation drifts from the spec. Add an endpoint in the spec and forget to implement it. TypeScript fails the build.
|
|
15
15
|
- **Prettier-clean output**: every generated file passes `prettier --check` out of the box.
|
|
16
16
|
- **OpenAPI 3.x**: 3.1.x primary target, 3.0.x best-effort. Full support for `$ref`, `allOf`, `anyOf`, `oneOf`, `nullable`.
|
|
@@ -38,7 +38,7 @@ Requires [`@codewithagents/openapi-gen`](../openapi-gen). Run both generators to
|
|
|
38
38
|
{
|
|
39
39
|
"input_openapi": "./spec/api.json",
|
|
40
40
|
"output": "./generated",
|
|
41
|
-
"framework": "hono" // or "
|
|
41
|
+
"framework": "hono" // or "express", "fastify", "none" (none = service.ts only, default)
|
|
42
42
|
}
|
|
43
43
|
```
|
|
44
44
|
|
|
@@ -215,7 +215,7 @@ See the [full configuration reference](https://openapi.codewithagents.de/openapi
|
|
|
215
215
|
{
|
|
216
216
|
"input_openapi": "./spec/api.json", // required: path to OpenAPI 3.x spec (JSON or YAML)
|
|
217
217
|
"output": "./generated", // required: directory to write generated files
|
|
218
|
-
"framework": "hono", // optional: router target (default: "
|
|
218
|
+
"framework": "hono", // optional: router target (default: "none")
|
|
219
219
|
"input_schema": "./generated/schemas.ts" // optional: Zod schema file for request validation
|
|
220
220
|
}
|
|
221
221
|
```
|
|
@@ -224,7 +224,7 @@ See the [full configuration reference](https://openapi.codewithagents.de/openapi
|
|
|
224
224
|
|---|---|---|---|
|
|
225
225
|
| `input_openapi` | Yes | n/a | Path to OpenAPI 3.x spec |
|
|
226
226
|
| `output` | Yes | n/a | Directory to write `service.ts` and `router.ts` |
|
|
227
|
-
| `framework` | No | `"
|
|
227
|
+
| `framework` | No | `"none"` | Router framework to generate: `"hono"`, `"express"`, `"fastify"`, or `"none"`. Use `"none"` to generate only `service.ts` |
|
|
228
228
|
| `input_schema` | No | none | Path to user-owned Zod schema file. Enables server-side request validation (see below) |
|
|
229
229
|
|
|
230
230
|
Use `--config <path>` to point at a config file in a different location:
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** The parsed result of CLI arguments. */
|
|
2
|
+
export type CliAction = {
|
|
3
|
+
action: 'help';
|
|
4
|
+
} | {
|
|
5
|
+
action: 'version';
|
|
6
|
+
} | {
|
|
7
|
+
action: 'run';
|
|
8
|
+
configFile?: string;
|
|
9
|
+
cwd: string;
|
|
10
|
+
} | {
|
|
11
|
+
action: 'error';
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Parse raw process.argv into a structured action.
|
|
16
|
+
*
|
|
17
|
+
* Pure function: no I/O, no process.exit. Testable in isolation.
|
|
18
|
+
*
|
|
19
|
+
* @param argv process.argv (first two entries are node + script path)
|
|
20
|
+
* @param cwd the working directory to resolve paths against
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseCliArgs(argv: string[], cwd: string): CliAction;
|
|
23
|
+
//# sourceMappingURL=cli-args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../src/cli-args.ts"],"names":[],"mappings":"AAEA,0CAA0C;AAC1C,MAAM,MAAM,SAAS,GACjB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,SAAS,CAAA;CAAE,GACrB;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACnD;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAExC;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CA8BnE"}
|
package/dist/cli-args.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { resolve, dirname } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Parse raw process.argv into a structured action.
|
|
4
|
+
*
|
|
5
|
+
* Pure function: no I/O, no process.exit. Testable in isolation.
|
|
6
|
+
*
|
|
7
|
+
* @param argv process.argv (first two entries are node + script path)
|
|
8
|
+
* @param cwd the working directory to resolve paths against
|
|
9
|
+
*/
|
|
10
|
+
export function parseCliArgs(argv, cwd) {
|
|
11
|
+
const args = argv.slice(2);
|
|
12
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
13
|
+
return { action: 'help' };
|
|
14
|
+
}
|
|
15
|
+
if (args.includes('--version') || args.includes('-v')) {
|
|
16
|
+
return { action: 'version' };
|
|
17
|
+
}
|
|
18
|
+
const configIdx = args.indexOf('--config');
|
|
19
|
+
if (configIdx !== -1) {
|
|
20
|
+
const next = args[configIdx + 1];
|
|
21
|
+
if (next === undefined || next.startsWith('--')) {
|
|
22
|
+
return {
|
|
23
|
+
action: 'error',
|
|
24
|
+
message: [
|
|
25
|
+
'Error: --config requires a file path argument',
|
|
26
|
+
'Usage: openapi-server [--config <path-to-config.json>]',
|
|
27
|
+
].join('\n'),
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const configFile = resolve(cwd, next);
|
|
31
|
+
// Relative paths inside the config resolve from the config file's directory,
|
|
32
|
+
// not from the shell's CWD. This matches how most tooling works.
|
|
33
|
+
return { action: 'run', configFile, cwd: dirname(configFile) };
|
|
34
|
+
}
|
|
35
|
+
return { action: 'run', cwd };
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=cli-args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli-args.js","sourceRoot":"","sources":["../src/cli-args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAS5C;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,IAAc,EAAE,GAAW;IACtD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAE1B,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAA;IAC3B,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACtD,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAA;IAC9B,CAAC;IAED,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;IAC1C,IAAI,SAAS,KAAK,CAAC,CAAC,EAAE,CAAC;QACrB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC,CAAA;QAChC,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;YAChD,OAAO;gBACL,MAAM,EAAE,OAAO;gBACf,OAAO,EAAE;oBACP,+CAA+C;oBAC/C,wDAAwD;iBACzD,CAAC,IAAI,CAAC,IAAI,CAAC;aACb,CAAA;QACH,CAAC;QACD,MAAM,UAAU,GAAG,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAA;QACrC,6EAA6E;QAC7E,iEAAiE;QACjE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE,CAAA;IAChE,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAA;AAC/B,CAAC"}
|