openapi-ts-request 0.6.0 → 0.7.0

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 CHANGED
@@ -135,7 +135,7 @@ $ openapi --help
135
135
  -i, --input <string> OpenAPI specification, can be a path, url (required)
136
136
  -o, --output <string> output directory (required)
137
137
  --requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch", default is "axios"
138
- --allowedTags <string[]> generate results from allowed tags
138
+ --allowedTags <string[]> generate code from allowed tags
139
139
  --requestOptionsType <string> custom request method options parameter type (default: "{ [key:
140
140
  string]: unknown }")
141
141
  --requestImportStatement <string> custom request import statement, for example: "const request =
@@ -145,6 +145,7 @@ $ openapi --help
145
145
  --isDisplayTypeLabel <boolean> generate label matching type field (default: false)
146
146
  --isGenJsonSchemas <boolean> generate JSON Schemas (default: false)
147
147
  --mockFolder <string> mock file path
148
+ --authorization <string> docs authorization
148
149
  --nullable <boolean> null instead of optional (default: false)
149
150
  --isTranslateToEnglishTag <boolean>translate chinese tag name to english tag name (default: false)
150
151
  --isCamelCase <boolean> camelCase naming of controller files and request client (default: true)
@@ -164,13 +165,14 @@ openapi --i ./spec.json --o ./apis
164
165
  | schemaPath | 是 | string | - | Swagger2/OpenAPI3 地址 |
165
166
  | serversPath | 否 | string | './src/apis' | 生成结果的文件夹路径 |
166
167
  | requestLibPath | 否 | string | 'axios' | 自定义请求方法路径,例如:'@/request'、'node-fetch' |
167
- | allowedTags | 否 | string[] | - | 根据指定的 tags 生成结果 |
168
+ | allowedTags | 否 | string[] | - | 根据指定的 tags 生成代码 |
168
169
  | requestOptionsType | 否 | string | '{ [key: string]: unknown }' | 自定义请求方法 options 参数类型 |
169
170
  | requestImportStatement | 否 | string | - | 自定义请求方法表达式,例如:"const request = require('@/request')" |
170
171
  | apiPrefix | 否 | string | - | api path的前缀,例如:'api'(动态变量), "'api'"(字符串) |
171
172
  | isDisplayTypeLabel | 否 | boolean | false | 是否生成 type 对应的label |
172
173
  | isGenJsonSchemas | 否 | boolean | false | 是否生成 JSON Schemas |
173
174
  | mockFolder | 否 | string | './mocks' | mock文件路径 |
175
+ | authorization | 否 | string | - | 文档权限凭证 |
174
176
  | nullable | 否 | boolean | false | 使用 null 代替可选 |
175
177
  | isTranslateToEnglishTag | 否 | boolean | false | 将中文 tag 名称翻译成英文 tag 名称 |
176
178
  | isCamelCase | 否 | boolean | true | 小驼峰命名文件和请求函数 |
@@ -20,6 +20,7 @@ const params = commander_1.program
20
20
  .option('--isDisplayTypeLabel <boolean>', 'generate label matching type field', false)
21
21
  .option('--isGenJsonSchemas <boolean>', 'generate JSON Schemas', false)
22
22
  .option('--mockFolder <string>', 'mock file path')
23
+ .option('--authorization <string>', 'docs authorization')
23
24
  .option('--nullable <boolean>', 'null instead of optional', false)
24
25
  .option('--isTranslateToEnglishTag <boolean>', 'translate chinese tag name to english tag name', false)
25
26
  .option('--isCamelCase <boolean>', 'camelCase naming of controller files and request client', true)
