swagger-typescript-api 13.6.10 → 13.6.11
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/cli.cjs +1 -1
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/cli.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{src-DsH2wrQK.cjs → src-D7B_7nSd.cjs} +82 -4
- package/dist/src-D7B_7nSd.cjs.map +1 -0
- package/dist/{src-C3MRkcHD.mjs → src-Da26nVUM.mjs} +82 -4
- package/dist/src-Da26nVUM.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/src-C3MRkcHD.mjs.map +0 -1
- package/dist/src-DsH2wrQK.cjs.map +0 -1
|
@@ -208,7 +208,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
208
208
|
//#endregion
|
|
209
209
|
//#region package.json
|
|
210
210
|
var name = "swagger-typescript-api";
|
|
211
|
-
var version = "13.6.
|
|
211
|
+
var version = "13.6.11";
|
|
212
212
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
213
213
|
//#endregion
|
|
214
214
|
//#region src/constants.ts
|
|
@@ -376,10 +376,15 @@ var CodeGenConfig = class {
|
|
|
376
376
|
sortTypes = false;
|
|
377
377
|
sortRoutes = false;
|
|
378
378
|
templatePaths = {
|
|
379
|
+
/** `templates/base` */
|
|
379
380
|
base: "",
|
|
381
|
+
/** `templates/default` */
|
|
380
382
|
default: "",
|
|
383
|
+
/** `templates/modular` */
|
|
381
384
|
modular: "",
|
|
385
|
+
/** usage path if `--templates` option is not set */
|
|
382
386
|
original: "",
|
|
387
|
+
/** custom path to templates (`--templates`) */
|
|
383
388
|
custom: ""
|
|
384
389
|
};
|
|
385
390
|
/** Record<templateName, templateContent> */
|
|
@@ -479,18 +484,48 @@ var CodeGenConfig = class {
|
|
|
479
484
|
Ts = {
|
|
480
485
|
Keyword: structuredClone(TsKeyword),
|
|
481
486
|
CodeGenKeyword: structuredClone(TsCodeGenKeyword),
|
|
487
|
+
/**
|
|
488
|
+
* $A[] or Array<$A>
|
|
489
|
+
*/
|
|
482
490
|
ArrayType: (content) => {
|
|
483
491
|
if (this.anotherArrayType) return this.Ts.TypeWithGeneric(this.Ts.Keyword.Array, [content]);
|
|
484
492
|
return `${this.Ts.ExpressionGroup(content)}[]`;
|
|
485
493
|
},
|
|
494
|
+
/**
|
|
495
|
+
* "$A"
|
|
496
|
+
*/
|
|
486
497
|
StringValue: (content) => `"${content}"`,
|
|
498
|
+
/**
|
|
499
|
+
* $A
|
|
500
|
+
*/
|
|
487
501
|
BooleanValue: (content) => `${content}`,
|
|
502
|
+
/**
|
|
503
|
+
* $A
|
|
504
|
+
*/
|
|
488
505
|
NumberValue: (content) => `${content}`,
|
|
506
|
+
/**
|
|
507
|
+
* $A
|
|
508
|
+
*/
|
|
489
509
|
NullValue: () => "null",
|
|
510
|
+
/**
|
|
511
|
+
* $A1 | $A2
|
|
512
|
+
*/
|
|
490
513
|
UnionType: (contents) => (0, es_toolkit.uniq)(contents).join(` ${this.Ts.Keyword.Union} `),
|
|
514
|
+
/**
|
|
515
|
+
* ($A1)
|
|
516
|
+
*/
|
|
491
517
|
ExpressionGroup: (content) => content ? `(${content})` : "",
|
|
518
|
+
/**
|
|
519
|
+
* $A1 & $A2
|
|
520
|
+
*/
|
|
492
521
|
IntersectionType: (contents) => (0, es_toolkit.uniq)(contents).join(` ${this.Ts.Keyword.Intersection} `),
|
|
522
|
+
/**
|
|
523
|
+
* Record<$A1, $A2>
|
|
524
|
+
*/
|
|
493
525
|
RecordType: (key, value) => this.Ts.TypeWithGeneric(this.Ts.Keyword.Record, [key, value]),
|
|
526
|
+
/**
|
|
527
|
+
* readonly $key?:$value
|
|
528
|
+
*/
|
|
494
529
|
TypeField: ({ readonly, key, optional, value }) => (0, es_toolkit.compact)([
|
|
495
530
|
readonly && "readonly ",
|
|
496
531
|
key,
|
|
@@ -498,25 +533,57 @@ var CodeGenConfig = class {
|
|
|
498
533
|
": ",
|
|
499
534
|
value
|
|
500
535
|
]).join(""),
|
|
536
|
+
/**
|
|
537
|
+
* [key: $A1]: $A2
|
|
538
|
+
*/
|
|
501
539
|
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
|
|
540
|
+
/**
|
|
541
|
+
* EnumName.EnumKey
|
|
542
|
+
*/
|
|
502
543
|
EnumUsageKey: (enumStruct, key) => `${enumStruct}.${key}`,
|
|
544
|
+
/**
|
|
545
|
+
* $A1 = $A2
|
|
546
|
+
*/
|
|
503
547
|
EnumField: (key, value) => `${key} = ${value}`,
|
|
548
|
+
/**
|
|
549
|
+
* /\** description \*\/
|
|
550
|
+
*/
|
|
504
551
|
EnumFieldDescription: (description) => {
|
|
505
552
|
if (description) return ` /** ${description} */`;
|
|
506
553
|
else return "";
|
|
507
554
|
},
|
|
555
|
+
/**
|
|
556
|
+
* /\** $A0.description \*\/
|
|
557
|
+
* $A0.key = $A0.value,
|
|
558
|
+
* /\** $A1.description \*\/
|
|
559
|
+
* $A1.key = $A1.value,
|
|
560
|
+
* /\** $AN.description \*\/
|
|
561
|
+
* $AN.key = $AN.value,
|
|
562
|
+
*/
|
|
508
563
|
EnumFieldsWrapper: (contents) => contents.map(({ key, value, description }) => {
|
|
509
564
|
return (0, es_toolkit.compact)([this.Ts.EnumFieldDescription(description), ` ${this.Ts.EnumField(key, value)}`]).join("\n");
|
|
510
565
|
}).join(",\n"),
|
|
566
|
+
/**
|
|
567
|
+
* {\n $A \n}
|
|
568
|
+
*/
|
|
511
569
|
ObjectWrapper: (content) => `{\n${content}\n}`,
|
|
570
|
+
/**
|
|
571
|
+
* /** $A *\/
|
|
572
|
+
*/
|
|
512
573
|
MultilineComment: (contents, formatFn) => [...contents.length === 1 ? [`/** ${contents[0]} */`] : [
|
|
513
574
|
"/**",
|
|
514
575
|
...contents.map((content) => ` * ${content}`),
|
|
515
576
|
" */"
|
|
516
577
|
]].map((part) => `${formatFn ? formatFn(part) : part}\n`),
|
|
578
|
+
/**
|
|
579
|
+
* $A1<...$A2.join(,)>
|
|
580
|
+
*/
|
|
517
581
|
TypeWithGeneric: (typeName, genericArgs) => {
|
|
518
582
|
return `${typeName}${genericArgs.length ? `<${genericArgs.join(",")}>` : ""}`;
|
|
519
583
|
},
|
|
584
|
+
/**
|
|
585
|
+
* [$A1, $A2, ...$AN]
|
|
586
|
+
*/
|
|
520
587
|
Tuple: (values) => {
|
|
521
588
|
return `[${values.join(", ")}]`;
|
|
522
589
|
}
|
|
@@ -533,6 +600,7 @@ var CodeGenConfig = class {
|
|
|
533
600
|
file: () => this.Ts.Keyword.File,
|
|
534
601
|
string: {
|
|
535
602
|
$default: this.Ts.Keyword.String,
|
|
603
|
+
/** formats */
|
|
536
604
|
binary: () => this.Ts.Keyword.File,
|
|
537
605
|
byte: () => this.Ts.Keyword.Blob,
|
|
538
606
|
file: () => this.Ts.Keyword.File,
|
|
@@ -656,6 +724,7 @@ var SchemaComponentsMap = class {
|
|
|
656
724
|
typeName,
|
|
657
725
|
rawTypeData,
|
|
658
726
|
componentName: rawComponentName === "definitions" ? "schemas" : rawComponentName,
|
|
727
|
+
/** result from schema parser */
|
|
659
728
|
typeData: null
|
|
660
729
|
};
|
|
661
730
|
}
|
|
@@ -1195,10 +1264,11 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1195
1264
|
const rawTypeData = (0, es_toolkit_compat.get)(this.schemaUtils.getSchemaRefType(property), "rawTypeData", {});
|
|
1196
1265
|
const nullable = !!(rawTypeData.nullable || property.nullable);
|
|
1197
1266
|
const fieldName = this.typeNameFormatter.isValidName(name) ? name : this.config.Ts.StringValue(name);
|
|
1198
|
-
const
|
|
1267
|
+
const rawFieldValue = this.schemaParserFabric.createSchemaParser({
|
|
1199
1268
|
schema: property,
|
|
1200
1269
|
schemaPath: [...this.schemaPath, name]
|
|
1201
1270
|
}).getInlineParseContent();
|
|
1271
|
+
const fieldValue = nullable ? this.schemaUtils.safeAddNullToType(property, rawFieldValue) : rawFieldValue;
|
|
1202
1272
|
const readOnly = property.readOnly;
|
|
1203
1273
|
const complexType = this.schemaUtils.getComplexType(property);
|
|
1204
1274
|
const rawDataComplexType = this.schemaUtils.getComplexType(rawTypeData);
|
|
@@ -1493,7 +1563,10 @@ var SchemaUtils = class {
|
|
|
1493
1563
|
};
|
|
1494
1564
|
isNullMissingInType = (schema, type) => {
|
|
1495
1565
|
const { nullable, type: schemaType } = schema || {};
|
|
1496
|
-
|
|
1566
|
+
if (!(nullable || !!(0, es_toolkit_compat.get)(schema, "x-nullable") || schemaType === this.config.Ts.Keyword.Null) || typeof type !== "string") return false;
|
|
1567
|
+
const nullKeyword = this.config.Ts.Keyword.Null;
|
|
1568
|
+
const lastLine = type.trimEnd().split("\n").pop() ?? type;
|
|
1569
|
+
return !lastLine.includes(` ${nullKeyword}`) && !lastLine.includes(`${nullKeyword} `);
|
|
1497
1570
|
};
|
|
1498
1571
|
safeAddNullToType = (schema, type) => {
|
|
1499
1572
|
if (this.isNullMissingInType(schema, type)) return this.config.Ts.UnionType([type, this.config.Ts.Keyword.Null]);
|
|
@@ -3002,10 +3075,15 @@ var TemplatesWorker = class {
|
|
|
3002
3075
|
const defaultTemplatesPath = node_path.resolve(__dirname, "../templates/default");
|
|
3003
3076
|
const modularTemplatesPath = node_path.resolve(__dirname, "../templates/modular");
|
|
3004
3077
|
return {
|
|
3078
|
+
/** `templates/base` */
|
|
3005
3079
|
base: baseTemplatesPath,
|
|
3080
|
+
/** `templates/default` */
|
|
3006
3081
|
default: defaultTemplatesPath,
|
|
3082
|
+
/** `templates/modular` */
|
|
3007
3083
|
modular: modularTemplatesPath,
|
|
3084
|
+
/** usage path if `--templates` option is not set */
|
|
3008
3085
|
original: config.modular ? modularTemplatesPath : defaultTemplatesPath,
|
|
3086
|
+
/** custom path to templates (`--templates`) */
|
|
3009
3087
|
custom: config.templates && node_path.resolve(process.cwd(), config.templates)
|
|
3010
3088
|
};
|
|
3011
3089
|
};
|
|
@@ -3739,4 +3817,4 @@ Object.defineProperty(exports, "version", {
|
|
|
3739
3817
|
}
|
|
3740
3818
|
});
|
|
3741
3819
|
|
|
3742
|
-
//# sourceMappingURL=src-
|
|
3820
|
+
//# sourceMappingURL=src-D7B_7nSd.cjs.map
|