@twin.org/ts-to-openapi 0.0.2-next.1 → 0.0.2-next.3
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/dist/cjs/index.cjs +7 -5
- package/dist/esm/index.mjs +8 -6
- package/docs/changelog.md +28 -0
- package/package.json +3 -3
- package/dist/types/models/IOpenApi.d.ts +0 -54
- package/dist/types/models/IOpenApiExample.d.ts +0 -13
- package/dist/types/models/IOpenApiHeader.d.ts +0 -19
- package/dist/types/models/IOpenApiPathMethod.d.ts +0 -64
- package/dist/types/models/IOpenApiResponse.d.ts +0 -32
- package/dist/types/models/IOpenApiSecurityScheme.d.ts +0 -25
package/dist/cjs/index.cjs
CHANGED
|
@@ -196,7 +196,7 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
196
196
|
compilerOptions: {}
|
|
197
197
|
}, undefined, "\t"));
|
|
198
198
|
const openApi = {
|
|
199
|
-
openapi:
|
|
199
|
+
openapi: toolsCore.OpenApiHelper.API_VERSION,
|
|
200
200
|
info: {
|
|
201
201
|
title: config.title,
|
|
202
202
|
description: config.description,
|
|
@@ -241,7 +241,7 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
241
241
|
}
|
|
242
242
|
cliCore.CLIDisplay.task(core.I18n.formatMessage("commands.ts-to-openapi.progress.generatingSchemas"));
|
|
243
243
|
const autoExpandTypes = config.autoExpandTypes ?? [];
|
|
244
|
-
const defaultExpandTypes = ["ObjectOrArray
|
|
244
|
+
const defaultExpandTypes = ["/ObjectOrArray<.*>/"];
|
|
245
245
|
for (const defaultType of defaultExpandTypes) {
|
|
246
246
|
if (!autoExpandTypes.includes(defaultType)) {
|
|
247
247
|
autoExpandTypes.push(defaultType);
|
|
@@ -665,7 +665,6 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
|
|
|
665
665
|
if (/I[A-Z]/.test(finalName)) {
|
|
666
666
|
finalName = finalName.slice(1);
|
|
667
667
|
}
|
|
668
|
-
finalName = finalName.replace("<", "_").replace(">", "_");
|
|
669
668
|
if (finalName.endsWith("[]")) {
|
|
670
669
|
finalName = `ListOf${finalName.slice(0, -2)}`;
|
|
671
670
|
}
|
|
@@ -872,7 +871,10 @@ async function generateSchemas(modelDirWildcards, types, autoExpandTypes, output
|
|
|
872
871
|
}
|
|
873
872
|
}
|
|
874
873
|
const referencedSchemas = {};
|
|
875
|
-
toolsCore.JsonSchemaHelper.extractTypes(allSchemas, [
|
|
874
|
+
toolsCore.JsonSchemaHelper.extractTypes(allSchemas, [
|
|
875
|
+
...types,
|
|
876
|
+
...autoExpandTypes.map(t => (t.startsWith("/") && t.endsWith("/") ? new RegExp(t) : t))
|
|
877
|
+
], referencedSchemas);
|
|
876
878
|
toolsCore.JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
|
|
877
879
|
for (const arraySingularType of arraySingularTypes) {
|
|
878
880
|
referencedSchemas[`${arraySingularType}[]`] = {
|
|
@@ -1053,7 +1055,7 @@ class CLI extends cliCore.CLIBase {
|
|
|
1053
1055
|
return this.execute({
|
|
1054
1056
|
title: "TWIN TypeScript To OpenAPI",
|
|
1055
1057
|
appName: "ts-to-openapi",
|
|
1056
|
-
version: "0.0.2-next.
|
|
1058
|
+
version: "0.0.2-next.3", // x-release-please-version
|
|
1057
1059
|
icon: "⚙️ ",
|
|
1058
1060
|
supportsEnvFiles: false,
|
|
1059
1061
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
3
3
|
import { CLIDisplay, CLIUtils, CLIBase } from '@twin.org/cli-core';
|
|
4
4
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { I18n, GeneralError, Is, StringHelper, ObjectHelper } from '@twin.org/core';
|
|
6
|
-
import { JsonSchemaHelper } from '@twin.org/tools-core';
|
|
6
|
+
import { OpenApiHelper, JsonSchemaHelper } from '@twin.org/tools-core';
|
|
7
7
|
import { HttpStatusCode, MimeTypes } from '@twin.org/web';
|
|
8
8
|
import { createGenerator } from 'ts-json-schema-generator';
|
|
9
9
|
|
|
@@ -193,7 +193,7 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
193
193
|
compilerOptions: {}
|
|
194
194
|
}, undefined, "\t"));
|
|
195
195
|
const openApi = {
|
|
196
|
-
openapi:
|
|
196
|
+
openapi: OpenApiHelper.API_VERSION,
|
|
197
197
|
info: {
|
|
198
198
|
title: config.title,
|
|
199
199
|
description: config.description,
|
|
@@ -238,7 +238,7 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
238
238
|
}
|
|
239
239
|
CLIDisplay.task(I18n.formatMessage("commands.ts-to-openapi.progress.generatingSchemas"));
|
|
240
240
|
const autoExpandTypes = config.autoExpandTypes ?? [];
|
|
241
|
-
const defaultExpandTypes = ["ObjectOrArray
|
|
241
|
+
const defaultExpandTypes = ["/ObjectOrArray<.*>/"];
|
|
242
242
|
for (const defaultType of defaultExpandTypes) {
|
|
243
243
|
if (!autoExpandTypes.includes(defaultType)) {
|
|
244
244
|
autoExpandTypes.push(defaultType);
|
|
@@ -662,7 +662,6 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
|
|
|
662
662
|
if (/I[A-Z]/.test(finalName)) {
|
|
663
663
|
finalName = finalName.slice(1);
|
|
664
664
|
}
|
|
665
|
-
finalName = finalName.replace("<", "_").replace(">", "_");
|
|
666
665
|
if (finalName.endsWith("[]")) {
|
|
667
666
|
finalName = `ListOf${finalName.slice(0, -2)}`;
|
|
668
667
|
}
|
|
@@ -869,7 +868,10 @@ async function generateSchemas(modelDirWildcards, types, autoExpandTypes, output
|
|
|
869
868
|
}
|
|
870
869
|
}
|
|
871
870
|
const referencedSchemas = {};
|
|
872
|
-
JsonSchemaHelper.extractTypes(allSchemas, [
|
|
871
|
+
JsonSchemaHelper.extractTypes(allSchemas, [
|
|
872
|
+
...types,
|
|
873
|
+
...autoExpandTypes.map(t => (t.startsWith("/") && t.endsWith("/") ? new RegExp(t) : t))
|
|
874
|
+
], referencedSchemas);
|
|
873
875
|
JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
|
|
874
876
|
for (const arraySingularType of arraySingularTypes) {
|
|
875
877
|
referencedSchemas[`${arraySingularType}[]`] = {
|
|
@@ -1050,7 +1052,7 @@ class CLI extends CLIBase {
|
|
|
1050
1052
|
return this.execute({
|
|
1051
1053
|
title: "TWIN TypeScript To OpenAPI",
|
|
1052
1054
|
appName: "ts-to-openapi",
|
|
1053
|
-
version: "0.0.2-next.
|
|
1055
|
+
version: "0.0.2-next.3", // x-release-please-version
|
|
1054
1056
|
icon: "⚙️ ",
|
|
1055
1057
|
supportsEnvFiles: false,
|
|
1056
1058
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @twin.org/ts-to-openapi - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.3](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.2...ts-to-openapi-v0.0.2-next.3) (2025-08-05)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* improve type name normalisation ([1fe28e5](https://github.com/twinfoundation/tools/commit/1fe28e567593e46a41a833fbba95fe4cd958f525))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Dependencies
|
|
12
|
+
|
|
13
|
+
* The following workspace dependencies were updated
|
|
14
|
+
* dependencies
|
|
15
|
+
* @twin.org/tools-core bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
16
|
+
|
|
17
|
+
## [0.0.2-next.2](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.1...ts-to-openapi-v0.0.2-next.2) (2025-07-17)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* improve auto expand types ([6181d1d](https://github.com/twinfoundation/tools/commit/6181d1daded1f91323195cf7efbc2f1881f38b41))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Dependencies
|
|
26
|
+
|
|
27
|
+
* The following workspace dependencies were updated
|
|
28
|
+
* dependencies
|
|
29
|
+
* @twin.org/tools-core bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
30
|
+
|
|
3
31
|
## [0.0.2-next.1](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.0...ts-to-openapi-v0.0.2-next.1) (2025-07-14)
|
|
4
32
|
|
|
5
33
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/ts-to-openapi",
|
|
3
|
-
"version": "0.0.2-next.
|
|
3
|
+
"version": "0.0.2-next.3",
|
|
4
4
|
"description": "Tool to convert TypeScript REST route definitions to OpenAPI Specifications",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
"@twin.org/cli-core": "next",
|
|
19
19
|
"@twin.org/core": "next",
|
|
20
20
|
"@twin.org/nameof": "next",
|
|
21
|
-
"@twin.org/tools-core": "0.0.2-next.
|
|
21
|
+
"@twin.org/tools-core": "0.0.2-next.3",
|
|
22
22
|
"@twin.org/web": "next",
|
|
23
23
|
"commander": "14.0.0",
|
|
24
|
-
"glob": "11.0.
|
|
24
|
+
"glob": "11.0.3",
|
|
25
25
|
"ts-json-schema-generator": "2.4.0"
|
|
26
26
|
},
|
|
27
27
|
"main": "./dist/cjs/index.cjs",
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { IJsonSchema } from "@twin.org/tools-core";
|
|
2
|
-
import type { IOpenApiPathMethod } from "./IOpenApiPathMethod";
|
|
3
|
-
import type { IOpenApiSecurityScheme } from "./IOpenApiSecurityScheme";
|
|
4
|
-
/**
|
|
5
|
-
* The Open API config definition.
|
|
6
|
-
*/
|
|
7
|
-
export interface IOpenApi {
|
|
8
|
-
/**
|
|
9
|
-
* The open api version.
|
|
10
|
-
*/
|
|
11
|
-
openapi: string;
|
|
12
|
-
/**
|
|
13
|
-
* Info.
|
|
14
|
-
*/
|
|
15
|
-
info: {
|
|
16
|
-
title: string;
|
|
17
|
-
version: string;
|
|
18
|
-
description: string;
|
|
19
|
-
license?: {
|
|
20
|
-
name: string;
|
|
21
|
-
url: string;
|
|
22
|
-
};
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* The servers for the endpoints.
|
|
26
|
-
*/
|
|
27
|
-
servers?: {
|
|
28
|
-
url: string;
|
|
29
|
-
}[];
|
|
30
|
-
/**
|
|
31
|
-
* Tags for the endpoints.
|
|
32
|
-
*/
|
|
33
|
-
tags?: {
|
|
34
|
-
name: string;
|
|
35
|
-
description: string;
|
|
36
|
-
}[];
|
|
37
|
-
/**
|
|
38
|
-
* The paths.
|
|
39
|
-
*/
|
|
40
|
-
paths: {
|
|
41
|
-
[path: string]: {
|
|
42
|
-
[method: string]: IOpenApiPathMethod;
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* The components.
|
|
47
|
-
*/
|
|
48
|
-
components?: {
|
|
49
|
-
schemas?: IJsonSchema;
|
|
50
|
-
securitySchemes?: {
|
|
51
|
-
[name: string]: IOpenApiSecurityScheme;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Open API config definition.
|
|
3
|
-
*/
|
|
4
|
-
export interface IOpenApiHeader {
|
|
5
|
-
/**
|
|
6
|
-
* The schema of the header.
|
|
7
|
-
*/
|
|
8
|
-
schema?: {
|
|
9
|
-
type: string;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* The description of the header.
|
|
13
|
-
*/
|
|
14
|
-
description?: string;
|
|
15
|
-
/**
|
|
16
|
-
* The format of the header.
|
|
17
|
-
*/
|
|
18
|
-
format?: string;
|
|
19
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { IJsonSchema, JsonTypeName } from "@twin.org/tools-core";
|
|
2
|
-
import type { IOpenApiExample } from "./IOpenApiExample";
|
|
3
|
-
import type { IOpenApiResponse } from "./IOpenApiResponse";
|
|
4
|
-
/**
|
|
5
|
-
* The Open API config definition.
|
|
6
|
-
*/
|
|
7
|
-
export interface IOpenApiPathMethod {
|
|
8
|
-
/**
|
|
9
|
-
* The operation id.
|
|
10
|
-
*/
|
|
11
|
-
operationId: string;
|
|
12
|
-
/**
|
|
13
|
-
* Summary.
|
|
14
|
-
*/
|
|
15
|
-
summary: string;
|
|
16
|
-
/**
|
|
17
|
-
* Tags.
|
|
18
|
-
*/
|
|
19
|
-
tags?: string[];
|
|
20
|
-
/**
|
|
21
|
-
* Parameters.
|
|
22
|
-
*/
|
|
23
|
-
parameters?: {
|
|
24
|
-
name: string;
|
|
25
|
-
in: string;
|
|
26
|
-
description?: string;
|
|
27
|
-
required: boolean;
|
|
28
|
-
schema: {
|
|
29
|
-
type?: JsonTypeName | JsonTypeName[];
|
|
30
|
-
enum?: IJsonSchema[];
|
|
31
|
-
$ref?: string;
|
|
32
|
-
};
|
|
33
|
-
style?: string;
|
|
34
|
-
}[];
|
|
35
|
-
/**
|
|
36
|
-
* Request body.
|
|
37
|
-
*/
|
|
38
|
-
requestBody?: {
|
|
39
|
-
required: boolean;
|
|
40
|
-
description?: string;
|
|
41
|
-
content?: {
|
|
42
|
-
[contentType: string]: {
|
|
43
|
-
schema: {
|
|
44
|
-
$ref: string;
|
|
45
|
-
};
|
|
46
|
-
examples?: {
|
|
47
|
-
[id: string]: IOpenApiExample;
|
|
48
|
-
};
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Response body.
|
|
54
|
-
*/
|
|
55
|
-
responses?: {
|
|
56
|
-
[code: string]: IOpenApiResponse;
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Security model for the API.
|
|
60
|
-
*/
|
|
61
|
-
security?: {
|
|
62
|
-
[name: string]: string[];
|
|
63
|
-
}[];
|
|
64
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { IOpenApiExample } from "./IOpenApiExample";
|
|
2
|
-
import type { IOpenApiHeader } from "./IOpenApiHeader";
|
|
3
|
-
/**
|
|
4
|
-
* The Open API config definition.
|
|
5
|
-
*/
|
|
6
|
-
export interface IOpenApiResponse {
|
|
7
|
-
/**
|
|
8
|
-
* Descriptions for the response.
|
|
9
|
-
*/
|
|
10
|
-
description?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Content for the response.
|
|
13
|
-
*/
|
|
14
|
-
content?: {
|
|
15
|
-
[contentType: string]: {
|
|
16
|
-
schema: {
|
|
17
|
-
type?: string;
|
|
18
|
-
format?: string;
|
|
19
|
-
$ref?: string;
|
|
20
|
-
};
|
|
21
|
-
examples?: {
|
|
22
|
-
[id: string]: IOpenApiExample;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* The headers for the response.
|
|
28
|
-
*/
|
|
29
|
-
headers?: {
|
|
30
|
-
[id: string]: IOpenApiHeader;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The Open API config definition for security scheme.
|
|
3
|
-
*/
|
|
4
|
-
export interface IOpenApiSecurityScheme {
|
|
5
|
-
/**
|
|
6
|
-
* The type of the security schema.
|
|
7
|
-
*/
|
|
8
|
-
type?: string;
|
|
9
|
-
/**
|
|
10
|
-
* The scheme method.
|
|
11
|
-
*/
|
|
12
|
-
scheme?: string;
|
|
13
|
-
/**
|
|
14
|
-
* The bearer format.
|
|
15
|
-
*/
|
|
16
|
-
bearerFormat?: string;
|
|
17
|
-
/**
|
|
18
|
-
* Where is the token located.
|
|
19
|
-
*/
|
|
20
|
-
in?: string;
|
|
21
|
-
/**
|
|
22
|
-
* What is the name of the token.
|
|
23
|
-
*/
|
|
24
|
-
name?: string;
|
|
25
|
-
}
|