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
|
@@ -169,7 +169,7 @@ var ComponentTypeNameResolver = class extends NameResolver {
|
|
|
169
169
|
//#endregion
|
|
170
170
|
//#region package.json
|
|
171
171
|
var name = "swagger-typescript-api";
|
|
172
|
-
var version = "13.6.
|
|
172
|
+
var version = "13.6.11";
|
|
173
173
|
var description = "Generate the API client for Fetch or Axios from an OpenAPI Specification";
|
|
174
174
|
//#endregion
|
|
175
175
|
//#region src/constants.ts
|
|
@@ -337,10 +337,15 @@ var CodeGenConfig = class {
|
|
|
337
337
|
sortTypes = false;
|
|
338
338
|
sortRoutes = false;
|
|
339
339
|
templatePaths = {
|
|
340
|
+
/** `templates/base` */
|
|
340
341
|
base: "",
|
|
342
|
+
/** `templates/default` */
|
|
341
343
|
default: "",
|
|
344
|
+
/** `templates/modular` */
|
|
342
345
|
modular: "",
|
|
346
|
+
/** usage path if `--templates` option is not set */
|
|
343
347
|
original: "",
|
|
348
|
+
/** custom path to templates (`--templates`) */
|
|
344
349
|
custom: ""
|
|
345
350
|
};
|
|
346
351
|
/** Record<templateName, templateContent> */
|
|
@@ -440,18 +445,48 @@ var CodeGenConfig = class {
|
|
|
440
445
|
Ts = {
|
|
441
446
|
Keyword: structuredClone(TsKeyword),
|
|
442
447
|
CodeGenKeyword: structuredClone(TsCodeGenKeyword),
|
|
448
|
+
/**
|
|
449
|
+
* $A[] or Array<$A>
|
|
450
|
+
*/
|
|
443
451
|
ArrayType: (content) => {
|
|
444
452
|
if (this.anotherArrayType) return this.Ts.TypeWithGeneric(this.Ts.Keyword.Array, [content]);
|
|
445
453
|
return `${this.Ts.ExpressionGroup(content)}[]`;
|
|
446
454
|
},
|
|
455
|
+
/**
|
|
456
|
+
* "$A"
|
|
457
|
+
*/
|
|
447
458
|
StringValue: (content) => `"${content}"`,
|
|
459
|
+
/**
|
|
460
|
+
* $A
|
|
461
|
+
*/
|
|
448
462
|
BooleanValue: (content) => `${content}`,
|
|
463
|
+
/**
|
|
464
|
+
* $A
|
|
465
|
+
*/
|
|
449
466
|
NumberValue: (content) => `${content}`,
|
|
467
|
+
/**
|
|
468
|
+
* $A
|
|
469
|
+
*/
|
|
450
470
|
NullValue: () => "null",
|
|
471
|
+
/**
|
|
472
|
+
* $A1 | $A2
|
|
473
|
+
*/
|
|
451
474
|
UnionType: (contents) => uniq(contents).join(` ${this.Ts.Keyword.Union} `),
|
|
475
|
+
/**
|
|
476
|
+
* ($A1)
|
|
477
|
+
*/
|
|
452
478
|
ExpressionGroup: (content) => content ? `(${content})` : "",
|
|
479
|
+
/**
|
|
480
|
+
* $A1 & $A2
|
|
481
|
+
*/
|
|
453
482
|
IntersectionType: (contents) => uniq(contents).join(` ${this.Ts.Keyword.Intersection} `),
|
|
483
|
+
/**
|
|
484
|
+
* Record<$A1, $A2>
|
|
485
|
+
*/
|
|
454
486
|
RecordType: (key, value) => this.Ts.TypeWithGeneric(this.Ts.Keyword.Record, [key, value]),
|
|
487
|
+
/**
|
|
488
|
+
* readonly $key?:$value
|
|
489
|
+
*/
|
|
455
490
|
TypeField: ({ readonly, key, optional, value }) => compact([
|
|
456
491
|
readonly && "readonly ",
|
|
457
492
|
key,
|
|
@@ -459,25 +494,57 @@ var CodeGenConfig = class {
|
|
|
459
494
|
": ",
|
|
460
495
|
value
|
|
461
496
|
]).join(""),
|
|
497
|
+
/**
|
|
498
|
+
* [key: $A1]: $A2
|
|
499
|
+
*/
|
|
462
500
|
InterfaceDynamicField: (key, value) => `[key: ${key}]: ${value}`,
|
|
501
|
+
/**
|
|
502
|
+
* EnumName.EnumKey
|
|
503
|
+
*/
|
|
463
504
|
EnumUsageKey: (enumStruct, key) => `${enumStruct}.${key}`,
|
|
505
|
+
/**
|
|
506
|
+
* $A1 = $A2
|
|
507
|
+
*/
|
|
464
508
|
EnumField: (key, value) => `${key} = ${value}`,
|
|
509
|
+
/**
|
|
510
|
+
* /\** description \*\/
|
|
511
|
+
*/
|
|
465
512
|
EnumFieldDescription: (description) => {
|
|
466
513
|
if (description) return ` /** ${description} */`;
|
|
467
514
|
else return "";
|
|
468
515
|
},
|
|
516
|
+
/**
|
|
517
|
+
* /\** $A0.description \*\/
|
|
518
|
+
* $A0.key = $A0.value,
|
|
519
|
+
* /\** $A1.description \*\/
|
|
520
|
+
* $A1.key = $A1.value,
|
|
521
|
+
* /\** $AN.description \*\/
|
|
522
|
+
* $AN.key = $AN.value,
|
|
523
|
+
*/
|
|
469
524
|
EnumFieldsWrapper: (contents) => contents.map(({ key, value, description }) => {
|
|
470
525
|
return compact([this.Ts.EnumFieldDescription(description), ` ${this.Ts.EnumField(key, value)}`]).join("\n");
|
|
471
526
|
}).join(",\n"),
|
|
527
|
+
/**
|
|
528
|
+
* {\n $A \n}
|
|
529
|
+
*/
|
|
472
530
|
ObjectWrapper: (content) => `{\n${content}\n}`,
|
|
531
|
+
/**
|
|
532
|
+
* /** $A *\/
|
|
533
|
+
*/
|
|
473
534
|
MultilineComment: (contents, formatFn) => [...contents.length === 1 ? [`/** ${contents[0]} */`] : [
|
|
474
535
|
"/**",
|
|
475
536
|
...contents.map((content) => ` * ${content}`),
|
|
476
537
|
" */"
|
|
477
538
|
]].map((part) => `${formatFn ? formatFn(part) : part}\n`),
|
|
539
|
+
/**
|
|
540
|
+
* $A1<...$A2.join(,)>
|
|
541
|
+
*/
|
|
478
542
|
TypeWithGeneric: (typeName, genericArgs) => {
|
|
479
543
|
return `${typeName}${genericArgs.length ? `<${genericArgs.join(",")}>` : ""}`;
|
|
480
544
|
},
|
|
545
|
+
/**
|
|
546
|
+
* [$A1, $A2, ...$AN]
|
|
547
|
+
*/
|
|
481
548
|
Tuple: (values) => {
|
|
482
549
|
return `[${values.join(", ")}]`;
|
|
483
550
|
}
|
|
@@ -494,6 +561,7 @@ var CodeGenConfig = class {
|
|
|
494
561
|
file: () => this.Ts.Keyword.File,
|
|
495
562
|
string: {
|
|
496
563
|
$default: this.Ts.Keyword.String,
|
|
564
|
+
/** formats */
|
|
497
565
|
binary: () => this.Ts.Keyword.File,
|
|
498
566
|
byte: () => this.Ts.Keyword.Blob,
|
|
499
567
|
file: () => this.Ts.Keyword.File,
|
|
@@ -617,6 +685,7 @@ var SchemaComponentsMap = class {
|
|
|
617
685
|
typeName,
|
|
618
686
|
rawTypeData,
|
|
619
687
|
componentName: rawComponentName === "definitions" ? "schemas" : rawComponentName,
|
|
688
|
+
/** result from schema parser */
|
|
620
689
|
typeData: null
|
|
621
690
|
};
|
|
622
691
|
}
|
|
@@ -1156,10 +1225,11 @@ var ObjectSchemaParser = class extends MonoSchemaParser {
|
|
|
1156
1225
|
const rawTypeData = get(this.schemaUtils.getSchemaRefType(property), "rawTypeData", {});
|
|
1157
1226
|
const nullable = !!(rawTypeData.nullable || property.nullable);
|
|
1158
1227
|
const fieldName = this.typeNameFormatter.isValidName(name) ? name : this.config.Ts.StringValue(name);
|
|
1159
|
-
const
|
|
1228
|
+
const rawFieldValue = this.schemaParserFabric.createSchemaParser({
|
|
1160
1229
|
schema: property,
|
|
1161
1230
|
schemaPath: [...this.schemaPath, name]
|
|
1162
1231
|
}).getInlineParseContent();
|
|
1232
|
+
const fieldValue = nullable ? this.schemaUtils.safeAddNullToType(property, rawFieldValue) : rawFieldValue;
|
|
1163
1233
|
const readOnly = property.readOnly;
|
|
1164
1234
|
const complexType = this.schemaUtils.getComplexType(property);
|
|
1165
1235
|
const rawDataComplexType = this.schemaUtils.getComplexType(rawTypeData);
|
|
@@ -1454,7 +1524,10 @@ var SchemaUtils = class {
|
|
|
1454
1524
|
};
|
|
1455
1525
|
isNullMissingInType = (schema, type) => {
|
|
1456
1526
|
const { nullable, type: schemaType } = schema || {};
|
|
1457
|
-
|
|
1527
|
+
if (!(nullable || !!get(schema, "x-nullable") || schemaType === this.config.Ts.Keyword.Null) || typeof type !== "string") return false;
|
|
1528
|
+
const nullKeyword = this.config.Ts.Keyword.Null;
|
|
1529
|
+
const lastLine = type.trimEnd().split("\n").pop() ?? type;
|
|
1530
|
+
return !lastLine.includes(` ${nullKeyword}`) && !lastLine.includes(`${nullKeyword} `);
|
|
1458
1531
|
};
|
|
1459
1532
|
safeAddNullToType = (schema, type) => {
|
|
1460
1533
|
if (this.isNullMissingInType(schema, type)) return this.config.Ts.UnionType([type, this.config.Ts.Keyword.Null]);
|
|
@@ -2963,10 +3036,15 @@ var TemplatesWorker = class {
|
|
|
2963
3036
|
const defaultTemplatesPath = path$1.resolve(__dirname, "../templates/default");
|
|
2964
3037
|
const modularTemplatesPath = path$1.resolve(__dirname, "../templates/modular");
|
|
2965
3038
|
return {
|
|
3039
|
+
/** `templates/base` */
|
|
2966
3040
|
base: baseTemplatesPath,
|
|
3041
|
+
/** `templates/default` */
|
|
2967
3042
|
default: defaultTemplatesPath,
|
|
3043
|
+
/** `templates/modular` */
|
|
2968
3044
|
modular: modularTemplatesPath,
|
|
3045
|
+
/** usage path if `--templates` option is not set */
|
|
2969
3046
|
original: config.modular ? modularTemplatesPath : defaultTemplatesPath,
|
|
3047
|
+
/** custom path to templates (`--templates`) */
|
|
2970
3048
|
custom: config.templates && path$1.resolve(process.cwd(), config.templates)
|
|
2971
3049
|
};
|
|
2972
3050
|
};
|
|
@@ -3629,4 +3707,4 @@ async function generateApi(config) {
|
|
|
3629
3707
|
//#endregion
|
|
3630
3708
|
export { SCHEMA_TYPES as a, constants_exports as c, version as d, RequestContentKind as i, description as l, generateTemplates as n, CodeGenConfig as o, TemplatesGenConfig as r, HTTP_CLIENT as s, generateApi as t, name as u };
|
|
3631
3709
|
|
|
3632
|
-
//# sourceMappingURL=src-
|
|
3710
|
+
//# sourceMappingURL=src-Da26nVUM.mjs.map
|