@twin.org/ts-to-openapi 0.0.1-next.2
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/LICENSE +201 -0
- package/README.md +21 -0
- package/bin/index.js +8 -0
- package/dist/cjs/index.cjs +1124 -0
- package/dist/esm/index.mjs +1118 -0
- package/dist/locales/en.json +274 -0
- package/dist/types/cli.d.ts +19 -0
- package/dist/types/commands/httpStatusCodeMap.d.ts +20 -0
- package/dist/types/commands/tsToOpenApi.d.ts +21 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/models/IInputPath.d.ts +68 -0
- package/dist/types/models/IInputResult.d.ts +15 -0
- package/dist/types/models/IOpenApi.d.ts +54 -0
- package/dist/types/models/IOpenApiExample.d.ts +13 -0
- package/dist/types/models/IOpenApiHeader.d.ts +19 -0
- package/dist/types/models/IOpenApiPathMethod.d.ts +64 -0
- package/dist/types/models/IOpenApiResponse.d.ts +32 -0
- package/dist/types/models/IOpenApiSecurityScheme.d.ts +25 -0
- package/dist/types/models/IPackageJson.d.ts +15 -0
- package/dist/types/models/ITsToOpenApiConfig.d.ts +61 -0
- package/dist/types/models/ITsToOpenApiConfigEntryPoint.d.ts +17 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +890 -0
- package/docs/reference/classes/CLI.md +67 -0
- package/docs/reference/functions/actionCommandTsToOpenApi.md +23 -0
- package/docs/reference/functions/buildCommandTsToOpenApi.md +15 -0
- package/docs/reference/functions/tsToOpenApi.md +23 -0
- package/docs/reference/index.md +16 -0
- package/docs/reference/interfaces/ITsToOpenApiConfig.md +79 -0
- package/docs/reference/interfaces/ITsToOpenApiConfigEntryPoint.md +27 -0
- package/locales/en.json +45 -0
- package/package.json +78 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Class: CLI
|
|
2
|
+
|
|
3
|
+
The main entry point for the CLI.
|
|
4
|
+
|
|
5
|
+
## Extends
|
|
6
|
+
|
|
7
|
+
- `CLIBase`
|
|
8
|
+
|
|
9
|
+
## Constructors
|
|
10
|
+
|
|
11
|
+
### new CLI()
|
|
12
|
+
|
|
13
|
+
> **new CLI**(): [`CLI`](CLI.md)
|
|
14
|
+
|
|
15
|
+
#### Returns
|
|
16
|
+
|
|
17
|
+
[`CLI`](CLI.md)
|
|
18
|
+
|
|
19
|
+
#### Inherited from
|
|
20
|
+
|
|
21
|
+
`CLIBase.constructor`
|
|
22
|
+
|
|
23
|
+
## Methods
|
|
24
|
+
|
|
25
|
+
### run()
|
|
26
|
+
|
|
27
|
+
> **run**(`argv`, `localesDirectory`?): `Promise`\<`number`\>
|
|
28
|
+
|
|
29
|
+
Run the app.
|
|
30
|
+
|
|
31
|
+
#### Parameters
|
|
32
|
+
|
|
33
|
+
• **argv**: `string`[]
|
|
34
|
+
|
|
35
|
+
The process arguments.
|
|
36
|
+
|
|
37
|
+
• **localesDirectory?**: `string`
|
|
38
|
+
|
|
39
|
+
The directory for the locales, default to relative to the script.
|
|
40
|
+
|
|
41
|
+
#### Returns
|
|
42
|
+
|
|
43
|
+
`Promise`\<`number`\>
|
|
44
|
+
|
|
45
|
+
The exit code.
|
|
46
|
+
|
|
47
|
+
***
|
|
48
|
+
|
|
49
|
+
### configureRoot()
|
|
50
|
+
|
|
51
|
+
> `protected` **configureRoot**(`program`): `void`
|
|
52
|
+
|
|
53
|
+
Configure any options or actions at the root program level.
|
|
54
|
+
|
|
55
|
+
#### Parameters
|
|
56
|
+
|
|
57
|
+
• **program**: `Command`
|
|
58
|
+
|
|
59
|
+
The root program command.
|
|
60
|
+
|
|
61
|
+
#### Returns
|
|
62
|
+
|
|
63
|
+
`void`
|
|
64
|
+
|
|
65
|
+
#### Overrides
|
|
66
|
+
|
|
67
|
+
`CLIBase.configureRoot`
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Function: actionCommandTsToOpenApi()
|
|
2
|
+
|
|
3
|
+
> **actionCommandTsToOpenApi**(`configFile`, `outputFile`, `opts`): `Promise`\<`void`\>
|
|
4
|
+
|
|
5
|
+
Action the root command.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
• **configFile**: `string`
|
|
10
|
+
|
|
11
|
+
The optional configuration file.
|
|
12
|
+
|
|
13
|
+
• **outputFile**: `string`
|
|
14
|
+
|
|
15
|
+
The output file for the generation OpenApi spec.
|
|
16
|
+
|
|
17
|
+
• **opts**: `unknown`
|
|
18
|
+
|
|
19
|
+
The options for the command.
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
`Promise`\<`void`\>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Function: buildCommandTsToOpenApi()
|
|
2
|
+
|
|
3
|
+
> **buildCommandTsToOpenApi**(`program`): `void`
|
|
4
|
+
|
|
5
|
+
Build the root command to be consumed by the CLI.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
• **program**: `Command`
|
|
10
|
+
|
|
11
|
+
The command to build on.
|
|
12
|
+
|
|
13
|
+
## Returns
|
|
14
|
+
|
|
15
|
+
`void`
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Function: tsToOpenApi()
|
|
2
|
+
|
|
3
|
+
> **tsToOpenApi**(`config`, `outputFile`, `workingDirectory`): `Promise`\<`void`\>
|
|
4
|
+
|
|
5
|
+
Convert the TypeScript definitions to OpenAPI spec.
|
|
6
|
+
|
|
7
|
+
## Parameters
|
|
8
|
+
|
|
9
|
+
• **config**: [`ITsToOpenApiConfig`](../interfaces/ITsToOpenApiConfig.md)
|
|
10
|
+
|
|
11
|
+
The configuration for the app.
|
|
12
|
+
|
|
13
|
+
• **outputFile**: `string`
|
|
14
|
+
|
|
15
|
+
The location of the file to output the OpenAPI spec.
|
|
16
|
+
|
|
17
|
+
• **workingDirectory**: `string`
|
|
18
|
+
|
|
19
|
+
The folder the app was run from.
|
|
20
|
+
|
|
21
|
+
## Returns
|
|
22
|
+
|
|
23
|
+
`Promise`\<`void`\>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @twin.org/ts-to-openapi
|
|
2
|
+
|
|
3
|
+
## Classes
|
|
4
|
+
|
|
5
|
+
- [CLI](classes/CLI.md)
|
|
6
|
+
|
|
7
|
+
## Interfaces
|
|
8
|
+
|
|
9
|
+
- [ITsToOpenApiConfig](interfaces/ITsToOpenApiConfig.md)
|
|
10
|
+
- [ITsToOpenApiConfigEntryPoint](interfaces/ITsToOpenApiConfigEntryPoint.md)
|
|
11
|
+
|
|
12
|
+
## Functions
|
|
13
|
+
|
|
14
|
+
- [buildCommandTsToOpenApi](functions/buildCommandTsToOpenApi.md)
|
|
15
|
+
- [actionCommandTsToOpenApi](functions/actionCommandTsToOpenApi.md)
|
|
16
|
+
- [tsToOpenApi](functions/tsToOpenApi.md)
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Interface: ITsToOpenApiConfig
|
|
2
|
+
|
|
3
|
+
Configuration for the API.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### title
|
|
8
|
+
|
|
9
|
+
> **title**: `string`
|
|
10
|
+
|
|
11
|
+
Title of the API.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### version
|
|
16
|
+
|
|
17
|
+
> **version**: `string`
|
|
18
|
+
|
|
19
|
+
The version.
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### description
|
|
24
|
+
|
|
25
|
+
> **description**: `string`
|
|
26
|
+
|
|
27
|
+
Description of the API.
|
|
28
|
+
|
|
29
|
+
***
|
|
30
|
+
|
|
31
|
+
### licenseName
|
|
32
|
+
|
|
33
|
+
> **licenseName**: `string`
|
|
34
|
+
|
|
35
|
+
The license to use.
|
|
36
|
+
|
|
37
|
+
***
|
|
38
|
+
|
|
39
|
+
### licenseUrl
|
|
40
|
+
|
|
41
|
+
> **licenseUrl**: `string`
|
|
42
|
+
|
|
43
|
+
The license URL.
|
|
44
|
+
|
|
45
|
+
***
|
|
46
|
+
|
|
47
|
+
### servers
|
|
48
|
+
|
|
49
|
+
> **servers**: `string`[]
|
|
50
|
+
|
|
51
|
+
The servers for the endpoints.
|
|
52
|
+
|
|
53
|
+
***
|
|
54
|
+
|
|
55
|
+
### authMethods?
|
|
56
|
+
|
|
57
|
+
> `optional` **authMethods**: `string`[]
|
|
58
|
+
|
|
59
|
+
The authentication methods.
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
63
|
+
### restRoutes
|
|
64
|
+
|
|
65
|
+
> **restRoutes**: `object`[]
|
|
66
|
+
|
|
67
|
+
The packages containing routes.
|
|
68
|
+
|
|
69
|
+
***
|
|
70
|
+
|
|
71
|
+
### externalReferences?
|
|
72
|
+
|
|
73
|
+
> `optional` **externalReferences**: `object`
|
|
74
|
+
|
|
75
|
+
External type references
|
|
76
|
+
|
|
77
|
+
#### Index Signature
|
|
78
|
+
|
|
79
|
+
\[`id`: `string`\]: `string`
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Interface: ITsToOpenApiConfigEntryPoint
|
|
2
|
+
|
|
3
|
+
Configuration for the API.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
### name
|
|
8
|
+
|
|
9
|
+
> **name**: `string`
|
|
10
|
+
|
|
11
|
+
Match the name of the exported entry point.
|
|
12
|
+
|
|
13
|
+
***
|
|
14
|
+
|
|
15
|
+
### baseRoutePath?
|
|
16
|
+
|
|
17
|
+
> `optional` **baseRoutePath**: `string`
|
|
18
|
+
|
|
19
|
+
The base route path to use, defaults to the one in the entry point.
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### operationIdDistinguisher?
|
|
24
|
+
|
|
25
|
+
> `optional` **operationIdDistinguisher**: `string`
|
|
26
|
+
|
|
27
|
+
If using the same routes on multiple paths use the distinguisher to avoid operationId clashes, will be appended to operationIds.
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"error": {
|
|
3
|
+
"commands": {
|
|
4
|
+
"ts-to-openapi": {
|
|
5
|
+
"configFailed": "Configuration failed to load.",
|
|
6
|
+
"missingRestRoutesEntryPoints": "Missing REST routes method \"{method}\" in package \"{package}\".",
|
|
7
|
+
"missingRestRoutesEntryPoint": "Missing REST routes entryPoint \"{entryPoint}\" in package \"{package}\".",
|
|
8
|
+
"unsupportedProperties": "Unsupported properties found in the request object \"{keys}\"."
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"commands": {
|
|
13
|
+
"ts-to-openapi": {
|
|
14
|
+
"options": {
|
|
15
|
+
"config": {
|
|
16
|
+
"param": "'<'config'>'",
|
|
17
|
+
"description": "Path to the JSON configuration file."
|
|
18
|
+
},
|
|
19
|
+
"output-file": {
|
|
20
|
+
"param": "'<'output-file'>'",
|
|
21
|
+
"description": "The JSON file to write the OpenAPI spec."
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"progress": {
|
|
25
|
+
"loadingConfigJson": "Loading Config JSON",
|
|
26
|
+
"creatingWorkingDir": "Creating Working Directory",
|
|
27
|
+
"creatingSecuritySchemas": "Creating Security Schemas",
|
|
28
|
+
"generatingSchemas": "Generating Schemas",
|
|
29
|
+
"finalisingSchemas": "Finalising Schemas",
|
|
30
|
+
"writingOutputFile": "Writing Output File",
|
|
31
|
+
"models": "Models",
|
|
32
|
+
"installingNpmPackages": "Installing NPM Packages",
|
|
33
|
+
"processingPackage": "Processing Package",
|
|
34
|
+
"importingModule": "Importing Module",
|
|
35
|
+
"processingRoutes": "Processing Routes"
|
|
36
|
+
},
|
|
37
|
+
"labels": {
|
|
38
|
+
"configJson": "Config JSON",
|
|
39
|
+
"outputFile": "Output File",
|
|
40
|
+
"outputWorkingDir": "Output Working Directory",
|
|
41
|
+
"route": "Route"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@twin.org/ts-to-openapi",
|
|
3
|
+
"version": "0.0.1-next.2",
|
|
4
|
+
"description": "Tool to convert TypeScript REST route definitions to OpenAPI Specifications",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/twinfoundation/tools.git",
|
|
8
|
+
"directory": "packages/ts-to-openapi"
|
|
9
|
+
},
|
|
10
|
+
"author": "martyn.janes@iota.org",
|
|
11
|
+
"license": "Apache-2.0",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=20.0.0"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"clean": "rimraf dist coverage",
|
|
18
|
+
"build": "tspc",
|
|
19
|
+
"merge-locales": "merge-locales",
|
|
20
|
+
"test": "vitest --run --config ./vitest.config.ts --no-cache",
|
|
21
|
+
"coverage": "vitest --run --coverage --config ./vitest.config.ts --no-cache",
|
|
22
|
+
"bundle:esm": "rollup --config rollup.config.mjs --environment MODULE:esm",
|
|
23
|
+
"bundle:cjs": "rollup --config rollup.config.mjs --environment MODULE:cjs",
|
|
24
|
+
"bundle": "npm run bundle:esm && npm run bundle:cjs",
|
|
25
|
+
"docs:clean": "rimraf docs/reference",
|
|
26
|
+
"docs:generate": "typedoc",
|
|
27
|
+
"docs": "npm run docs:clean && npm run docs:generate",
|
|
28
|
+
"dist": "npm run clean && npm run build && npm run merge-locales && npm run test && npm run bundle && npm run docs"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@twin.org/api-models": "next",
|
|
32
|
+
"@twin.org/cli-core": "next",
|
|
33
|
+
"@twin.org/core": "next",
|
|
34
|
+
"@twin.org/nameof": "0.0.1-next.2",
|
|
35
|
+
"@twin.org/web": "next",
|
|
36
|
+
"commander": "12.1.0",
|
|
37
|
+
"glob": "11.0.0",
|
|
38
|
+
"jsonschema": "1.4.1",
|
|
39
|
+
"ts-json-schema-generator": "2.4.0-next.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@twin.org/merge-locales": "0.0.1-next.2",
|
|
43
|
+
"@twin.org/nameof-transformer": "0.0.1-next.2",
|
|
44
|
+
"@types/node": "22.5.5",
|
|
45
|
+
"@vitest/coverage-v8": "2.1.1",
|
|
46
|
+
"copyfiles": "2.4.1",
|
|
47
|
+
"rimraf": "6.0.1",
|
|
48
|
+
"rollup": "4.21.3",
|
|
49
|
+
"rollup-plugin-typescript2": "0.36.0",
|
|
50
|
+
"ts-patch": "3.2.1",
|
|
51
|
+
"typedoc": "0.26.7",
|
|
52
|
+
"typedoc-plugin-markdown": "4.2.7",
|
|
53
|
+
"typescript": "5.6.2",
|
|
54
|
+
"vitest": "2.1.1"
|
|
55
|
+
},
|
|
56
|
+
"main": "./dist/cjs/index.cjs",
|
|
57
|
+
"module": "./dist/esm/index.mjs",
|
|
58
|
+
"types": "./dist/types/index.d.ts",
|
|
59
|
+
"exports": {
|
|
60
|
+
".": {
|
|
61
|
+
"require": "./dist/cjs/index.cjs",
|
|
62
|
+
"import": "./dist/esm/index.mjs",
|
|
63
|
+
"types": "./dist/types/index.d.ts"
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
"files": [
|
|
67
|
+
"bin",
|
|
68
|
+
"dist/cjs",
|
|
69
|
+
"dist/esm",
|
|
70
|
+
"dist/locales",
|
|
71
|
+
"dist/types",
|
|
72
|
+
"locales",
|
|
73
|
+
"docs"
|
|
74
|
+
],
|
|
75
|
+
"bin": {
|
|
76
|
+
"ts-to-openapi": "bin/index.js"
|
|
77
|
+
}
|
|
78
|
+
}
|