@spec2ts/openapi 3.1.2 → 4.0.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 +24 -21
- package/dist/bin/oapi2ts.d.mts +1 -0
- package/dist/bin/oapi2ts.mjs +8 -0
- package/dist/cli/index.d.mts +15 -0
- package/dist/cli/index.mjs +2 -0
- package/dist/command-kheR7V25.mjs +64 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +2 -0
- package/dist/openapi-parser-CQvFG8Kq.mjs +6858 -0
- package/dist/openapi-parser-RoDGKcjO.d.mts +48 -0
- package/package.json +71 -64
- package/bin/oapi2ts.js +0 -4
- package/cli/command.d.ts +0 -12
- package/cli/command.js +0 -72
- package/cli/index.d.ts +0 -1
- package/cli/index.js +0 -9
- package/index.d.ts +0 -1
- package/index.js +0 -17
- package/lib/core-parser.d.ts +0 -39
- package/lib/core-parser.js +0 -194
- package/lib/openapi-parser.d.ts +0 -10
- package/lib/openapi-parser.js +0 -29
package/README.md
CHANGED
|
@@ -8,15 +8,16 @@
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
- **AST-based:** Unlike other code generators `@spec2ts/openapi` does not use templates to generate code but uses TypeScript's built-in API to generate and pretty-print an abstract syntax tree.
|
|
12
|
+
- **Tree-shakeable:** Individually exported types allows you to bundle only the ones you actually use.
|
|
13
|
+
- **YAML or JSON:** Use YAML or JSON for your OpenAPI v3 specification.
|
|
14
|
+
- **External references:** Resolves automatically external references and bundle or import them in generated files.
|
|
15
|
+
- **Implementation agnostic:** Use generated types in any projet or framework.
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
|
19
19
|
Install in your project:
|
|
20
|
+
|
|
20
21
|
```bash
|
|
21
22
|
npm install @spec2ts/openapi
|
|
22
23
|
```
|
|
@@ -56,32 +57,34 @@ async function generateSpec(path: string): Promise<string> {
|
|
|
56
57
|
## Implementations
|
|
57
58
|
|
|
58
59
|
- [x] Types for parameters:
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
- [x] path
|
|
61
|
+
- [x] header
|
|
62
|
+
- [x] query
|
|
63
|
+
- [x] cookie
|
|
63
64
|
- [x] Types for requestBody
|
|
64
65
|
- [x] Types for responses
|
|
65
66
|
- [x] Automatic naming
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
- [x] From operationId
|
|
68
|
+
- [x] From path
|
|
68
69
|
- [x] Parameters merging
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
- [x] From path item
|
|
71
|
+
- [x] From operation
|
|
72
|
+
- [x] Override from operation
|
|
72
73
|
- [x] [Schema references](http://json-schema.org/latest/json-schema-core.html#rfc.section.7.2.2)
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
- [x] Local (filesystem) schema references
|
|
75
|
+
- [x] External (network) schema references
|
|
75
76
|
- [x] Modular architecture
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
- [x] Import local references
|
|
78
|
+
- [x] Embed external references
|
|
78
79
|
|
|
79
80
|
## Compatibility Matrix
|
|
80
81
|
|
|
81
82
|
| TypeScript version | spec2ts version |
|
|
82
|
-
|
|
83
|
-
| v3.x.x | v1 |
|
|
84
|
-
| v4.x.x | v2 |
|
|
83
|
+
| ------------------ | --------------- |
|
|
84
|
+
| v3.x.x | v1 |
|
|
85
|
+
| v4.x.x | v2 |
|
|
86
|
+
| v5.x.x | v3 |
|
|
87
|
+
| v6.x.x | v4 |
|
|
85
88
|
|
|
86
89
|
## License
|
|
87
90
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { i as usage, n as describe, r as handler, t as builder } from "../command-kheR7V25.mjs";
|
|
3
|
+
import yargs from "yargs";
|
|
4
|
+
import { hideBin } from "yargs/helpers";
|
|
5
|
+
//#region src/bin/oapi2ts.ts
|
|
6
|
+
yargs(hideBin(process.argv)).command(usage, describe, builder, handler).help("help", "Show help usage").demandCommand().argv;
|
|
7
|
+
//#endregion
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as ParseOpenApiOptions } from "../openapi-parser-RoDGKcjO.mjs";
|
|
2
|
+
import { Argv } from "yargs";
|
|
3
|
+
//#region src/cli/command.d.ts
|
|
4
|
+
interface BuildTsFromOpenApiOptions extends ParseOpenApiOptions {
|
|
5
|
+
input: string | string[];
|
|
6
|
+
output?: string;
|
|
7
|
+
ext?: string;
|
|
8
|
+
banner?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const usage = "$0 <input..>";
|
|
11
|
+
declare const describe = "Generate TypeScript types from OpenAPI specification";
|
|
12
|
+
declare function builder(argv: Argv): Argv<BuildTsFromOpenApiOptions>;
|
|
13
|
+
declare function handler(options: BuildTsFromOpenApiOptions): Promise<void>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { BuildTsFromOpenApiOptions, builder, describe, handler, usage };
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { n as parseOpenApiFile } from "./openapi-parser-CQvFG8Kq.mjs";
|
|
2
|
+
import { cli, printer } from "@spec2ts/core";
|
|
3
|
+
//#region src/cli/command.ts
|
|
4
|
+
const usage = "$0 <input..>";
|
|
5
|
+
const describe = "Generate TypeScript types from OpenAPI specification";
|
|
6
|
+
function builder(argv) {
|
|
7
|
+
return argv.positional("input", {
|
|
8
|
+
array: true,
|
|
9
|
+
type: "string",
|
|
10
|
+
describe: "Path to OpenAPI Specification(s) to convert to TypeScript",
|
|
11
|
+
demandOption: true
|
|
12
|
+
}).option("output", {
|
|
13
|
+
type: "string",
|
|
14
|
+
alias: "o",
|
|
15
|
+
describe: "Output directory for generated types"
|
|
16
|
+
}).option("ext", {
|
|
17
|
+
type: "string",
|
|
18
|
+
alias: "e",
|
|
19
|
+
describe: "Output extension for generated types",
|
|
20
|
+
choices: [".d.ts", ".ts"]
|
|
21
|
+
}).option("cwd", {
|
|
22
|
+
type: "string",
|
|
23
|
+
alias: "c",
|
|
24
|
+
describe: "Root directory for resolving $refs"
|
|
25
|
+
}).option("avoidAny", {
|
|
26
|
+
type: "boolean",
|
|
27
|
+
describe: "Avoid the `any` type and use `unknown` instead"
|
|
28
|
+
}).option("enableDate", {
|
|
29
|
+
choices: [
|
|
30
|
+
true,
|
|
31
|
+
"strict",
|
|
32
|
+
"lax"
|
|
33
|
+
],
|
|
34
|
+
describe: "Build `Date` for format `date` and `date-time`"
|
|
35
|
+
}).option("lowerHeaders", {
|
|
36
|
+
type: "boolean",
|
|
37
|
+
describe: "Lowercase headers keys to match Node.js standard"
|
|
38
|
+
}).option("banner", {
|
|
39
|
+
type: "string",
|
|
40
|
+
alias: "b",
|
|
41
|
+
describe: "Comment prepended to the top of each generated file"
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function handler(options) {
|
|
45
|
+
const files = await cli.findFiles(options.input);
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
const ast = await parseOpenApiFile(file, options);
|
|
48
|
+
const content = printer.printNodes(ast.all);
|
|
49
|
+
const output = cli.getOutputPath(file, options);
|
|
50
|
+
await cli.mkdirp(output);
|
|
51
|
+
await cli.writeFile(output, (options.banner || defaultBanner()) + "\n\n" + content);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function defaultBanner() {
|
|
55
|
+
return `/**
|
|
56
|
+
* DO NOT MODIFY
|
|
57
|
+
* Generated using @spec2ts/openapi.
|
|
58
|
+
* See https://www.npmjs.com/package/@spec2ts/openapi
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/* eslint-disable */`;
|
|
62
|
+
}
|
|
63
|
+
//#endregion
|
|
64
|
+
export { usage as i, describe as n, handler as r, builder as t };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { _ as parseParameters, a as ParamType, c as createOpenApiResult, d as getOperationName, f as getParamType, g as parseOperation, h as getSchemaFromContent, i as OApiParserContext, l as getContentDeclaration, m as getResponseName, n as parseOpenApi, o as ParseOpenApiResult, p as getPathName, r as parseOpenApiFile, s as addToOpenApiResult, t as ParseOpenApiOptions, u as getOperationIdentifier, v as parsePathItem, y as parseReference } from "./openapi-parser-RoDGKcjO.mjs";
|
|
2
|
+
export { OApiParserContext, ParamType, ParseOpenApiOptions, ParseOpenApiResult, addToOpenApiResult, createOpenApiResult, getContentDeclaration, getOperationIdentifier, getOperationName, getParamType, getPathName, getResponseName, getSchemaFromContent, parseOpenApi, parseOpenApiFile, parseOperation, parseParameters, parsePathItem, parseReference };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as getContentDeclaration, c as getParamType, d as getSchemaFromContent, f as parseOperation, h as parseReference, i as createOpenApiResult, l as getPathName, m as parsePathItem, n as parseOpenApiFile, o as getOperationIdentifier, p as parseParameters, r as addToOpenApiResult, s as getOperationName, t as parseOpenApi, u as getResponseName } from "./openapi-parser-CQvFG8Kq.mjs";
|
|
2
|
+
export { addToOpenApiResult, createOpenApiResult, getContentDeclaration, getOperationIdentifier, getOperationName, getParamType, getPathName, getResponseName, getSchemaFromContent, parseOpenApi, parseOpenApiFile, parseOperation, parseParameters, parsePathItem, parseReference };
|