swagger-typescript-api 13.0.7 → 13.0.8
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/package.json +7 -4
- package/src/code-formatter.js +1 -1
- package/src/code-gen-process.js +1 -1
- package/src/configuration.js +1 -1
- package/src/schema-parser/base-schema-parsers/enum.js +1 -1
- package/src/schema-parser/schema-formatters.js +1 -1
- package/src/schema-parser/schema-parser.js +1 -4
- package/src/schema-parser/schema-utils.js +3 -5
- package/src/schema-routes/schema-routes.js +6 -15
- package/src/util/file-system.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-typescript-api",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.8",
|
|
4
4
|
"description": "Generate TypeScript/JavaScript API from Swagger schema",
|
|
5
5
|
"homepage": "https://github.com/acacode/swagger-typescript-api",
|
|
6
6
|
"bugs": "https://github.com/acacode/swagger-typescript-api/issues",
|
|
@@ -46,12 +46,15 @@
|
|
|
46
46
|
"prettier": "~3.3.2",
|
|
47
47
|
"swagger-schema-official": "2.0.0-bab6bed",
|
|
48
48
|
"swagger2openapi": "^7.0.8",
|
|
49
|
-
"typescript": "~5.
|
|
49
|
+
"typescript": "~5.5.2"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@biomejs/biome": "1.8.
|
|
52
|
+
"@biomejs/biome": "1.8.2",
|
|
53
|
+
"@types/didyoumean": "1.2.2",
|
|
54
|
+
"@types/js-yaml": "4.0.9",
|
|
53
55
|
"@types/lodash": "4.17.5",
|
|
54
|
-
"@types/node": "20.14.
|
|
56
|
+
"@types/node": "20.14.7",
|
|
57
|
+
"@types/swagger2openapi": "7.0.4",
|
|
55
58
|
"axios": "1.7.2",
|
|
56
59
|
"shx": "0.3.4",
|
|
57
60
|
"vitest": "1.6.0"
|
package/src/code-formatter.js
CHANGED
|
@@ -23,7 +23,7 @@ class CodeFormatter {
|
|
|
23
23
|
{ newLineCharacter: ts.sys.newLine },
|
|
24
24
|
)[0];
|
|
25
25
|
|
|
26
|
-
if (fileTextChanges
|
|
26
|
+
if (fileTextChanges?.textChanges.length) {
|
|
27
27
|
return _.reduceRight(
|
|
28
28
|
fileTextChanges.textChanges,
|
|
29
29
|
(content, { span, newText }) =>
|
package/src/code-gen-process.js
CHANGED
|
@@ -533,7 +533,7 @@ class CodeGenProcess {
|
|
|
533
533
|
|
|
534
534
|
createApiConfig = (swaggerSchema) => {
|
|
535
535
|
const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
|
|
536
|
-
const server =
|
|
536
|
+
const server = servers?.[0] || { url: "" };
|
|
537
537
|
const { title = "No title", version } = info || {};
|
|
538
538
|
const { url: serverUrl } = server;
|
|
539
539
|
|
package/src/configuration.js
CHANGED
|
@@ -38,7 +38,7 @@ class EnumSchemaParser extends MonoSchemaParser {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
const refType = this.schemaUtils.getSchemaRefType(this.schema);
|
|
41
|
-
const $ref =
|
|
41
|
+
const $ref = refType?.$ref || null;
|
|
42
42
|
|
|
43
43
|
// fix schema when enum has length 1+ but value is []
|
|
44
44
|
if (Array.isArray(this.schema.enum)) {
|
|
@@ -105,7 +105,7 @@ class SchemaFormatters {
|
|
|
105
105
|
_.get(parsedSchema, ["schemaType"]) ||
|
|
106
106
|
_.get(parsedSchema, ["$parsed", "schemaType"]);
|
|
107
107
|
const formatterFn = _.get(this, [formatType, schemaType]);
|
|
108
|
-
return
|
|
108
|
+
return formatterFn?.(parsedSchema) || parsedSchema;
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
formatDescription = (description, inline) => {
|
|
@@ -213,10 +213,7 @@ class SchemaParser {
|
|
|
213
213
|
this.schema = { type: this.config.Ts.Keyword.Null };
|
|
214
214
|
}
|
|
215
215
|
// schema is response schema
|
|
216
|
-
if (
|
|
217
|
-
"content" in this.schema &&
|
|
218
|
-
typeof this.schema["content"] === "object"
|
|
219
|
-
) {
|
|
216
|
+
if ("content" in this.schema && typeof this.schema.content === "object") {
|
|
220
217
|
const schema = this.extractSchemaFromResponseStruct(this.schema);
|
|
221
218
|
const schemaParser = this.schemaParserFabric.createSchemaParser({
|
|
222
219
|
schema,
|
|
@@ -33,13 +33,13 @@ class SchemaUtils {
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
isRefSchema = (schema) => {
|
|
36
|
-
return !!
|
|
36
|
+
return !!schema?.$ref;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
getEnumNames = (schema) => {
|
|
40
40
|
return (
|
|
41
41
|
schema["x-enumNames"] ||
|
|
42
|
-
schema
|
|
42
|
+
schema.xEnumNames ||
|
|
43
43
|
schema["x-enumnames"] ||
|
|
44
44
|
schema["x-enum-varnames"]
|
|
45
45
|
);
|
|
@@ -143,9 +143,7 @@ class SchemaUtils {
|
|
|
143
143
|
const refData = this.getSchemaRefType(childSchema);
|
|
144
144
|
|
|
145
145
|
if (refData) {
|
|
146
|
-
const refObjectProperties = _.keys(
|
|
147
|
-
(refData.rawTypeData && refData.rawTypeData.properties) || {},
|
|
148
|
-
);
|
|
146
|
+
const refObjectProperties = _.keys(refData.rawTypeData?.properties || {});
|
|
149
147
|
const existedRequiredKeys = refObjectProperties.filter((key) =>
|
|
150
148
|
required.includes(key),
|
|
151
149
|
);
|
|
@@ -160,7 +160,7 @@ class SchemaRoutes {
|
|
|
160
160
|
const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
|
|
161
161
|
const queryParams = [];
|
|
162
162
|
|
|
163
|
-
if (queryParamMatches
|
|
163
|
+
if (queryParamMatches?.length) {
|
|
164
164
|
queryParamMatches.forEach((match) => {
|
|
165
165
|
fixedRoute = fixedRoute.replace(match, "");
|
|
166
166
|
});
|
|
@@ -220,11 +220,7 @@ class SchemaRoutes {
|
|
|
220
220
|
this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
|
|
221
221
|
let routeParam = null;
|
|
222
222
|
|
|
223
|
-
if (
|
|
224
|
-
refTypeInfo &&
|
|
225
|
-
refTypeInfo.rawTypeData.in &&
|
|
226
|
-
refTypeInfo.rawTypeData
|
|
227
|
-
) {
|
|
223
|
+
if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
|
|
228
224
|
if (!routeParams[refTypeInfo.rawTypeData.in]) {
|
|
229
225
|
routeParams[refTypeInfo.rawTypeData.in] = [];
|
|
230
226
|
}
|
|
@@ -345,7 +341,7 @@ class SchemaRoutes {
|
|
|
345
341
|
|
|
346
342
|
/* for example: dataType = "multipart/form-data" */
|
|
347
343
|
for (const dataType in content) {
|
|
348
|
-
if (content[dataType]
|
|
344
|
+
if (content[dataType]?.schema) {
|
|
349
345
|
return {
|
|
350
346
|
...content[dataType].schema,
|
|
351
347
|
dataType,
|
|
@@ -510,9 +506,7 @@ class SchemaRoutes {
|
|
|
510
506
|
responses: responseInfos,
|
|
511
507
|
success: {
|
|
512
508
|
schema: successResponse,
|
|
513
|
-
type:
|
|
514
|
-
(successResponse && successResponse.type) ||
|
|
515
|
-
this.config.Ts.Keyword.Any,
|
|
509
|
+
type: successResponse?.type || this.config.Ts.Keyword.Any,
|
|
516
510
|
},
|
|
517
511
|
error: {
|
|
518
512
|
schemas: errorResponses,
|
|
@@ -640,10 +634,7 @@ class SchemaRoutes {
|
|
|
640
634
|
}
|
|
641
635
|
|
|
642
636
|
return {
|
|
643
|
-
paramName:
|
|
644
|
-
requestBodyName ||
|
|
645
|
-
(requestBody && requestBody.name) ||
|
|
646
|
-
DEFAULT_BODY_ARG_NAME,
|
|
637
|
+
paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
|
|
647
638
|
contentTypes,
|
|
648
639
|
contentKind,
|
|
649
640
|
schema,
|
|
@@ -892,7 +883,7 @@ class SchemaRoutes {
|
|
|
892
883
|
moduleNameFirstTag && firstTag
|
|
893
884
|
? _.camelCase(firstTag)
|
|
894
885
|
: _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);
|
|
895
|
-
let hasSecurity = !!
|
|
886
|
+
let hasSecurity = !!globalSecurity?.length;
|
|
896
887
|
if (security) {
|
|
897
888
|
hasSecurity = security.length > 0;
|
|
898
889
|
}
|