@twin.org/ts-to-openapi 0.0.2-next.1 → 0.0.2-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/dist/cjs/index.cjs +7 -4
- package/dist/esm/index.mjs +8 -5
- package/docs/changelog.md +14 -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);
|
|
@@ -872,7 +872,10 @@ async function generateSchemas(modelDirWildcards, types, autoExpandTypes, output
|
|
|
872
872
|
}
|
|
873
873
|
}
|
|
874
874
|
const referencedSchemas = {};
|
|
875
|
-
toolsCore.JsonSchemaHelper.extractTypes(allSchemas, [
|
|
875
|
+
toolsCore.JsonSchemaHelper.extractTypes(allSchemas, [
|
|
876
|
+
...types,
|
|
877
|
+
...autoExpandTypes.map(t => (t.startsWith("/") && t.endsWith("/") ? new RegExp(t) : t))
|
|
878
|
+
], referencedSchemas);
|
|
876
879
|
toolsCore.JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
|
|
877
880
|
for (const arraySingularType of arraySingularTypes) {
|
|
878
881
|
referencedSchemas[`${arraySingularType}[]`] = {
|
|
@@ -1053,7 +1056,7 @@ class CLI extends cliCore.CLIBase {
|
|
|
1053
1056
|
return this.execute({
|
|
1054
1057
|
title: "TWIN TypeScript To OpenAPI",
|
|
1055
1058
|
appName: "ts-to-openapi",
|
|
1056
|
-
version: "0.0.2-next.
|
|
1059
|
+
version: "0.0.2-next.2", // x-release-please-version
|
|
1057
1060
|
icon: "⚙️ ",
|
|
1058
1061
|
supportsEnvFiles: false,
|
|
1059
1062
|
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);
|
|
@@ -869,7 +869,10 @@ async function generateSchemas(modelDirWildcards, types, autoExpandTypes, output
|
|
|
869
869
|
}
|
|
870
870
|
}
|
|
871
871
|
const referencedSchemas = {};
|
|
872
|
-
JsonSchemaHelper.extractTypes(allSchemas, [
|
|
872
|
+
JsonSchemaHelper.extractTypes(allSchemas, [
|
|
873
|
+
...types,
|
|
874
|
+
...autoExpandTypes.map(t => (t.startsWith("/") && t.endsWith("/") ? new RegExp(t) : t))
|
|
875
|
+
], referencedSchemas);
|
|
873
876
|
JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
|
|
874
877
|
for (const arraySingularType of arraySingularTypes) {
|
|
875
878
|
referencedSchemas[`${arraySingularType}[]`] = {
|
|
@@ -1050,7 +1053,7 @@ class CLI extends CLIBase {
|
|
|
1050
1053
|
return this.execute({
|
|
1051
1054
|
title: "TWIN TypeScript To OpenAPI",
|
|
1052
1055
|
appName: "ts-to-openapi",
|
|
1053
|
-
version: "0.0.2-next.
|
|
1056
|
+
version: "0.0.2-next.2", // x-release-please-version
|
|
1054
1057
|
icon: "⚙️ ",
|
|
1055
1058
|
supportsEnvFiles: false,
|
|
1056
1059
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @twin.org/ts-to-openapi - Changelog
|
|
2
2
|
|
|
3
|
+
## [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)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* improve auto expand types ([6181d1d](https://github.com/twinfoundation/tools/commit/6181d1daded1f91323195cf7efbc2f1881f38b41))
|
|
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.1 to 0.0.2-next.2
|
|
16
|
+
|
|
3
17
|
## [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
18
|
|
|
5
19
|
|
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.2",
|
|
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.2",
|
|
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
|
-
}
|