@twin.org/ts-to-openapi 0.0.1 → 0.0.2-next.10
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 +44 -160
- package/dist/esm/index.mjs +45 -161
- package/dist/locales/en.json +20 -32
- package/dist/types/models/ITsToOpenApiConfig.d.ts +11 -0
- package/docs/changelog.md +153 -0
- package/docs/examples.md +1 -1
- package/docs/reference/interfaces/ITsToOpenApiConfig.md +20 -0
- package/locales/.validate-ignore +1 -0
- package/locales/en.json +1 -0
- package/package.json +22 -10
- package/dist/types/models/IJsonSchema.d.ts +0 -5
- 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 -65
- package/dist/types/models/IOpenApiResponse.d.ts +0 -32
- package/dist/types/models/IOpenApiSecurityScheme.d.ts +0 -25
- package/dist/types/models/IPackageJson.d.ts +0 -15
- package/dist/types/models/jsonTypeName.d.ts +0 -5
package/dist/esm/index.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import path from 'node:path';
|
|
|
2
2
|
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
|
-
import { I18n, GeneralError, Is, StringHelper, ObjectHelper
|
|
5
|
+
import { I18n, GeneralError, Is, StringHelper, ObjectHelper } from '@twin.org/core';
|
|
6
|
+
import { OpenApiHelper, JsonSchemaHelper } from '@twin.org/tools-core';
|
|
6
7
|
import { HttpStatusCode, MimeTypes } from '@twin.org/web';
|
|
7
8
|
import { createGenerator } from 'ts-json-schema-generator';
|
|
8
9
|
|
|
@@ -28,7 +29,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
28
29
|
responseType: "IBadRequestResponse",
|
|
29
30
|
example: {
|
|
30
31
|
name: "GeneralError",
|
|
31
|
-
message: "
|
|
32
|
+
message: "errorMessage",
|
|
32
33
|
properties: {
|
|
33
34
|
foo: "bar"
|
|
34
35
|
}
|
|
@@ -39,7 +40,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
39
40
|
responseType: "IUnauthorizedResponse",
|
|
40
41
|
example: {
|
|
41
42
|
name: "UnauthorizedError",
|
|
42
|
-
message: "
|
|
43
|
+
message: "errorMessage"
|
|
43
44
|
}
|
|
44
45
|
},
|
|
45
46
|
forbidden: {
|
|
@@ -47,7 +48,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
47
48
|
responseType: "IForbiddenResponse",
|
|
48
49
|
example: {
|
|
49
50
|
name: "NotImplementedError",
|
|
50
|
-
message: "
|
|
51
|
+
message: "errorMessage",
|
|
51
52
|
properties: {
|
|
52
53
|
method: "aMethod"
|
|
53
54
|
}
|
|
@@ -58,7 +59,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
58
59
|
responseType: "INotFoundResponse",
|
|
59
60
|
example: {
|
|
60
61
|
name: "NotFoundError",
|
|
61
|
-
message: "
|
|
62
|
+
message: "errorMessage",
|
|
62
63
|
properties: {
|
|
63
64
|
notFoundId: "1"
|
|
64
65
|
}
|
|
@@ -69,7 +70,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
69
70
|
responseType: "IConflictResponse",
|
|
70
71
|
example: {
|
|
71
72
|
name: "ConflictError",
|
|
72
|
-
message: "
|
|
73
|
+
message: "errorMessage",
|
|
73
74
|
properties: {
|
|
74
75
|
conflicts: ["1"]
|
|
75
76
|
}
|
|
@@ -80,7 +81,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
80
81
|
responseType: "IInternalServerErrorResponse",
|
|
81
82
|
example: {
|
|
82
83
|
name: "InternalServerError",
|
|
83
|
-
message: "
|
|
84
|
+
message: "errorMessage"
|
|
84
85
|
}
|
|
85
86
|
},
|
|
86
87
|
unprocessableEntity: {
|
|
@@ -88,7 +89,7 @@ const HTTP_STATUS_CODE_MAP = {
|
|
|
88
89
|
responseType: "IUnprocessableEntityResponse",
|
|
89
90
|
example: {
|
|
90
91
|
name: "UnprocessableError",
|
|
91
|
-
message: "
|
|
92
|
+
message: "errorMessage"
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
};
|
|
@@ -192,7 +193,7 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
192
193
|
compilerOptions: {}
|
|
193
194
|
}, undefined, "\t"));
|
|
194
195
|
const openApi = {
|
|
195
|
-
openapi:
|
|
196
|
+
openapi: OpenApiHelper.API_VERSION,
|
|
196
197
|
info: {
|
|
197
198
|
title: config.title,
|
|
198
199
|
description: config.description,
|
|
@@ -236,7 +237,20 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
236
237
|
}
|
|
237
238
|
}
|
|
238
239
|
CLIDisplay.task(I18n.formatMessage("commands.ts-to-openapi.progress.generatingSchemas"));
|
|
239
|
-
const
|
|
240
|
+
const autoExpandTypes = config.autoExpandTypes ?? [];
|
|
241
|
+
const defaultExpandTypes = ["/ObjectOrArray<.*>/"];
|
|
242
|
+
for (const defaultType of defaultExpandTypes) {
|
|
243
|
+
if (!autoExpandTypes.includes(defaultType)) {
|
|
244
|
+
autoExpandTypes.push(defaultType);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const schemas = await generateSchemas(typeRoots, types, autoExpandTypes, workingDirectory);
|
|
248
|
+
for (const type in schemas) {
|
|
249
|
+
if (Is.object(config.overrides?.[type])) {
|
|
250
|
+
CLIDisplay.task(I18n.formatMessage("commands.ts-to-openapi.progress.overridingSchema"));
|
|
251
|
+
schemas[type] = config.overrides?.[type];
|
|
252
|
+
}
|
|
253
|
+
}
|
|
240
254
|
const usedCommonResponseTypes = [];
|
|
241
255
|
for (let i = 0; i < inputResults.length; i++) {
|
|
242
256
|
const result = inputResults[i];
|
|
@@ -421,12 +435,13 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
421
435
|
if (requestObject?.properties) {
|
|
422
436
|
// If there are any properties other than body, query, pathParams and headers
|
|
423
437
|
// we should throw an error as we don't know what to do with them
|
|
424
|
-
const otherKeys = Object.keys(requestObject.properties).filter(k => !["body", "query", "pathParams", "headers"].includes(k));
|
|
438
|
+
const otherKeys = Object.keys(requestObject.properties).filter(k => !["body", "query", "pathParams", "headers", "authentication"].includes(k));
|
|
425
439
|
if (otherKeys.length > 0) {
|
|
426
440
|
throw new GeneralError("commands", "commands.ts-to-openapi.unsupportedProperties", {
|
|
427
441
|
keys: otherKeys.join(", ")
|
|
428
442
|
});
|
|
429
443
|
}
|
|
444
|
+
delete requestObject.properties.authentication;
|
|
430
445
|
// If there is a path params object convert these to params
|
|
431
446
|
if (Is.object(requestObject.properties.pathParams)) {
|
|
432
447
|
for (const pathParam of pathQueryHeaderParams) {
|
|
@@ -583,7 +598,7 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
583
598
|
}
|
|
584
599
|
}
|
|
585
600
|
}
|
|
586
|
-
await finaliseOutput(usedCommonResponseTypes, schemas, openApi, securitySchemes, config.externalReferences, outputFile);
|
|
601
|
+
await finaliseOutput(usedCommonResponseTypes, schemas, openApi, securitySchemes, config.externalReferences, autoExpandTypes, outputFile);
|
|
587
602
|
}
|
|
588
603
|
/**
|
|
589
604
|
* Finalise the schemas and output the spec.
|
|
@@ -592,9 +607,10 @@ async function tsToOpenApi(config, outputFile, workingDirectory) {
|
|
|
592
607
|
* @param openApi The OpenAPI spec.
|
|
593
608
|
* @param securitySchemes The security schemes.
|
|
594
609
|
* @param externalReferences The external references.
|
|
610
|
+
* @param autoExpandTypes The auto expand types.
|
|
595
611
|
* @param outputFile The output file.
|
|
596
612
|
*/
|
|
597
|
-
async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securitySchemes, externalReferences, outputFile) {
|
|
613
|
+
async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securitySchemes, externalReferences, autoExpandTypes, outputFile) {
|
|
598
614
|
CLIDisplay.break();
|
|
599
615
|
CLIDisplay.task(I18n.formatMessage("commands.ts-to-openapi.progress.finalisingSchemas"));
|
|
600
616
|
// Remove the response codes that we haven't used
|
|
@@ -635,6 +651,15 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
|
|
|
635
651
|
}
|
|
636
652
|
}
|
|
637
653
|
}
|
|
654
|
+
// We can remove any auto expand types from the final schema as they
|
|
655
|
+
// will have been expanded inline so no need to keep them
|
|
656
|
+
for (const autoExpandType of autoExpandTypes) {
|
|
657
|
+
const regExp = JsonSchemaHelper.stringToRegEx(autoExpandType);
|
|
658
|
+
if (regExp.test(schema)) {
|
|
659
|
+
skipSchema = true;
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
638
663
|
if (!skipSchema) {
|
|
639
664
|
// If the final schema has no properties and is just a ref to another object type
|
|
640
665
|
// then replace the references with that of the referenced type
|
|
@@ -648,7 +673,6 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
|
|
|
648
673
|
if (/I[A-Z]/.test(finalName)) {
|
|
649
674
|
finalName = finalName.slice(1);
|
|
650
675
|
}
|
|
651
|
-
finalName = finalName.replace("<", "_").replace(">", "_");
|
|
652
676
|
if (finalName.endsWith("[]")) {
|
|
653
677
|
finalName = `ListOf${finalName.slice(0, -2)}`;
|
|
654
678
|
}
|
|
@@ -662,7 +686,7 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
|
|
|
662
686
|
delete finalSchemas[type];
|
|
663
687
|
}
|
|
664
688
|
for (const type in finalSchemas) {
|
|
665
|
-
processArrays(finalSchemas[type]);
|
|
689
|
+
JsonSchemaHelper.processArrays(finalSchemas[type]);
|
|
666
690
|
}
|
|
667
691
|
const schemaKeys = Object.keys(finalSchemas);
|
|
668
692
|
schemaKeys.sort();
|
|
@@ -695,7 +719,7 @@ async function finaliseOutput(usedCommonResponseTypes, schemas, openApi, securit
|
|
|
695
719
|
// Remove the array [] from the type names
|
|
696
720
|
// eslint-disable-next-line unicorn/better-regex
|
|
697
721
|
json = json.replace(/#\/components\/schemas\/(.*)\[\]/g, "#/components/schemas/ListOf$1");
|
|
698
|
-
json = normaliseTypeName(json);
|
|
722
|
+
json = JsonSchemaHelper.normaliseTypeName(json);
|
|
699
723
|
// Remove external references
|
|
700
724
|
for (const finalExternal in finalExternals) {
|
|
701
725
|
json = json.replace(new RegExp(`"#/components/schemas/${StringHelper.stripPrefix(finalExternal)}"`, "g"), `"${finalExternals[finalExternal]}"`);
|
|
@@ -825,7 +849,7 @@ async function processPackageRestDetails(restRoutes) {
|
|
|
825
849
|
* @returns Nothing.
|
|
826
850
|
* @internal
|
|
827
851
|
*/
|
|
828
|
-
async function generateSchemas(modelDirWildcards, types, outputWorkingDir) {
|
|
852
|
+
async function generateSchemas(modelDirWildcards, types, autoExpandTypes, outputWorkingDir) {
|
|
829
853
|
const allSchemas = {};
|
|
830
854
|
const arraySingularTypes = [];
|
|
831
855
|
for (const type of types) {
|
|
@@ -849,13 +873,14 @@ async function generateSchemas(modelDirWildcards, types, outputWorkingDir) {
|
|
|
849
873
|
const schema = generator.createSchema("*");
|
|
850
874
|
if (schema.definitions) {
|
|
851
875
|
for (const def in schema.definitions) {
|
|
852
|
-
const defSub = normaliseTypeName(def);
|
|
876
|
+
const defSub = JsonSchemaHelper.normaliseTypeName(def);
|
|
853
877
|
allSchemas[defSub] = schema.definitions[def];
|
|
854
878
|
}
|
|
855
879
|
}
|
|
856
880
|
}
|
|
857
881
|
const referencedSchemas = {};
|
|
858
|
-
extractTypes(allSchemas, types, referencedSchemas);
|
|
882
|
+
JsonSchemaHelper.extractTypes(allSchemas, [...types, ...autoExpandTypes], referencedSchemas);
|
|
883
|
+
JsonSchemaHelper.expandTypes(referencedSchemas, autoExpandTypes);
|
|
859
884
|
for (const arraySingularType of arraySingularTypes) {
|
|
860
885
|
referencedSchemas[`${arraySingularType}[]`] = {
|
|
861
886
|
type: "array",
|
|
@@ -866,74 +891,6 @@ async function generateSchemas(modelDirWildcards, types, outputWorkingDir) {
|
|
|
866
891
|
}
|
|
867
892
|
return referencedSchemas;
|
|
868
893
|
}
|
|
869
|
-
/**
|
|
870
|
-
* Extract the required types from all the known schemas.
|
|
871
|
-
* @param allSchemas All the known schemas.
|
|
872
|
-
* @param requiredTypes The required types.
|
|
873
|
-
* @param referencedSchemas The references schemas.
|
|
874
|
-
* @internal
|
|
875
|
-
*/
|
|
876
|
-
function extractTypes(allSchemas, requiredTypes, referencedSchemas) {
|
|
877
|
-
for (const type of requiredTypes) {
|
|
878
|
-
if (allSchemas[type] && !referencedSchemas[type]) {
|
|
879
|
-
referencedSchemas[type] = allSchemas[type];
|
|
880
|
-
extractTypesFromSchema(allSchemas, allSchemas[type], referencedSchemas);
|
|
881
|
-
}
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
/**
|
|
885
|
-
* Extract type from properties definition.
|
|
886
|
-
* @param allTypes All the known types.
|
|
887
|
-
* @param schema The schema to extract from.
|
|
888
|
-
* @param output The output types.
|
|
889
|
-
* @internal
|
|
890
|
-
*/
|
|
891
|
-
function extractTypesFromSchema(allTypes, schema, output) {
|
|
892
|
-
const additionalTypes = [];
|
|
893
|
-
if (Is.stringValue(schema.$ref)) {
|
|
894
|
-
additionalTypes.push(normaliseTypeName(schema.$ref).replace("#/definitions/", ""));
|
|
895
|
-
}
|
|
896
|
-
else if (Is.object(schema.items)) {
|
|
897
|
-
if (Is.arrayValue(schema.items)) {
|
|
898
|
-
for (const itemSchema of schema.items) {
|
|
899
|
-
extractTypesFromSchema(allTypes, itemSchema, output);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
else {
|
|
903
|
-
extractTypesFromSchema(allTypes, schema.items, output);
|
|
904
|
-
}
|
|
905
|
-
}
|
|
906
|
-
else if (Is.object(schema.properties) || Is.object(schema.additionalProperties)) {
|
|
907
|
-
if (Is.object(schema.properties)) {
|
|
908
|
-
for (const prop in schema.properties) {
|
|
909
|
-
const p = schema.properties[prop];
|
|
910
|
-
if (Is.object(p)) {
|
|
911
|
-
extractTypesFromSchema(allTypes, p, output);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
}
|
|
915
|
-
if (Is.object(schema.additionalProperties)) {
|
|
916
|
-
extractTypesFromSchema(allTypes, schema.additionalProperties, output);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
else if (Is.arrayValue(schema.anyOf)) {
|
|
920
|
-
for (const prop of schema.anyOf) {
|
|
921
|
-
if (Is.object(prop)) {
|
|
922
|
-
extractTypesFromSchema(allTypes, prop, output);
|
|
923
|
-
}
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
else if (Is.arrayValue(schema.oneOf)) {
|
|
927
|
-
for (const prop of schema.oneOf) {
|
|
928
|
-
if (Is.object(prop)) {
|
|
929
|
-
extractTypesFromSchema(allTypes, prop, output);
|
|
930
|
-
}
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
if (additionalTypes.length > 0) {
|
|
934
|
-
extractTypes(allTypes, additionalTypes, output);
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
894
|
/**
|
|
938
895
|
* Tidy up the schemas for use in OpenAPI context.
|
|
939
896
|
* @param props The properties to tidy up.
|
|
@@ -1084,79 +1041,6 @@ async function loadPackages(tsToOpenApiConfig, outputWorkingDir, typeRoots) {
|
|
|
1084
1041
|
}
|
|
1085
1042
|
return restRoutes;
|
|
1086
1043
|
}
|
|
1087
|
-
/**
|
|
1088
|
-
* Process arrays in the schema object.
|
|
1089
|
-
* @param schemaObject The schema object to process.
|
|
1090
|
-
*/
|
|
1091
|
-
function processArrays(schemaObject) {
|
|
1092
|
-
if (Is.object(schemaObject)) {
|
|
1093
|
-
// latest specs have singular items in `items` property
|
|
1094
|
-
// and multiple items in prefixItems, so update the schema accordingly
|
|
1095
|
-
// https://www.learnjsonschema.com/2020-12/applicator/items/
|
|
1096
|
-
// https://www.learnjsonschema.com/2020-12/applicator/prefixitems/
|
|
1097
|
-
const schemaItems = schemaObject.items;
|
|
1098
|
-
if (Is.array(schemaItems) || Is.object(schemaItems)) {
|
|
1099
|
-
schemaObject.prefixItems = ArrayHelper.fromObjectOrArray(schemaItems);
|
|
1100
|
-
delete schemaObject.items;
|
|
1101
|
-
}
|
|
1102
|
-
const additionalItems = schemaObject.additionalItems;
|
|
1103
|
-
if (Is.array(additionalItems) || Is.object(additionalItems)) {
|
|
1104
|
-
schemaObject.items = ArrayHelper.fromObjectOrArray(additionalItems)[0];
|
|
1105
|
-
delete schemaObject.additionalItems;
|
|
1106
|
-
}
|
|
1107
|
-
processSchemaDictionary(schemaObject.properties);
|
|
1108
|
-
processArrays(schemaObject.additionalProperties);
|
|
1109
|
-
processSchemaArray(schemaObject.allOf);
|
|
1110
|
-
processSchemaArray(schemaObject.anyOf);
|
|
1111
|
-
processSchemaArray(schemaObject.oneOf);
|
|
1112
|
-
}
|
|
1113
|
-
}
|
|
1114
|
-
/**
|
|
1115
|
-
* Process arrays in the schema object.
|
|
1116
|
-
* @param schemaDictionary The schema object to process.
|
|
1117
|
-
*/
|
|
1118
|
-
function processSchemaDictionary(schemaDictionary) {
|
|
1119
|
-
if (Is.object(schemaDictionary)) {
|
|
1120
|
-
for (const item of Object.values(schemaDictionary)) {
|
|
1121
|
-
if (Is.object(item)) {
|
|
1122
|
-
processArrays(item);
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
/**
|
|
1128
|
-
* Process arrays in the schema object.
|
|
1129
|
-
* @param schemaArray The schema object to process.
|
|
1130
|
-
*/
|
|
1131
|
-
function processSchemaArray(schemaArray) {
|
|
1132
|
-
if (Is.arrayValue(schemaArray)) {
|
|
1133
|
-
for (const item of schemaArray) {
|
|
1134
|
-
if (Is.object(item)) {
|
|
1135
|
-
processArrays(item);
|
|
1136
|
-
}
|
|
1137
|
-
}
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
/**
|
|
1141
|
-
* Cleanup TypeScript markers from the type name.
|
|
1142
|
-
* @param typeName The definition string to clean up.
|
|
1143
|
-
* @returns The cleaned up definition string.
|
|
1144
|
-
*/
|
|
1145
|
-
function normaliseTypeName(typeName) {
|
|
1146
|
-
// Remove the partial markers
|
|
1147
|
-
let sTypeName = typeName.replace(/^Partial<(.*?)>/g, "$1");
|
|
1148
|
-
sTypeName = sTypeName.replace(/Partial%3CI(.*?)%3E/g, "$1");
|
|
1149
|
-
// Remove the omit markers
|
|
1150
|
-
sTypeName = sTypeName.replace(/^Omit<(.*?),.*>/g, "$1");
|
|
1151
|
-
sTypeName = sTypeName.replace(/Omit%3CI(.*?)%2C.*%3E/g, "$1");
|
|
1152
|
-
// Remove the pick markers
|
|
1153
|
-
sTypeName = sTypeName.replace(/^Pick<(.*?),.*>/g, "$1");
|
|
1154
|
-
sTypeName = sTypeName.replace(/Pick%3CI(.*?)%2C.*%3E/g, "$1");
|
|
1155
|
-
// Cleanup the generic markers
|
|
1156
|
-
sTypeName = sTypeName.replace(/</g, "%3C").replace(/>/g, "%3E");
|
|
1157
|
-
sTypeName = sTypeName.replace(/%3Cunknown%3E/g, "");
|
|
1158
|
-
return sTypeName;
|
|
1159
|
-
}
|
|
1160
1044
|
|
|
1161
1045
|
// Copyright 2024 IOTA Stiftung.
|
|
1162
1046
|
// SPDX-License-Identifier: Apache-2.0.
|
|
@@ -1176,7 +1060,7 @@ class CLI extends CLIBase {
|
|
|
1176
1060
|
return this.execute({
|
|
1177
1061
|
title: "TWIN TypeScript To OpenAPI",
|
|
1178
1062
|
appName: "ts-to-openapi",
|
|
1179
|
-
version: "0.0.
|
|
1063
|
+
version: "0.0.2-next.10", // x-release-please-version
|
|
1180
1064
|
icon: "⚙️ ",
|
|
1181
1065
|
supportsEnvFiles: false,
|
|
1182
1066
|
overrideOutputWidth: options?.overrideOutputWidth
|
package/dist/locales/en.json
CHANGED
|
@@ -44,8 +44,13 @@
|
|
|
44
44
|
"beUrl": "{fieldName} must be a correctly formatted url",
|
|
45
45
|
"beJSON": "{fieldName} must be correctly formatted JSON",
|
|
46
46
|
"beEmail": "{fieldName} must be a correctly formatted e-mail address",
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"minLengthRequired": "The value length should be at least {minLength}, it is {actualLength}",
|
|
48
|
+
"maxLengthRequired": "The value length should be at most {maxLength}, it is {actualLength}",
|
|
49
|
+
"repeatedCharacters": "The value should not contain repeated characters in sequence",
|
|
50
|
+
"atLeastOneLowerCase": "The value should contain at least one lowercase character",
|
|
51
|
+
"atLeastOneUpperCase": "The value should contain at least one uppercase character",
|
|
52
|
+
"atLeastOneNumber": "The value should contain at least one number",
|
|
53
|
+
"atLeastOneSpecialChar": "The value should contain at least one symbol"
|
|
49
54
|
},
|
|
50
55
|
"guard": {
|
|
51
56
|
"undefined": "Property \"{property}\" must be defined, it is \"{value}\"",
|
|
@@ -78,9 +83,7 @@
|
|
|
78
83
|
"url": "Property \"{property}\" must be a Url formatted string, it is \"{value}\"",
|
|
79
84
|
"email": "Property \"{property}\" must be string in e-mail format, it is \"{value}\"",
|
|
80
85
|
"length32Multiple": "Property \"{property}\" should be a multiple of 32, it is {value}",
|
|
81
|
-
"lengthEntropy": "Property \"{property}\" should be a multiple of 4, >=16 and <= 32, it is {value}"
|
|
82
|
-
"length3Multiple": "Property \"{property}\" should be a multiple of 3, it is {value}",
|
|
83
|
-
"greaterThan0": "Property \"{property}\" must be greater than zero, it is {value}"
|
|
86
|
+
"lengthEntropy": "Property \"{property}\" should be a multiple of 4, >=16 and <= 32, it is {value}"
|
|
84
87
|
},
|
|
85
88
|
"objectHelper": {
|
|
86
89
|
"failedBytesToJSON": "Failed converting bytes to JSON",
|
|
@@ -96,7 +99,7 @@
|
|
|
96
99
|
"noGet": "The requested {typeName} \"{name}\" does not exist in the factory"
|
|
97
100
|
},
|
|
98
101
|
"bitString": {
|
|
99
|
-
"outOfRange": "The index should be >= 0 and less than the length of the bit string"
|
|
102
|
+
"outOfRange": "The index should be >= 0 and less than the length of the bit string, the index is \"{index}\" and the number of bit is \"{numberBits}\""
|
|
100
103
|
},
|
|
101
104
|
"base32": {
|
|
102
105
|
"invalidCharacter": "Data contains a character \"{invalidCharacter}\" which is not in the charset"
|
|
@@ -111,11 +114,12 @@
|
|
|
111
114
|
"failedPatch": "Failed to patch the JSON object, patch index \"{index}\" failed"
|
|
112
115
|
},
|
|
113
116
|
"fetchHelper": {
|
|
114
|
-
"decodingJSON": "Decoding JSON failed for route \"{
|
|
117
|
+
"decodingJSON": "Decoding JSON failed for route \"{url}\"",
|
|
115
118
|
"failureStatusText": "The request to the API failed: \"{statusText}\"",
|
|
116
119
|
"connectivity": "The request failed, the API could be offline, or there are other connectivity issues",
|
|
117
120
|
"timeout": "The request timed out",
|
|
118
|
-
"general": "A general failure occurred during the request"
|
|
121
|
+
"general": "A general failure occurred during the request",
|
|
122
|
+
"retryLimitExceeded": "The retry limit was exceeded for route \"{url}\""
|
|
119
123
|
},
|
|
120
124
|
"jwt": {
|
|
121
125
|
"noKeyOrSigner": "No key or signer was provided for JWT creation",
|
|
@@ -131,10 +135,6 @@
|
|
|
131
135
|
"createFailed": "Failed to create JWS",
|
|
132
136
|
"verifyFailed": "Failed to verify JWS"
|
|
133
137
|
},
|
|
134
|
-
"bip39": {
|
|
135
|
-
"missingMnemonicWord": "The mnemonic contains a word not in the wordlist, \"{value}\"",
|
|
136
|
-
"checksumMismatch": "The checksum does not match \"{newChecksum}\" != \"{checksumBits}\""
|
|
137
|
-
},
|
|
138
138
|
"ed25519": {
|
|
139
139
|
"privateKeyLength": "The private key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\"",
|
|
140
140
|
"publicKeyLength": "The public key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\""
|
|
@@ -143,13 +143,6 @@
|
|
|
143
143
|
"privateKeyLength": "The private key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\"",
|
|
144
144
|
"publicKeyLength": "The public key length is incorrect, it should be \"{requiredSize}\" but is \"{actualSize}\""
|
|
145
145
|
},
|
|
146
|
-
"x25519": {
|
|
147
|
-
"invalidPublicKey": "Invalid Ed25519 Public Key"
|
|
148
|
-
},
|
|
149
|
-
"blake2b": {
|
|
150
|
-
"outputLength64": "The output length should be between 1 and 64, it is \"{outputLength}\"",
|
|
151
|
-
"keyLength64": "The key length should be between 1 and 64, it is \"{keyLength}\""
|
|
152
|
-
},
|
|
153
146
|
"sha512": {
|
|
154
147
|
"bitSize": "Only 224, 256, 384 or 512 bits are supported, it is \"{bitSize}\""
|
|
155
148
|
},
|
|
@@ -172,17 +165,6 @@
|
|
|
172
165
|
"lowerUpper": "The address my use either lowercase or uppercase, \"{bech32}\"",
|
|
173
166
|
"dataTooShort": "The address does not contain enough data to decode, \"{bech32}\""
|
|
174
167
|
},
|
|
175
|
-
"pbkdf2": {
|
|
176
|
-
"keyTooLong": "The requested key length \"{keyLength}\" is too long, based on the \"{macLength}\""
|
|
177
|
-
},
|
|
178
|
-
"chaCha20Poly1305": {
|
|
179
|
-
"noAadWithData": "You can not set the aad when there is already data",
|
|
180
|
-
"noAuthTag": "Can not finalise when the auth tag is not set",
|
|
181
|
-
"authenticationFailed": "The data could not be authenticated",
|
|
182
|
-
"authTagDecrypting": "Can not get the auth tag when decrypting",
|
|
183
|
-
"authTagEncrypting": "Can not set the auth tag when encrypting",
|
|
184
|
-
"noAuthTagSet": "The auth tag has not been set"
|
|
185
|
-
},
|
|
186
168
|
"bip44": {
|
|
187
169
|
"unsupportedKeyType": "The key type \"{keyType}\" is not supported"
|
|
188
170
|
},
|
|
@@ -195,7 +177,6 @@
|
|
|
195
177
|
"optionInvalidHex": "The \"{option}\" does not appear to be hex. \"{value}\"",
|
|
196
178
|
"optionInvalidBase64": "The \"{option}\" does not appear to be base64. \"{value}\"",
|
|
197
179
|
"optionInvalidHexBase64": "The \"{option}\" does not appear to be hex or base64. \"{value}\"",
|
|
198
|
-
"optionInvalidBech32": "The \"{option}\" does not appear to be bech32. \"{value}\"",
|
|
199
180
|
"optionMinValue": "The \"{option}\" option must be greater than or equal to {minValue}, it is {value}.",
|
|
200
181
|
"optionMaxValue": "The \"{option}\" option must be less than or equal to {maxValue}, it is {value}."
|
|
201
182
|
},
|
|
@@ -217,7 +198,8 @@
|
|
|
217
198
|
"alreadyExistsError": "Already Exists",
|
|
218
199
|
"notImplementedError": "Not Implemented",
|
|
219
200
|
"validationError": "Validation",
|
|
220
|
-
"unprocessableError": "Unprocessable"
|
|
201
|
+
"unprocessableError": "Unprocessable",
|
|
202
|
+
"unauthorizedError": "Unauthorized"
|
|
221
203
|
},
|
|
222
204
|
"validation": {
|
|
223
205
|
"defaultFieldName": "The field"
|
|
@@ -225,6 +207,11 @@
|
|
|
225
207
|
"errorMessages": {
|
|
226
208
|
"fetch": "Fetch"
|
|
227
209
|
},
|
|
210
|
+
"warn": {
|
|
211
|
+
"common": {
|
|
212
|
+
"devOnlyTool": "This tool is intended to be used for development purposes, it is not recommended for use in production scenarios."
|
|
213
|
+
}
|
|
214
|
+
},
|
|
228
215
|
"cli": {
|
|
229
216
|
"progress": {
|
|
230
217
|
"done": "Done.",
|
|
@@ -284,6 +271,7 @@
|
|
|
284
271
|
"creatingWorkingDir": "Creating Working Directory",
|
|
285
272
|
"creatingSecuritySchemas": "Creating Security Schemas",
|
|
286
273
|
"generatingSchemas": "Generating Schemas",
|
|
274
|
+
"overridingSchema": "Overriding Schema",
|
|
287
275
|
"finalisingSchemas": "Finalising Schemas",
|
|
288
276
|
"writingOutputFile": "Writing Output File",
|
|
289
277
|
"models": "Models",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IJsonSchema } from "@twin.org/tools-core";
|
|
1
2
|
import type { ITsToOpenApiConfigEntryPoint } from "./ITsToOpenApiConfigEntryPoint";
|
|
2
3
|
/**
|
|
3
4
|
* Configuration for the API.
|
|
@@ -58,4 +59,14 @@ export interface ITsToOpenApiConfig {
|
|
|
58
59
|
externalReferences?: {
|
|
59
60
|
[id: string]: string;
|
|
60
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Override for specific types, to be used when the type cannot be generated automatically, or is generated incorrectly.
|
|
64
|
+
*/
|
|
65
|
+
overrides?: {
|
|
66
|
+
[id: string]: IJsonSchema;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The types to automatically expand inline in type definitions, reg ex string matches.
|
|
70
|
+
*/
|
|
71
|
+
autoExpandTypes?: string[];
|
|
61
72
|
}
|
package/docs/changelog.md
CHANGED
|
@@ -1,5 +1,158 @@
|
|
|
1
1
|
# @twin.org/ts-to-openapi - Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.2-next.10](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.9...ts-to-openapi-v0.0.2-next.10) (2025-10-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* add validate-locales ([97bb11f](https://github.com/twinfoundation/tools/commit/97bb11fd9e6ed400e7fa69671075ba78f36ca6e6))
|
|
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.9 to 0.0.2-next.10
|
|
16
|
+
|
|
17
|
+
## [0.0.2-next.9](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.8...ts-to-openapi-v0.0.2-next.9) (2025-09-23)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* add support for authentication property ([ba002c2](https://github.com/twinfoundation/tools/commit/ba002c2c641618ffe7664269179bca6e9fbc9655))
|
|
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.8 to 0.0.2-next.9
|
|
30
|
+
|
|
31
|
+
## [0.0.2-next.8](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.7...ts-to-openapi-v0.0.2-next.8) (2025-09-05)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
### Features
|
|
35
|
+
|
|
36
|
+
* tighten the types included with the regex matching ([e54909b](https://github.com/twinfoundation/tools/commit/e54909bded4a19d00560dd3ec783e9146580bda3))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Dependencies
|
|
40
|
+
|
|
41
|
+
* The following workspace dependencies were updated
|
|
42
|
+
* dependencies
|
|
43
|
+
* @twin.org/tools-core bumped from 0.0.2-next.7 to 0.0.2-next.8
|
|
44
|
+
|
|
45
|
+
## [0.0.2-next.7](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.6...ts-to-openapi-v0.0.2-next.7) (2025-08-29)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* eslint migration to flat config ([25acfcf](https://github.com/twinfoundation/tools/commit/25acfcf4c4e0c496fffeaf67659fe171bc15199a))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Dependencies
|
|
54
|
+
|
|
55
|
+
* The following workspace dependencies were updated
|
|
56
|
+
* dependencies
|
|
57
|
+
* @twin.org/tools-core bumped from 0.0.2-next.6 to 0.0.2-next.7
|
|
58
|
+
|
|
59
|
+
## [0.0.2-next.6](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.5...ts-to-openapi-v0.0.2-next.6) (2025-08-21)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### Features
|
|
63
|
+
|
|
64
|
+
* remove auto expanded types from final output ([18e05dc](https://github.com/twinfoundation/tools/commit/18e05dc88f71a0a27b79d1d076b1261b42d2c4c2))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Dependencies
|
|
68
|
+
|
|
69
|
+
* The following workspace dependencies were updated
|
|
70
|
+
* dependencies
|
|
71
|
+
* @twin.org/tools-core bumped from 0.0.2-next.5 to 0.0.2-next.6
|
|
72
|
+
|
|
73
|
+
## [0.0.2-next.5](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.4...ts-to-openapi-v0.0.2-next.5) (2025-08-19)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
### Features
|
|
77
|
+
|
|
78
|
+
* correctly handle auto expand types ([57fce0f](https://github.com/twinfoundation/tools/commit/57fce0f9ec4a0876665d70adc6e885f6feb3caf7))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Dependencies
|
|
82
|
+
|
|
83
|
+
* The following workspace dependencies were updated
|
|
84
|
+
* dependencies
|
|
85
|
+
* @twin.org/tools-core bumped from 0.0.2-next.4 to 0.0.2-next.5
|
|
86
|
+
|
|
87
|
+
## [0.0.2-next.4](https://github.com/twinfoundation/tools/compare/ts-to-openapi-v0.0.2-next.3...ts-to-openapi-v0.0.2-next.4) (2025-08-19)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
### Miscellaneous Chores
|
|
91
|
+
|
|
92
|
+
* **ts-to-openapi:** Synchronize repo versions
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
### Dependencies
|
|
96
|
+
|
|
97
|
+
* The following workspace dependencies were updated
|
|
98
|
+
* dependencies
|
|
99
|
+
* @twin.org/tools-core bumped from 0.0.2-next.3 to 0.0.2-next.4
|
|
100
|
+
|
|
101
|
+
## [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)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
### Features
|
|
105
|
+
|
|
106
|
+
* improve type name normalisation ([1fe28e5](https://github.com/twinfoundation/tools/commit/1fe28e567593e46a41a833fbba95fe4cd958f525))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
### Dependencies
|
|
110
|
+
|
|
111
|
+
* The following workspace dependencies were updated
|
|
112
|
+
* dependencies
|
|
113
|
+
* @twin.org/tools-core bumped from 0.0.2-next.2 to 0.0.2-next.3
|
|
114
|
+
|
|
115
|
+
## [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)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### Features
|
|
119
|
+
|
|
120
|
+
* improve auto expand types ([6181d1d](https://github.com/twinfoundation/tools/commit/6181d1daded1f91323195cf7efbc2f1881f38b41))
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
### Dependencies
|
|
124
|
+
|
|
125
|
+
* The following workspace dependencies were updated
|
|
126
|
+
* dependencies
|
|
127
|
+
* @twin.org/tools-core bumped from 0.0.2-next.1 to 0.0.2-next.2
|
|
128
|
+
|
|
129
|
+
## [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)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
### Features
|
|
133
|
+
|
|
134
|
+
* add latest json schema features ([494293f](https://github.com/twinfoundation/tools/commit/494293f4252b9c7d4a20790ec157fc9d8c96c3d2))
|
|
135
|
+
* add support for auto expand types ([dd1e10a](https://github.com/twinfoundation/tools/commit/dd1e10a5b2fea6f80890ff6f3971f48e239cb4c1))
|
|
136
|
+
* add ts-to-schema overrides ([3c54504](https://github.com/twinfoundation/tools/commit/3c5450468eb998204a75576b7791a7ca4027da62))
|
|
137
|
+
* generate schemas as individual entities ([9f372ab](https://github.com/twinfoundation/tools/commit/9f372abdfc27aba93b303c7b214991919c0c18c3))
|
|
138
|
+
* improve schema type name normalisation ([1a18b26](https://github.com/twinfoundation/tools/commit/1a18b267d87e9179bda01b396b256c450ae2889e))
|
|
139
|
+
* move package to framework repo ([4490bda](https://github.com/twinfoundation/tools/commit/4490bda472d4dc8ddfe931e2fce81f3411de9ab3))
|
|
140
|
+
* strip Omit types ([3a079f9](https://github.com/twinfoundation/tools/commit/3a079f9abe8127c5b44a2b9382babf2f19629d08))
|
|
141
|
+
* use most recent JSON schema specs ([4598cbf](https://github.com/twinfoundation/tools/commit/4598cbf29f7b82dba4a9f3b19f81dfe66f5a6060))
|
|
142
|
+
* use shared store mechanism ([#31](https://github.com/twinfoundation/tools/issues/31)) ([d9fe68b](https://github.com/twinfoundation/tools/commit/d9fe68b903d1268c7cb3c64772df5cb78fd63667))
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### Bug Fixes
|
|
146
|
+
|
|
147
|
+
* fix locale resource name ([53ad5b5](https://github.com/twinfoundation/tools/commit/53ad5b56f19a5082f16a4f1e4a761e114dce8250))
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
### Dependencies
|
|
151
|
+
|
|
152
|
+
* The following workspace dependencies were updated
|
|
153
|
+
* dependencies
|
|
154
|
+
* @twin.org/tools-core bumped from 0.0.2-next.0 to 0.0.2-next.1
|
|
155
|
+
|
|
3
156
|
## 0.0.1 (2025-07-03)
|
|
4
157
|
|
|
5
158
|
|