@@ -47,6 +48,7 @@ function run() {
47
48
  isDisplayTypeLabel: JSON.parse(params.isDisplayTypeLabel) === true,
48
49
  isGenJsonSchemas: JSON.parse(params.isGenJsonSchemas) === true,
49
50
  mockFolder: params.mockFolder,
51
+ authorization: params.authorization,
50
52
  nullable: JSON.parse(params.nullable) === true,
51
53
  isTranslateToEnglishTag: JSON.parse(params.isTranslateToEnglishTag) === true,
52
54
  isCamelCase: JSON.parse(params.isCamelCase) === true,
package/dist/index.d.ts CHANGED
@@ -56,6 +56,10 @@ export type GenerateServiceProps = {
56
56
  * mock目录
57
57
  */
58
58
  mockFolder?: string;
59
+ /**
60
+ * 文档权限凭证
61
+ */
62
+ authorization?: string;
59
63
  /**
60
64
  * 默认为false,true时使用null代替可选值
61
65
  */
@@ -135,4 +139,4 @@ export type GenerateServiceProps = {
135
139
  customFileNames?: (operationObject: OperationObject, apiPath: string, apiMethod: string) => string[] | null;
136
140
  };
137
141
  };
138
- export declare function generateService({ requestLibPath, schemaPath, mockFolder, allowedTags, isTranslateToEnglishTag, ...rest }: GenerateServiceProps): Promise<void>;
142
+ export declare function generateService({ requestLibPath, schemaPath, mockFolder, allowedTags, authorization, isTranslateToEnglishTag, ...rest }: GenerateServiceProps): Promise<void>;
package/dist/index.js CHANGED
@@ -9,11 +9,11 @@ const util_1 = require("./util");
9
9
  tslib_1.__exportStar(require("./generator/patchSchema"), exports);
10
10
  function generateService(_a) {
11
11
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- var { requestLibPath, schemaPath, mockFolder, allowedTags, isTranslateToEnglishTag } = _a, rest = tslib_1.__rest(_a, ["requestLibPath", "schemaPath", "mockFolder", "allowedTags", "isTranslateToEnglishTag"]);
12
+ var { requestLibPath, schemaPath, mockFolder, allowedTags, authorization, isTranslateToEnglishTag } = _a, rest = tslib_1.__rest(_a, ["requestLibPath", "schemaPath", "mockFolder", "allowedTags", "authorization", "isTranslateToEnglishTag"]);
13
13
  if (!schemaPath) {
14
14
  return;
15
15
  }
16
- const openAPI = (yield (0, util_1.getOpenAPIConfig)(schemaPath));
16
+ const openAPI = (yield (0, util_1.getOpenAPIConfig)(schemaPath, authorization));
17
17
  if ((0, lodash_1.isEmpty)(openAPI)) {
18
18
  return;
19
19
  }
package/dist/util.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { OpenAPI } from 'openapi-types';
2
2
  import { OpenAPIObject } from './type';
3
3
  export declare const getImportStatement: (requestLibPath: string) => string;
4
- export declare const getOpenAPIConfig: (schemaPath: string) => Promise<OpenAPI.Document<{}>>;
4
+ export declare const getOpenAPIConfig: (schemaPath: string, authorization?: string) => Promise<OpenAPI.Document<{}>>;
5
5
  export declare function parseSwaggerOrOpenapi(content: string | OpenAPI.Document): Promise<OpenAPI.Document<{}>>;
6
6
  export declare function translateChineseModuleNodeToEnglish(openAPI: OpenAPIObject): Promise<unknown>;
package/dist/util.js CHANGED
@@ -23,7 +23,7 @@ const getImportStatement = (requestLibPath) => {
23
23
  return `import request from 'axios';`;
24
24
  };
25
25
  exports.getImportStatement = getImportStatement;
26
- function getSchema(schemaPath) {
26
+ function getSchema(schemaPath, authorization) {
27
27
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
28
28
  if (schemaPath.startsWith('http')) {
29
29
  const isHttps = schemaPath.startsWith('https:');
@@ -34,7 +34,7 @@ function getSchema(schemaPath) {
34
34
  });
35
35
  const config = isHttps ? { httpsAgent: agent } : { httpAgent: agent };
36
36
  const json = yield axios_1.default
37
- .get(schemaPath, config)
37
+ .get(schemaPath, Object.assign(Object.assign({}, config), { headers: { authorization } }))
38
38
  .then((res) => res.data);
39
39
  return json;
40
40
  }
@@ -80,8 +80,8 @@ function converterSwaggerToOpenApi(swagger) {
80
80
  });
81
81
  });
82
82
  }
83
- const getOpenAPIConfig = (schemaPath) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
84
- const schema = yield getSchema(schemaPath);
83
+ const getOpenAPIConfig = (schemaPath, authorization) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
84
+ const schema = yield getSchema(schemaPath, authorization);
85
85
  if (!schema) {
86
86
  return;
87
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
5
5
  "repository": {
6
6
  "type": "git",