open-api-typescript-request-generator 0.0.1-alpha.2 → 0.0.2

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/lib/helpers.js CHANGED
@@ -186,13 +186,7 @@ function defineConfig(config) {
186
186
  var final = configs.map(function (item) {
187
187
  return __assign({
188
188
  serverUrl: '',
189
- typesOnly: false,
190
- target: 'typescript',
191
- outputFilePath: 'src/api',
192
- dataKey: 'data',
193
- jsonSchema: {
194
- enabled: false
195
- }
189
+ outputFilePath: 'src/api'
196
190
  }, item);
197
191
  });
198
192
  return final;
@@ -187,7 +187,7 @@ var runner = function runner(path, data, jsonSchema) {
187
187
  exports.runner = runner;
188
188
 
189
189
  var jsonSchemeFileHeader = function jsonSchemeFileHeader() {
190
- return "\n import * as changeCase from 'change-case';\n import { JSONSchema4 } from 'api-ts-generator';\n\n /**\n * \u83B7\u53D6scheme\u7684key\n */\n export const jsonSchemeKey = function (path: string): string {\n const deeps = path.split('/');\n const names = deeps.splice(deeps.length - 4, deeps.length).join('_');\n return changeCase.camelCase(names);\n };\n\n export const typeStr = function (data: unknown): string {\n const type = typeof data;\n if (type === 'object' && data instanceof Array) {\n return 'array';\n }\n if (type === 'object' && data === null) {\n return 'null';\n }\n if (type === 'number') {\n return 'integer';\n }\n\n return type;\n };\n\n /**\n * \u68C0\u67E5\u5668\n */\n export const responseDataInspector = function (data: any, jsonScheme: JSONSchema4, key: any[] = ['data']): boolean {\n const { type, properties, items } = jsonScheme;\n\n if (type !== typeStr(data)) {\n console.warn(`->ResponseDataInspector\uFF1A${key.join('.')}\u4E0E\u7EA6\u5B9A\u7684\u7C7B\u578B\u4E0D\u7B26\uFF0C\u7C7B\u578B\uFF1A${type}\uFF0C\u8FD4\u56DE\u503C\uFF1A${data}`);\n return false;\n }\n if (type === 'object') {\n if (!properties || !Object.keys(properties).length) {\n return true;\n }\n return Object.keys(properties).every(k => responseDataInspector(data[k], properties[k], [...key, k]));\n }\n if (type === 'array') {\n if (items === undefined) {\n // undefined\u5219\u4E3A\u63A5\u53D7\u4EFB\u610F\u7C7B\u578B\n return true;\n }\n if (items instanceof Array) {\n return (data as Array<any>).some(v => items.every(item => responseDataInspector(v, item)));\n }\n if (items instanceof Object) {\n return (data as Array<any>).every((v, index) => responseDataInspector(v, items, [...key, index]));\n }\n }\n\n return true;\n };\n\n export const runner = function (path: string, data: any, jsonSchema: Record<string, any>): void {\n const key = jsonSchemeKey(path);\n responseDataInspector(data, jsonSchema[key]);\n };\n ";
190
+ return "\n import * as changeCase from 'change-case';\n import { JSONSchema4 } from 'open-api-typescript-request-generator';\n\n /**\n * \u83B7\u53D6scheme\u7684key\n */\n export const jsonSchemeKey = function (path: string): string {\n const deeps = path.split('/');\n const names = deeps.splice(deeps.length - 4, deeps.length).join('_');\n return changeCase.camelCase(names);\n };\n\n export const typeStr = function (data: unknown): string {\n const type = typeof data;\n if (type === 'object' && data instanceof Array) {\n return 'array';\n }\n if (type === 'object' && data === null) {\n return 'null';\n }\n if (type === 'number') {\n return 'integer';\n }\n\n return type;\n };\n\n /**\n * \u68C0\u67E5\u5668\n */\n export const responseDataInspector = function (data: any, jsonScheme: JSONSchema4, key: any[] = ['data']): boolean {\n const { type, properties, items } = jsonScheme;\n\n if (type !== typeStr(data)) {\n console.warn(`->ResponseDataInspector\uFF1A${key.join('.')}\u4E0E\u7EA6\u5B9A\u7684\u7C7B\u578B\u4E0D\u7B26\uFF0C\u7C7B\u578B\uFF1A${type}\uFF0C\u8FD4\u56DE\u503C\uFF1A${data}`);\n return false;\n }\n if (type === 'object') {\n if (!properties || !Object.keys(properties).length) {\n return true;\n }\n return Object.keys(properties).every(k => responseDataInspector(data[k], properties[k], [...key, k]));\n }\n if (type === 'array') {\n if (items === undefined) {\n // undefined\u5219\u4E3A\u63A5\u53D7\u4EFB\u610F\u7C7B\u578B\n return true;\n }\n if (items instanceof Array) {\n return (data as Array<any>).some(v => items.every(item => responseDataInspector(v, item)));\n }\n if (items instanceof Object) {\n return (data as Array<any>).every((v, index) => responseDataInspector(v, items, [...key, index]));\n }\n }\n\n return true;\n };\n\n export const runner = function (path: string, data: any, jsonSchema: Record<string, any>): void {\n const key = jsonSchemeKey(path);\n responseDataInspector(data, jsonSchema[key]);\n };\n ";
191
191
  };
192
192
 
193
193
  exports.jsonSchemeFileHeader = jsonSchemeFileHeader;
package/lib/types.d.ts CHANGED
@@ -7,11 +7,7 @@ import { ParsedPath } from 'path';
7
7
  export declare type requestFunctionTemplateType = (props: RequestFunctionTemplateProps, config?: SyntheticalConfig) => string;
8
8
  /** 顶部依赖生成模板函数 */
9
9
  /** 生成器参数 */
10
- export declare type topImportPkgTemplateType = () => string;
11
- export interface GenTemplateType {
12
- requestFunctionTemplate?: requestFunctionTemplateType;
13
- topImportPkgTemplate?: topImportPkgTemplateType;
14
- }
10
+ export declare type topImportTemplateType = () => string;
15
11
  export interface GeneratorOptions {
16
12
  cwd: string;
17
13
  }
@@ -314,29 +310,6 @@ export interface ExtendedInterface extends Interface {
314
310
  }
315
311
  /** 分类列表,对应数据导出的 json 内容 */
316
312
  export declare type CategoryList = Category[];
317
- /** 支持生成 React Hooks 代码的相关配置 */
318
- export interface ReactHooksConfig {
319
- /**
320
- * 是否开启该项功能。
321
- */
322
- enabled: boolean;
323
- /**
324
- * 请求 Hook 函数制造者文件路径。
325
- *
326
- * @default 与 `outputFilePath` 同级目录下的 `makeRequestHook.ts` 文件
327
- * @example 'src/api/makeRequestHook.ts'
328
- */
329
- requestHookMakerFilePath?: string;
330
- /**
331
- * 获取请求 Hook 的名称。
332
- *
333
- * @default `use${changeCase.pascalCase(requestFunctionName)}`
334
- * @param interfaceInfo 接口信息
335
- * @param changeCase 常用的大小写转换函数集合对象
336
- * @returns 请求 Hook 的名称
337
- */
338
- getRequestHookName?(interfaceInfo: ExtendedInterface, changeCase: ChangeCase): string;
339
- }
340
313
  /** 支持生成 JSON Schema 的相关配置 */
341
314
  export interface JsonSchemaConfig {
342
315
  /**
@@ -393,29 +366,6 @@ export interface CommentConfig {
393
366
  * 共享的配置。
394
367
  */
395
368
  export interface SharedConfig {
396
- /**
397
- * 要生成的目标代码类型。
398
- * 默认为 `typescript`,若设为 `javascript`,会将生成的 `.ts` 文件转换为 `.js` + `.d.ts` 文件并删除原 `.ts` 文件。
399
- *
400
- * @default 'typescript'
401
- */
402
- target?: 'typescript' | 'javascript';
403
- /**
404
- * 是否只生成接口请求内容和返回内容的 TypeSript 类型,是则请求文件和请求函数都不会生成。
405
- *
406
- * @default false
407
- */
408
- typesOnly?: boolean;
409
- /**
410
- * 测试环境名称。
411
- *
412
- * **用于获取测试环境域名。**
413
- *
414
- * 获取方式:打开项目 --> `设置` --> `环境配置` --> 点开或新增测试环境 --> 复制测试环境名称。
415
- *
416
- * @example 'dev'
417
- */
418
- devEnvName?: string;
419
369
  /**
420
370
  * 输出文件路径。
421
371
  *
@@ -431,22 +381,6 @@ export interface SharedConfig {
431
381
  * @example 'src/api/request.ts'
432
382
  */
433
383
  requestFunctionFilePath?: string;
434
- /**
435
- * 如果接口响应的结果是 `JSON` 对象,
436
- * 且我们想要的数据在该对象下,
437
- * 那我们就可将 `dataKey` 设为我们想要的数据对应的键。
438
- *
439
- * 比如该对象为 `{ code: 0, msg: '成功', data: 100 }`,
440
- * 我们想要的数据为 `100`,
441
- * 则我们可将 `dataKey` 设为 `data`。
442
- *
443
- * @example 'data'
444
- */
445
- dataKey?: string;
446
- /**
447
- * 支持生成 React Hooks 代码的相关配置。
448
- */
449
- reactHooks?: ReactHooksConfig;
450
384
  /**
451
385
  * 支持生成 JSON Schema 的相关配置。
452
386
  */
@@ -454,21 +388,6 @@ export interface SharedConfig {
454
388
  * 支持生成注释的相关配置。
455
389
  */
456
390
  comment?: CommentConfig;
457
- /**
458
- * 预处理接口信息,返回新的接口信息。可返回 false 排除当前接口。
459
- *
460
- * 譬如你想对接口的 `path` 进行某些处理或者想排除某些接口,就可使用该方法。
461
- *
462
- * @example
463
- *
464
- * ```js
465
- * interfaceInfo => {
466
- * interfaceInfo.path = interfaceInfo.path.replace('v1', 'v2')
467
- * return interfaceInfo
468
- * }
469
- * ```
470
- */
471
- preproccessInterface?(interfaceInfo: Interface, changeCase: ChangeCase): Interface | false;
472
391
  /**
473
392
  * 获取请求函数的名称。
474
393
  *
@@ -497,116 +416,26 @@ export interface SharedConfig {
497
416
  */
498
417
  getResponseDataTypeName?(interfaceInfo: ExtendedInterface, changeCase: ChangeCase): string;
499
418
  }
500
- /**
501
- * 分类的配置。
502
- */
503
- export interface CategoryConfig extends SharedConfig {
504
- /**
505
- * 分类 ID。
506
- *
507
- * 获取方式:打开项目 --> 点开分类 --> 复制浏览器地址栏 `/api/cat_` 后面的数字。
508
- *
509
- * @example 20
510
- */
511
- id: number;
512
- /**
513
- * 过滤接口
514
- */
515
- filter?: ((path: string, id?: number) => boolean) | RegExp | string[];
516
- }
517
- export interface TokenNeed {
518
- /**
519
- * 项目id,与token等效,二选一
520
- *
521
- * 获取方式:打开项目 --> `设置` --> `项目配置` --> 项目ID。
522
- *
523
- * @example '123'
524
- */
525
- projectId?: number;
526
- /**
527
- * 项目的token,与projectId等效,二选一
528
- *
529
- * 获取方式:打开项目 --> `设置` --> `token配置` --> 复制 token。
530
- *
531
- * @example 'e02a47122259d0c1973a9ff81cabb30685d64abc72f39edaa1ac6b6a792a647d'
532
- */
533
- token: string;
534
- }
535
- export interface ProjectIdNeed {
536
- /**
537
- * 项目id,与token等效,二选一
538
- *
539
- * 获取方式:打开项目 --> `设置` --> `项目配置` --> 项目ID。
540
- *
541
- * @example '123'
542
- */
543
- projectId: number;
544
- /**
545
- * 项目的token,与projectId等效,二选一
546
- *
547
- * 获取方式:打开项目 --> `设置` --> `token配置` --> 复制 token。
548
- *
549
- * @example 'e02a47122259d0c1973a9ff81cabb30685d64abc72f39edaa1ac6b6a792a647d'
550
- */
551
- token?: string;
552
- }
553
- /**
554
- * 项目的配置。
555
- */
556
- export declare type ProjectConfig = SharedConfig & (ProjectIdNeed | TokenNeed) & {
557
- /**
558
- * 设置接口的baseURL
559
- *
560
- * @description 若要配置使用运行时代码,则增加`[code]:`前缀
561
- ```
562
- 例:
563
- baseURL: "[code]:process.env.BASE_URL" => baseURL:process.env.BASE_URL
564
-
565
- baseURL: "process.env.BASE_URL" => baseURL:"process.env.BASE_URL"
566
- ```
567
- */
568
- baseURL?: ((path: string) => string | undefined) | string;
569
- /**
570
- * 分类列表。
571
- */
572
- categories?: CategoryConfig[];
573
- };
574
419
  /**
575
420
  * 服务器的配置。
576
421
  */
577
- export interface ServerConfig extends SharedConfig, GenTemplateType {
578
- name?: string;
422
+ export interface ApiConfig {
423
+ name: string;
579
424
  configIndex?: number;
580
425
  /**
581
- * 服务地址。若服务类型为 `yapi`,此处填其首页地址;若服务类型为 `swagger`,此处填其 json 地址。
426
+ * 服务地址。此处填其 swagger json 地址。
427
+ * 比如nestjs项目一般为http://localhost:3041/api-json
582
428
  *
583
429
  */
584
430
  serverUrl: string;
585
431
  /**
586
- * 项目列表。
587
- */
588
- project?: ProjectConfig;
589
- /**
590
- * prettier代码格式化配置文件的路径
432
+ * 输出文件路径。
591
433
  *
592
- * @default process.cwd()
593
- */
594
- prettierConfigPath?: string;
595
- /**
596
- * 是否使用默认请求库,关闭后不再生成request.ts
597
- */
598
- defaultRequestLib?: boolean;
599
- /**
600
- * 代理请求模式,所有请求均请求到指定接口
434
+ * 可以是 `相对路径` 或 `绝对路径`。
435
+ *
436
+ * @example 'src/api/index.ts'
601
437
  */
602
- proxyInterface?: {
603
- /**
604
- * 代理接口
605
- *
606
- * @default /admin-interface/proxy/v0/proxy
607
- */
608
- path?: string;
609
- };
438
+ outputFilePath?: string;
610
439
  /**
611
440
  * 设置接口的baseURL
612
441
  *
@@ -615,50 +444,31 @@ export interface ServerConfig extends SharedConfig, GenTemplateType {
615
444
  例:
616
445
  baseURL: "[code]:process.env.BASE_URL" => baseURL:process.env.BASE_URL
617
446
 
618
- baseURL: "process.env.BASE_URL" => baseURL:"process.env.BASE_URL"
447
+ baseURL: "http://localhost:3000" => baseURL:"http://localhost:3000"
619
448
  ```
620
449
  */
621
450
  baseURL?: ((path: string) => string | undefined) | string;
622
451
  /**
623
- * 过滤接口
452
+ * 在每个生成的api文件顶部定义一段代码
453
+ * 例如:引入自定义request函数
454
+ * default: import request from './request'
624
455
  */
625
- filter?: ((path: string, id?: number) => boolean) | RegExp | string[];
456
+ topImportTemplate?: topImportTemplateType;
626
457
  /**
627
- * yapi页面链接地址列表
628
- * 通过url分析出项目id,接口id,分类id
629
- *
630
- @example
631
- ```
632
- `/project/9/interface/api/43 => 项目id:9、接口id: 43`
633
- ```
634
- */
635
- yapiUrlList?: string | string[];
636
- /**
637
- * 请求函数是否需要extra入参
638
- *
639
- * @default false
458
+ * 是否使用默认请求库,关闭后不再生成request.ts
640
459
  */
641
- requestFunctionExtraParams?: boolean;
460
+ defaultRequestLib?: boolean;
642
461
  }
643
462
  /** 混合的配置。 */
644
- export declare type SyntheticalConfig = Partial<ServerConfig & ProjectConfig & CategoryConfig & {
645
- mockUrl: string;
646
- devUrl: string;
647
- prodUrl: string;
463
+ export declare type SyntheticalConfig = Partial<ApiConfig & {
648
464
  components: OpenAPIV3.Document['components'];
649
465
  }>;
650
466
  /** 配置。 */
651
- export declare type Config = ServerConfig;
467
+ export declare type Config = ApiConfig;
652
468
  /**
653
469
  * 请求配置。
654
470
  */
655
- export interface RequestConfig<MockUrl extends string = string, DevUrl extends string = string, ProdUrl extends string = string, Path extends string = string, DataKey extends string | undefined = string | undefined, ParamName extends string = string, QueryName extends string = string, RequestDataOptional extends boolean = boolean> {
656
- /** 接口 Mock 地址,结尾无 `/` */
657
- mockUrl: MockUrl;
658
- /** 接口测试环境地址,结尾无 `/` */
659
- devUrl: DevUrl;
660
- /** 接口生产环境地址,结尾无 `/` */
661
- prodUrl: ProdUrl;
471
+ export interface RequestConfig<Path extends string = string, ParamName extends string = string, QueryName extends string = string, RequestDataOptional extends boolean = boolean> {
662
472
  /** 接口路径,以 `/` 开头 */
663
473
  path: Path;
664
474
  /** 请求方法 */
@@ -669,8 +479,6 @@ export interface RequestConfig<MockUrl extends string = string, DevUrl extends s
669
479
  requestBodyType: RequestBodyType;
670
480
  /** 返回数据类型 */
671
481
  responseBodyType: ResponseBodyType;
672
- /** 数据所在键 */
673
- dataKey: DataKey;
674
482
  /** 路径参数的名称列表 */
675
483
  paramNames: ParamName[];
676
484
  /** 查询参数的名称列表 */
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import prettier from 'prettier';
2
- import { Interface, PropDefinitions, Config } from './types';
2
+ import { Interface, PropDefinitions } from './types';
3
3
  import { JSONSchema4 } from 'json-schema';
4
4
  /**
5
5
  * 抛出错误。
@@ -61,7 +61,7 @@ export declare function propDefinitionsToJsonSchema(propDefinitions: PropDefinit
61
61
  * 获取prettier配置
62
62
  * @returns
63
63
  */
64
- export declare function getPrettier(filePath?: string): prettier.Options;
64
+ export declare function getPrettier(): prettier.Options;
65
65
  export declare function preprocessSchema(schema: JSONSchema4): JSONSchema4;
66
66
  /**
67
67
  * 根据 JSONSchema 对象生产 TypeScript 类型定义。
@@ -72,7 +72,7 @@ export declare function preprocessSchema(schema: JSONSchema4): JSONSchema4;
72
72
  */
73
73
  export declare function jsonSchemaToTsCode(jsonSchema: JSONSchema4, typeName: string): Promise<string>;
74
74
  export declare function getRequestDataJsonSchema(interfaceInfo: Interface): JSONSchema4;
75
- export declare function getResponseDataJsonSchema(interfaceInfo: Interface, dataKey?: string): JSONSchema4;
75
+ export declare function getResponseDataJsonSchema(interfaceInfo: Interface): JSONSchema4;
76
76
  export declare function sortByWeights<T extends {
77
77
  weights: number[];
78
78
  }>(list: T[]): T[];
@@ -83,15 +83,9 @@ export declare function sortByWeights<T extends {
83
83
  * @returns
84
84
  * https://prettier.io/docs/en/options.html
85
85
  */
86
- export declare function formatContent(content: string, prettierConfigPath?: string): string;
86
+ export declare function formatContent(content: string): string;
87
87
  /**
88
88
  * 通用生成文件顶部注释
89
89
  * @returns
90
90
  */
91
91
  export declare function topNotesContent(): string;
92
- /**
93
- * filter处理函数
94
- * @param interfaceFilter
95
- * @returns
96
- */
97
- export declare const filterHandler: (interfaceFilter?: Config['filter']) => (path: string, id?: number) => boolean;
package/lib/utils.js CHANGED
@@ -180,7 +180,7 @@ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
180
180
  Object.defineProperty(exports, "__esModule", {
181
181
  value: true
182
182
  });
183
- exports.filterHandler = exports.topNotesContent = exports.formatContent = exports.sortByWeights = exports.getResponseDataJsonSchema = exports.getRequestDataJsonSchema = exports.jsonSchemaToTsCode = exports.preprocessSchema = exports.getPrettier = exports.propDefinitionsToJsonSchema = exports.mockjsTemplateToJsonSchema = exports.jsonToJsonSchema = exports.jsonSchemaStringToJsonSchema = exports.processJsonSchema = exports.getNormalizedRelativePath = exports.toUnixPath = exports.throwError = void 0;
183
+ exports.topNotesContent = exports.formatContent = exports.sortByWeights = exports.getResponseDataJsonSchema = exports.getRequestDataJsonSchema = exports.jsonSchemaToTsCode = exports.preprocessSchema = exports.getPrettier = exports.propDefinitionsToJsonSchema = exports.mockjsTemplateToJsonSchema = exports.jsonToJsonSchema = exports.jsonSchemaStringToJsonSchema = exports.processJsonSchema = exports.getNormalizedRelativePath = exports.toUnixPath = exports.throwError = void 0;
184
184
 
185
185
  var json5_1 = __importDefault(require("json5"));
186
186
 
@@ -427,13 +427,8 @@ exports.propDefinitionsToJsonSchema = propDefinitionsToJsonSchema;
427
427
  * @returns
428
428
  */
429
429
 
430
- function getPrettier(filePath) {
431
- // 从项目中获取prettier配置文件
432
- var configPath = prettier_1.default.resolveConfigFile.sync(filePath && path_1.default.resolve(filePath) || process.cwd());
433
- var config = configPath && prettier_1.default.resolveConfig.sync(configPath) || {};
434
- return config ? __assign({
435
- parser: 'babel-ts'
436
- }, config) : {
430
+ function getPrettier() {
431
+ return {
437
432
  printWidth: 120,
438
433
  tabWidth: 2,
439
434
  singleQuote: true,
@@ -678,7 +673,7 @@ function getRequestDataJsonSchema(interfaceInfo) {
678
673
 
679
674
  exports.getRequestDataJsonSchema = getRequestDataJsonSchema;
680
675
 
681
- function getResponseDataJsonSchema(interfaceInfo, dataKey) {
676
+ function getResponseDataJsonSchema(interfaceInfo) {
682
677
  var jsonSchema = {};
683
678
 
684
679
  switch (interfaceInfo.res_body_type) {
@@ -695,12 +690,6 @@ function getResponseDataJsonSchema(interfaceInfo, dataKey) {
695
690
  };
696
691
  break;
697
692
  }
698
- /* istanbul ignore if */
699
-
700
-
701
- if (dataKey && jsonSchema && jsonSchema.properties && jsonSchema.properties[dataKey]) {
702
- jsonSchema = jsonSchema.properties[dataKey];
703
- }
704
693
 
705
694
  return jsonSchema;
706
695
  }
@@ -738,9 +727,9 @@ exports.sortByWeights = sortByWeights;
738
727
  * https://prettier.io/docs/en/options.html
739
728
  */
740
729
 
741
- function formatContent(content, prettierConfigPath) {
730
+ function formatContent(content) {
742
731
  // 从项目中获取prettier配置文件
743
- var config = getPrettier(prettierConfigPath);
732
+ var config = getPrettier();
744
733
  var prettyOutputContent = prettier_1.default.format(content, config);
745
734
  return prettyOutputContent;
746
735
  }
@@ -752,32 +741,7 @@ exports.formatContent = formatContent;
752
741
  */
753
742
 
754
743
  function topNotesContent() {
755
- return "\n /**\n * Created By api-ts-generator\n */\n\n ";
744
+ return "\n /**\n * Created By open-api-typescript-request-generator\n */\n\n ";
756
745
  }
757
746
 
758
- exports.topNotesContent = topNotesContent;
759
- /**
760
- * filter处理函数
761
- * @param interfaceFilter
762
- * @returns
763
- */
764
-
765
- var filterHandler = function filterHandler(interfaceFilter) {
766
- return function (path, id) {
767
- if (interfaceFilter instanceof RegExp && !interfaceFilter.test(path)) {
768
- return false;
769
- }
770
-
771
- if (interfaceFilter instanceof Array && !interfaceFilter.includes(path)) {
772
- return false;
773
- }
774
-
775
- if (interfaceFilter instanceof Function && !interfaceFilter(path, id)) {
776
- return false;
777
- }
778
-
779
- return true;
780
- };
781
- };
782
-
783
- exports.filterHandler = filterHandler;
747
+ exports.topNotesContent = topNotesContent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "open-api-typescript-request-generator",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.2",
4
4
  "author": "zimv <zimudashiren@163.com>",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./es/index.js",
@@ -15,7 +15,8 @@
15
15
  "scripts": {
16
16
  "build": "father build",
17
17
  "gen": "rm -rf ./api & tsx test/gen.ts --type-check false gen",
18
- "init": "tsx watch test/gen.ts --type-check false init",
18
+ "gen:api-1": "tsx test/gen.ts --type-check false gen -n api-1",
19
+ "init": "tsx test/gen.ts --type-check false init",
19
20
  "publishOnly": "npm run build",
20
21
  "release": "npm run build && standard-version && git push --follow-tags origin master && npm publish",
21
22
  "requestTest": "tsx watch test/requestTest.ts --type-check false",
@@ -1,153 +0,0 @@
1
- /**
2
- * 获取yapi数据
3
- */
4
- import { Options } from 'got';
5
- import { CategoryList, Category, Project, SyntheticalConfig, Interface, BaseInterfaceInfo } from './types';
6
- import prompts from 'prompts';
7
- declare type ApiConfig = SyntheticalConfig & {
8
- method?: Options['method'];
9
- /** 异常了是否执行 `process.exit()` */
10
- errorExit?: boolean;
11
- };
12
- declare const inputs: readonly [{
13
- readonly type: "text";
14
- readonly name: "email";
15
- readonly message: "请输入yapi的邮箱账号";
16
- readonly validate: prompts.PrevCaller<"email", string | boolean>;
17
- }, {
18
- readonly type: "password";
19
- readonly name: "password";
20
- readonly message: "请输入密码";
21
- readonly validate: prompts.PrevCaller<"password", string | boolean>;
22
- }];
23
- declare type NameValueKey = typeof inputs[number]['name'];
24
- /**
25
- * 登录提示框,账号密码录入
26
- * @returns
27
- */
28
- export declare const loginPrompts: (serverUrl?: string) => Promise<{
29
- email: string;
30
- password: string;
31
- }>;
32
- export declare type LoginProps = {
33
- [k in NameValueKey]: string;
34
- };
35
- export declare type LoginResponseData = {
36
- email: string;
37
- role: string;
38
- study: boolean;
39
- type: string;
40
- uid: number;
41
- username: string;
42
- };
43
- declare type FetchApiData = {
44
- token?: string;
45
- [k: string]: any;
46
- };
47
- /**
48
- *
49
- * @param url 请求方法
50
- * @param query
51
- * @returns
52
- */
53
- export declare const fetchApi: <T>(path: string, data: FetchApiData, config?: ApiConfig) => Promise<T>;
54
- /**
55
- * 获取项目token
56
- */
57
- export declare const fetchToken: (id: number, config?: ApiConfig) => Promise<string>;
58
- /**
59
- * 获取项目基本信息 by id
60
- */
61
- export declare const fetchProjectById: (config: ApiConfig) => Promise<Project>;
62
- /**
63
- * 获取项目基本信息
64
- *
65
- */
66
- export declare const fetchProject: (config: ApiConfig) => Promise<Project>;
67
- /**
68
- * 通过导出接口获取项目下的所有接口 by id
69
- */
70
- export declare const fetchExportById: (config: ApiConfig) => Promise<Category[]>;
71
- /**
72
- * 通过导出接口获取项目下的所有接口
73
- */
74
- export declare const fetchExport: (config: ApiConfig) => Promise<Category[]>;
75
- /**
76
- * 获取所有接口 by id
77
- * @param param0
78
- * @returns
79
- */
80
- export declare const fetchInterfaceListById: (config: ApiConfig) => Promise<Category[]>;
81
- /**
82
- * 获取所有接口
83
- * @param param0
84
- * @returns
85
- */
86
- export declare const fetchInterfaceList: (config: ApiConfig) => Promise<Category[]>;
87
- /**
88
- * 获取项目信息 by id
89
- * @param config
90
- * @returns
91
- */
92
- export declare const fetchProjectInfoById: (config: ApiConfig) => Promise<{
93
- cats: CategoryList;
94
- getMockUrl: () => string;
95
- _id: number;
96
- name: string;
97
- desc: string; /** 异常了是否执行 `process.exit()` */
98
- basepath: string;
99
- tag: string[];
100
- env: {
101
- name: string;
102
- domain: string;
103
- }[];
104
- token?: string;
105
- cat: Category[];
106
- components?: object[];
107
- }>;
108
- /**
109
- * 获取项目信息
110
- * @param config
111
- * @returns
112
- */
113
- export declare const fetchProjectInfo: (config: ApiConfig) => Promise<{
114
- cats: CategoryList;
115
- getMockUrl: () => string;
116
- _id: number;
117
- name: string;
118
- desc: string; /** 异常了是否执行 `process.exit()` */
119
- basepath: string;
120
- tag: string[];
121
- env: {
122
- name: string;
123
- domain: string;
124
- }[];
125
- token?: string;
126
- cat: Category[];
127
- components?: object[];
128
- }>;
129
- /**
130
- * 获取单个接口信息 by id
131
- */
132
- export declare const fetchInterfaceById: (id: number, config?: ApiConfig) => Promise<Interface>;
133
- /**
134
- * 获取分类下的接口列表信息 by id
135
- */
136
- export declare const fetchCatInterfaceById: (catid: number, config?: ApiConfig) => Promise<BaseInterfaceInfo[]>;
137
- /**
138
- * 批量获取分类下的详细接口信息
139
- * @param categoryList
140
- * @param config
141
- * @returns
142
- */
143
- export declare const getInterfacesByCategoryIds: (categoryIds: number[], config?: ApiConfig) => Promise<Interface[]>;
144
- /**
145
- * 获取项目信息和接口
146
- * @param config
147
- * @returns
148
- */
149
- export declare const getProjectInfoAndInterfaces: (config: ApiConfig) => Promise<{
150
- projectInfo: Project;
151
- allInterfaceList: Category[];
152
- }>;
153
- export {};