swagger-typescript-api 13.0.3 → 13.0.5
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/README.md +310 -369
- package/cli/constants.js +3 -3
- package/cli/execute.js +12 -12
- package/cli/index.js +16 -16
- package/cli/operations/display-help.js +25 -25
- package/cli/parse-args.js +3 -3
- package/cli/process-option.js +11 -11
- package/index.d.ts +140 -45
- package/index.js +110 -111
- package/package.json +93 -108
- package/src/code-formatter.js +6 -6
- package/src/code-gen-process.js +45 -45
- package/src/commands/generate-templates/configuration.js +2 -2
- package/src/commands/generate-templates/index.js +1 -1
- package/src/commands/generate-templates/templates-gen-process.js +21 -21
- package/src/component-type-name-resolver.js +4 -4
- package/src/configuration.js +107 -107
- package/src/constants.js +26 -26
- package/src/index.js +3 -3
- package/src/schema-components-map.js +3 -3
- package/src/schema-parser/base-schema-parsers/array.js +3 -3
- package/src/schema-parser/base-schema-parsers/complex.js +5 -5
- package/src/schema-parser/base-schema-parsers/discriminator.js +12 -12
- package/src/schema-parser/base-schema-parsers/enum.js +12 -12
- package/src/schema-parser/base-schema-parsers/object.js +8 -8
- package/src/schema-parser/base-schema-parsers/primitive.js +3 -3
- package/src/schema-parser/complex-schema-parsers/all-of.js +2 -2
- package/src/schema-parser/complex-schema-parsers/any-of.js +2 -2
- package/src/schema-parser/complex-schema-parsers/not.js +1 -1
- package/src/schema-parser/complex-schema-parsers/one-of.js +2 -2
- package/src/schema-parser/mono-schema-parser.js +1 -1
- package/src/schema-parser/schema-formatters.js +14 -14
- package/src/schema-parser/schema-parser-fabric.js +5 -5
- package/src/schema-parser/schema-parser.js +24 -24
- package/src/schema-parser/schema-utils.js +21 -21
- package/src/schema-parser/util/enum-key-resolver.js +2 -2
- package/src/schema-routes/schema-routes.js +68 -68
- package/src/schema-routes/util/specific-arg-name-resolver.js +2 -2
- package/src/schema-walker.js +7 -7
- package/src/swagger-schema-resolver.js +16 -16
- package/src/templates-worker.js +21 -18
- package/src/translators/javascript.js +7 -7
- package/src/translators/translator.js +1 -1
- package/src/type-name-formatter.js +16 -16
- package/src/util/file-system.js +13 -14
- package/src/util/id.js +2 -2
- package/src/util/internal-case.js +1 -1
- package/src/util/logger.js +27 -27
- package/src/util/name-resolver.js +5 -5
- package/src/util/object-assign.js +2 -2
- package/src/util/pascal-case.js +1 -1
- package/src/util/request.js +15 -10
- package/templates/README.md +15 -14
- package/templates/base/README.md +4 -5
- package/templates/base/http-clients/fetch-http-client.ejs +1 -1
- package/templates/base/route-name.ejs +4 -4
- package/templates/default/README.md +4 -4
- package/templates/modular/README.md +4 -4
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {MonoSchemaParser} from "./src/schema-parser/mono-schema-parser";
|
|
1
|
+
import type { MonoSchemaParser } from "./src/schema-parser/mono-schema-parser";
|
|
2
2
|
|
|
3
3
|
type HttpClientType = "axios" | "fetch";
|
|
4
4
|
|
|
@@ -8,6 +8,11 @@ interface GenerateApiParamsBase {
|
|
|
8
8
|
*/
|
|
9
9
|
name?: string;
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* name of the main exported class
|
|
13
|
+
*/
|
|
14
|
+
apiClassName?: string;
|
|
15
|
+
|
|
11
16
|
/**
|
|
12
17
|
* path to folder where will be located the created api module.
|
|
13
18
|
*
|
|
@@ -145,7 +150,9 @@ interface GenerateApiParamsBase {
|
|
|
145
150
|
*/
|
|
146
151
|
addReadonly?: boolean;
|
|
147
152
|
|
|
148
|
-
primitiveTypeConstructs?: (
|
|
153
|
+
primitiveTypeConstructs?: (
|
|
154
|
+
struct: PrimitiveTypeStruct,
|
|
155
|
+
) => Partial<PrimitiveTypeStruct>;
|
|
149
156
|
|
|
150
157
|
codeGenConstructs?: (struct: CodeGenConstruct) => Partial<CodeGenConstruct>;
|
|
151
158
|
|
|
@@ -174,7 +181,7 @@ interface GenerateApiParamsBase {
|
|
|
174
181
|
extractingOptions?: Partial<ExtractingOptions>;
|
|
175
182
|
|
|
176
183
|
/** configuration for fetching swagger schema requests */
|
|
177
|
-
requestOptions?: null | Partial<
|
|
184
|
+
requestOptions?: null | Partial<RequestInit>;
|
|
178
185
|
|
|
179
186
|
/** ts compiler configuration object (for --to-js option) */
|
|
180
187
|
compilerTsConfig?: Record<string, any>;
|
|
@@ -213,17 +220,17 @@ interface GenerateApiParamsBase {
|
|
|
213
220
|
/** fallback name for specific arg name resolver */
|
|
214
221
|
specificArgNameResolverName?: string;
|
|
215
222
|
schemaParsers?: {
|
|
216
|
-
complexOneOf?:MonoSchemaParser;
|
|
217
|
-
complexAllOf?:MonoSchemaParser;
|
|
218
|
-
complexAnyOf?:MonoSchemaParser;
|
|
219
|
-
complexNot?:MonoSchemaParser;
|
|
220
|
-
enum?:MonoSchemaParser;
|
|
221
|
-
object?:MonoSchemaParser;
|
|
222
|
-
complex?:MonoSchemaParser;
|
|
223
|
-
primitive?:MonoSchemaParser;
|
|
224
|
-
discriminator?:MonoSchemaParser;
|
|
223
|
+
complexOneOf?: MonoSchemaParser;
|
|
224
|
+
complexAllOf?: MonoSchemaParser;
|
|
225
|
+
complexAnyOf?: MonoSchemaParser;
|
|
226
|
+
complexNot?: MonoSchemaParser;
|
|
227
|
+
enum?: MonoSchemaParser;
|
|
228
|
+
object?: MonoSchemaParser;
|
|
229
|
+
complex?: MonoSchemaParser;
|
|
230
|
+
primitive?: MonoSchemaParser;
|
|
231
|
+
discriminator?: MonoSchemaParser;
|
|
225
232
|
array?: MonoSchemaParser;
|
|
226
|
-
}
|
|
233
|
+
};
|
|
227
234
|
}
|
|
228
235
|
|
|
229
236
|
type CodeGenConstruct = {
|
|
@@ -270,11 +277,18 @@ type CodeGenConstruct = {
|
|
|
270
277
|
|
|
271
278
|
type PrimitiveTypeStructValue =
|
|
272
279
|
| string
|
|
273
|
-
| ((
|
|
280
|
+
| ((
|
|
281
|
+
schema: Record<string, any>,
|
|
282
|
+
parser: import("./src/schema-parser/schema-parser").SchemaParser,
|
|
283
|
+
) => string);
|
|
274
284
|
|
|
275
285
|
type PrimitiveTypeStruct = Record<
|
|
276
286
|
"integer" | "number" | "boolean" | "object" | "file" | "string" | "array",
|
|
277
|
-
|
|
287
|
+
| string
|
|
288
|
+
| ({ $default: PrimitiveTypeStructValue } & Record<
|
|
289
|
+
string,
|
|
290
|
+
PrimitiveTypeStructValue
|
|
291
|
+
>)
|
|
278
292
|
>;
|
|
279
293
|
|
|
280
294
|
interface GenerateApiParamsFromPath extends GenerateApiParamsBase {
|
|
@@ -298,7 +312,10 @@ interface GenerateApiParamsFromSpecLiteral extends GenerateApiParamsBase {
|
|
|
298
312
|
spec: import("swagger-schema-official").Spec;
|
|
299
313
|
}
|
|
300
314
|
|
|
301
|
-
export type GenerateApiParams =
|
|
315
|
+
export type GenerateApiParams =
|
|
316
|
+
| GenerateApiParamsFromPath
|
|
317
|
+
| GenerateApiParamsFromUrl
|
|
318
|
+
| GenerateApiParamsFromSpecLiteral;
|
|
302
319
|
|
|
303
320
|
type BuildRouteParam = {
|
|
304
321
|
/** {bar} */
|
|
@@ -328,11 +345,20 @@ export interface Hooks {
|
|
|
328
345
|
/** calls after parse\process route path */
|
|
329
346
|
onBuildRoutePath: (data: BuildRoutePath) => BuildRoutePath | void;
|
|
330
347
|
/** calls before insert path param name into string path interpolation */
|
|
331
|
-
onInsertPathParam: (
|
|
348
|
+
onInsertPathParam: (
|
|
349
|
+
paramName: string,
|
|
350
|
+
index: number,
|
|
351
|
+
arr: BuildRouteParam[],
|
|
352
|
+
resultRoute: string,
|
|
353
|
+
) => string | void;
|
|
332
354
|
/** calls after parse schema component */
|
|
333
355
|
onCreateComponent: (component: SchemaComponent) => SchemaComponent | void;
|
|
334
356
|
/** calls before parse any kind of schema */
|
|
335
|
-
onPreParseSchema: (
|
|
357
|
+
onPreParseSchema: (
|
|
358
|
+
originalSchema: any,
|
|
359
|
+
typeName: string,
|
|
360
|
+
schemaType: string,
|
|
361
|
+
) => any;
|
|
336
362
|
/** calls after parse any kind of schema */
|
|
337
363
|
onParseSchema: (originalSchema: any, parsedSchema: any) => any | void;
|
|
338
364
|
/** calls after parse route (return type: customized route (ParsedRoute), nothing change (void), false (ignore this route)) */
|
|
@@ -343,18 +369,32 @@ export interface Hooks {
|
|
|
343
369
|
codeGenProcess: import("./src/code-gen-process").CodeGenProcess,
|
|
344
370
|
) => C | void;
|
|
345
371
|
/** customize configuration object before sending it to ETA templates */
|
|
346
|
-
onPrepareConfig?: <C extends GenerateApiConfiguration>(
|
|
372
|
+
onPrepareConfig?: <C extends GenerateApiConfiguration>(
|
|
373
|
+
currentConfiguration: C,
|
|
374
|
+
) => C | void;
|
|
347
375
|
/** customize route name as you need */
|
|
348
|
-
onCreateRouteName?: (
|
|
376
|
+
onCreateRouteName?: (
|
|
377
|
+
routeNameInfo: RouteNameInfo,
|
|
378
|
+
rawRouteInfo: RawRouteInfo,
|
|
379
|
+
) => RouteNameInfo | void;
|
|
349
380
|
/** customize request params (path params, query params) */
|
|
350
|
-
onCreateRequestParams?: (
|
|
381
|
+
onCreateRequestParams?: (
|
|
382
|
+
rawType: SchemaComponent["rawTypeData"],
|
|
383
|
+
) => SchemaComponent["rawTypeData"] | void;
|
|
351
384
|
/** customize name of model type */
|
|
352
|
-
onFormatTypeName?: (
|
|
385
|
+
onFormatTypeName?: (
|
|
386
|
+
typeName: string,
|
|
387
|
+
rawTypeName?: string,
|
|
388
|
+
schemaType?: "type-name" | "enum-key",
|
|
389
|
+
) => string | void;
|
|
353
390
|
/** customize name of route (operationId), you can do it with using onCreateRouteName too */
|
|
354
|
-
onFormatRouteName?: (
|
|
391
|
+
onFormatRouteName?: (
|
|
392
|
+
routeInfo: RawRouteInfo,
|
|
393
|
+
templateRouteName: string,
|
|
394
|
+
) => string | void;
|
|
355
395
|
}
|
|
356
396
|
|
|
357
|
-
export
|
|
397
|
+
export type RouteNameRouteInfo = {};
|
|
358
398
|
|
|
359
399
|
export type RouteNameInfo = {
|
|
360
400
|
usage: string;
|
|
@@ -424,10 +464,16 @@ export interface SchemaComponent {
|
|
|
424
464
|
discriminator?: {
|
|
425
465
|
propertyName?: string;
|
|
426
466
|
};
|
|
427
|
-
$parsed: ParsedSchema<
|
|
467
|
+
$parsed: ParsedSchema<
|
|
468
|
+
| SchemaTypeObjectContent
|
|
469
|
+
| SchemaTypeEnumContent
|
|
470
|
+
| SchemaTypePrimitiveContent
|
|
471
|
+
>;
|
|
428
472
|
};
|
|
429
473
|
componentName: "schemas" | "paths";
|
|
430
|
-
typeData: ParsedSchema<
|
|
474
|
+
typeData: ParsedSchema<
|
|
475
|
+
SchemaTypeObjectContent | SchemaTypeEnumContent | SchemaTypePrimitiveContent
|
|
476
|
+
> | null;
|
|
431
477
|
}
|
|
432
478
|
|
|
433
479
|
export enum RequestContentKind {
|
|
@@ -495,7 +541,10 @@ export enum SCHEMA_TYPES {
|
|
|
495
541
|
COMPLEX_UNKNOWN = "__unknown",
|
|
496
542
|
}
|
|
497
543
|
|
|
498
|
-
type MAIN_SCHEMA_TYPES =
|
|
544
|
+
type MAIN_SCHEMA_TYPES =
|
|
545
|
+
| SCHEMA_TYPES.PRIMITIVE
|
|
546
|
+
| SCHEMA_TYPES.OBJECT
|
|
547
|
+
| SCHEMA_TYPES.ENUM;
|
|
499
548
|
|
|
500
549
|
type ExtractingOptions = {
|
|
501
550
|
requestBodySuffix: string[];
|
|
@@ -505,13 +554,31 @@ type ExtractingOptions = {
|
|
|
505
554
|
enumSuffix: string[];
|
|
506
555
|
discriminatorMappingSuffix: string[];
|
|
507
556
|
discriminatorAbstractPrefix: string[];
|
|
508
|
-
requestBodyNameResolver: (
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
557
|
+
requestBodyNameResolver: (
|
|
558
|
+
name: string,
|
|
559
|
+
reservedNames: string,
|
|
560
|
+
) => string | undefined;
|
|
561
|
+
responseBodyNameResolver: (
|
|
562
|
+
name: string,
|
|
563
|
+
reservedNames: string,
|
|
564
|
+
) => string | undefined;
|
|
565
|
+
responseErrorNameResolver: (
|
|
566
|
+
name: string,
|
|
567
|
+
reservedNames: string,
|
|
568
|
+
) => string | undefined;
|
|
569
|
+
requestParamsNameResolver: (
|
|
570
|
+
name: string,
|
|
571
|
+
reservedNames: string,
|
|
572
|
+
) => string | undefined;
|
|
512
573
|
enumNameResolver: (name: string, reservedNames: string) => string | undefined;
|
|
513
|
-
discriminatorMappingNameResolver: (
|
|
514
|
-
|
|
574
|
+
discriminatorMappingNameResolver: (
|
|
575
|
+
name: string,
|
|
576
|
+
reservedNames: string,
|
|
577
|
+
) => string | undefined;
|
|
578
|
+
discriminatorAbstractResolver: (
|
|
579
|
+
name: string,
|
|
580
|
+
reservedNames: string,
|
|
581
|
+
) => string | undefined;
|
|
515
582
|
};
|
|
516
583
|
|
|
517
584
|
export interface GenerateApiConfiguration {
|
|
@@ -588,7 +655,9 @@ export interface GenerateApiConfiguration {
|
|
|
588
655
|
typeNameResolverName: string;
|
|
589
656
|
specificArgNameResolverName: string;
|
|
590
657
|
/** do not use constructor args, it can break functionality of this property, just send class reference */
|
|
591
|
-
customTranslator?: new (
|
|
658
|
+
customTranslator?: new (
|
|
659
|
+
...args: never[]
|
|
660
|
+
) => typeof import("./src/translators/translator").Translator;
|
|
592
661
|
internalTemplateOptions: {
|
|
593
662
|
addUtilRequiredKeysType: boolean;
|
|
594
663
|
};
|
|
@@ -613,7 +682,7 @@ export interface GenerateApiConfiguration {
|
|
|
613
682
|
};
|
|
614
683
|
routeNameDuplicatesMap: Map<string, string>;
|
|
615
684
|
apiClassName: string;
|
|
616
|
-
requestOptions?:
|
|
685
|
+
requestOptions?: RequestInit;
|
|
617
686
|
extractingOptions: ExtractingOptions;
|
|
618
687
|
};
|
|
619
688
|
modelTypes: ModelType[];
|
|
@@ -628,23 +697,35 @@ export interface GenerateApiConfiguration {
|
|
|
628
697
|
routes: ParsedRoute[];
|
|
629
698
|
}[];
|
|
630
699
|
};
|
|
631
|
-
requestOptions?: null | Partial<
|
|
700
|
+
requestOptions?: null | Partial<RequestInit>;
|
|
632
701
|
utils: {
|
|
633
702
|
formatDescription: (description: string, inline?: boolean) => string;
|
|
634
703
|
internalCase: (value: string) => string;
|
|
635
704
|
/** @deprecated */
|
|
636
705
|
classNameCase: (value: string) => string;
|
|
637
706
|
pascalCase: (value: string) => string;
|
|
638
|
-
getInlineParseContent: (
|
|
639
|
-
|
|
707
|
+
getInlineParseContent: (
|
|
708
|
+
rawTypeData: SchemaComponent["rawTypeData"],
|
|
709
|
+
typeName?: string,
|
|
710
|
+
) => string;
|
|
711
|
+
getParseContent: (
|
|
712
|
+
rawTypeData: SchemaComponent["rawTypeData"],
|
|
713
|
+
typeName?: string,
|
|
714
|
+
) => ModelType;
|
|
640
715
|
getComponentByRef: (ref: string) => SchemaComponent;
|
|
641
716
|
parseSchema: (
|
|
642
717
|
rawSchema: string | SchemaComponent["rawTypeData"],
|
|
643
718
|
typeName?: string,
|
|
644
719
|
formattersMap?: Record<MAIN_SCHEMA_TYPES, (content: ModelType) => string>,
|
|
645
720
|
) => ModelType;
|
|
646
|
-
formatters: Record<
|
|
647
|
-
|
|
721
|
+
formatters: Record<
|
|
722
|
+
MAIN_SCHEMA_TYPES,
|
|
723
|
+
(content: string | object | string[] | object[]) => string
|
|
724
|
+
>;
|
|
725
|
+
inlineExtraFormatters: Record<
|
|
726
|
+
Exclude<MAIN_SCHEMA_TYPES, SCHEMA_TYPES.PRIMITIVE>,
|
|
727
|
+
(schema: ModelType) => string
|
|
728
|
+
>;
|
|
648
729
|
formatModelName: (name: string) => string;
|
|
649
730
|
fmtToJSDocLine: (line: string, params?: { eol?: boolean }) => string;
|
|
650
731
|
_: import("lodash").LoDashStatic;
|
|
@@ -664,17 +745,28 @@ type FileInfo = {
|
|
|
664
745
|
export interface GenerateApiOutput {
|
|
665
746
|
configuration: GenerateApiConfiguration;
|
|
666
747
|
files: FileInfo[];
|
|
667
|
-
createFile: (params: {
|
|
748
|
+
createFile: (params: {
|
|
749
|
+
path: string;
|
|
750
|
+
fileName: string;
|
|
751
|
+
content: string;
|
|
752
|
+
withPrefix?: boolean;
|
|
753
|
+
}) => void;
|
|
668
754
|
renderTemplate: (
|
|
669
755
|
templateContent: string,
|
|
670
756
|
data: Record<string, unknown>,
|
|
671
757
|
etaOptions?: import("eta/dist/types/config").PartialConfig,
|
|
672
758
|
) => string;
|
|
673
|
-
getTemplate: (params: {
|
|
759
|
+
getTemplate: (params: {
|
|
760
|
+
fileName?: string;
|
|
761
|
+
name?: string;
|
|
762
|
+
path?: string;
|
|
763
|
+
}) => string;
|
|
674
764
|
formatTSContent: (content: string) => Promise<string>;
|
|
675
765
|
}
|
|
676
766
|
|
|
677
|
-
export declare function generateApi(
|
|
767
|
+
export declare function generateApi(
|
|
768
|
+
params: GenerateApiParams,
|
|
769
|
+
): Promise<GenerateApiOutput>;
|
|
678
770
|
|
|
679
771
|
export interface GenerateTemplatesParams {
|
|
680
772
|
cleanOutput?: boolean;
|
|
@@ -684,6 +776,9 @@ export interface GenerateTemplatesParams {
|
|
|
684
776
|
silent?: boolean;
|
|
685
777
|
}
|
|
686
778
|
|
|
687
|
-
export interface GenerateTemplatesOutput
|
|
779
|
+
export interface GenerateTemplatesOutput
|
|
780
|
+
extends Pick<GenerateApiOutput, "files" | "createFile"> {}
|
|
688
781
|
|
|
689
|
-
export declare function generateTemplates(
|
|
782
|
+
export declare function generateTemplates(
|
|
783
|
+
params: GenerateTemplatesParams,
|
|
784
|
+
): Promise<GenerateTemplatesOutput>;
|