openapi-ts-request 0.10.0 → 0.11.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
@@ -6,6 +6,8 @@
6
6
 
7
7
  根据 [Swagger2/OpenAPI3](https://swagger.io/blog/news/whats-new-in-openapi-3-0/) 文档生成 TS 类型, 客户端请求函数, 模拟请求响应服务, 枚举, 类型字段翻译, JSON Schemas
8
8
 
9
+ 文档:[使用手册](https://github.com/openapi-ui/openapi-ts-request/issues/100)
10
+
9
11
  ## 功能
10
12
 
11
13
  - 支持 Swagger2.0/OpenAPI 3.0,3.1 定义
@@ -207,7 +209,7 @@ export declare function patchSchema<T extends object>(
207
209
 
208
210
  ## 适配uniapp
209
211
 
210
- 适配 uniapp 推荐采用自定义 request 函数的方式,你也可以使用 `@uni-helper/axios-adapter` 适配器,详情见 [issue#46](https://github.com/openapi-ui/openapi-ts-request/issues/46)
212
+ 适配 uniapp 推荐采用自定义 request 函数的方式,你也可以使用 `@uni-helper/axios-adapter` 适配器,详情见 [【使用手册 2.2】](https://github.com/openapi-ui/openapi-ts-request/issues/100)
211
213
 
212
214
  ## 贡献
213
215
 
@@ -145,7 +145,7 @@ class ServiceGenerator {
145
145
  if (!(0, lodash_1.isEmpty)((_a = this.config) === null || _a === void 0 ? void 0 : _a.allowedTags) &&
146
146
  !(0, lodash_1.isEmpty)(operationObject.tags)) {
147
147
  if (!(0, lodash_1.isEmpty)((0, lodash_1.intersection)(this.config.allowedTags, (0, lodash_1.map)(operationObject.tags, (tag) => tag.toLowerCase())))) {
148
- (0, util_1.markAllowSchema)(JSON.stringify(pathItem), schemas);
148
+ (0, util_1.markAllowedSchema)(JSON.stringify(pathItem), schemas);
149
149
  }
150
150
  else {
151
151
  return;
@@ -316,7 +316,7 @@ class ServiceGenerator {
316
316
  };
317
317
  return Object.assign(Object.assign({}, newApi), { functionName: this.config.isCamelCase
318
318
  ? (0, lodash_1.camelCase)(functionName)
319
- : functionName, typeName: this.getTypeName(newApi), path: getPrefixPath(), pathInComment: formattedPath.replace(/\*/g, '&#42;'), hasPathVariables: formattedPath.includes('{'), hasApiPrefix: !!this.config.apiPrefix, method: newApi.method,
319
+ : functionName, typeName: this.getTypeName(newApi), path: getPrefixPath(), pathInComment: formattedPath.replace(/\*/g, '&#42;'), apifoxRunLink: newApi === null || newApi === void 0 ? void 0 : newApi['x-run-in-apifox'], hasPathVariables: formattedPath.includes('{'), hasApiPrefix: !!this.config.apiPrefix, method: newApi.method,
320
320
  // 如果 functionName 和 summary 相同,则不显示 summary
321
321
  desc: functionName === newApi.summary
322
322
  ? (newApi.description || '').replace(config_1.lineBreakReg, '')
@@ -593,7 +593,7 @@ class ServiceGenerator {
593
593
  }
594
594
  resolveArray(schemaObject) {
595
595
  if ((0, util_1.isReferenceObject)(schemaObject.items)) {
596
- const refName = (0, util_1.getLastRefName)(schemaObject.items.$ref);
596
+ const refName = (0, util_1.getRefName)(schemaObject.items);
597
597
  return {
598
598
  type: `${refName}[]`,
599
599
  };
@@ -2,6 +2,7 @@ import { ArraySchemaObject, BinaryArraySchemaObject, ComponentsObject, ISchemaOb
2
2
  import { ITypeItem } from './type';
3
3
  export declare function stripDot(str: string): string;
4
4
  export declare function resolveTypeName(typeName: string): string;
5
+ export declare function getRefName(refObject: ReferenceObject | string): string;
5
6
  export declare function getLastRefName(refPath?: string): string;
6
7
  export declare function getDefaultType(schemaObject?: ISchemaObject | string, namespace?: string, schemas?: ComponentsObject['schemas']): string;
7
8
  export declare function getDefaultFileTag(operationObject: OperationObject, apiPath: string): string[];
@@ -11,7 +12,7 @@ export declare function genDefaultFunctionName(path: string, pathBasePrefix: str
11
12
  export declare function getFinalFileName(s: string): string;
12
13
  export declare function replaceDot(s: string): string;
13
14
  export declare function resolveFunctionName(functionName: string, methodName: string): string;
14
- export declare function markAllowSchema(schemaStr: string, schemas: ComponentsObject['schemas']): void;
15
+ export declare function markAllowedSchema(schemaStr: string, schemas: ComponentsObject['schemas']): void;
15
16
  export declare function isReferenceObject(schema: unknown): schema is ReferenceObject;
16
17
  export declare function isSchemaObject(schema: unknown): schema is SchemaObject;
17
18
  export declare function isNonArraySchemaObject(schema: unknown): schema is NonArraySchemaObject;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stripDot = stripDot;
4
4
  exports.resolveTypeName = resolveTypeName;
5
+ exports.getRefName = getRefName;
5
6
  exports.getLastRefName = getLastRefName;
6
7
  exports.getDefaultType = getDefaultType;
7
8
  exports.getDefaultFileTag = getDefaultFileTag;
@@ -11,7 +12,7 @@ exports.genDefaultFunctionName = genDefaultFunctionName;
11
12
  exports.getFinalFileName = getFinalFileName;
12
13
  exports.replaceDot = replaceDot;
13
14
  exports.resolveFunctionName = resolveFunctionName;
14
- exports.markAllowSchema = markAllowSchema;
15
+ exports.markAllowedSchema = markAllowedSchema;
15
16
  exports.isReferenceObject = isReferenceObject;
16
17
  exports.isSchemaObject = isSchemaObject;
17
18
  exports.isNonArraySchemaObject = isNonArraySchemaObject;
@@ -285,13 +286,13 @@ function resolveFunctionName(functionName, methodName) {
285
286
  return functionName;
286
287
  }
287
288
  // 标记引用的 $ref 对应的schema
288
- function markAllowSchema(schemaStr, schemas) {
289
+ function markAllowedSchema(schemaStr, schemas) {
289
290
  const refs = schemaStr === null || schemaStr === void 0 ? void 0 : schemaStr.match(/#\/components\/schemas\/([\w%«».-]+)/g);
290
291
  (0, lodash_1.forEach)(refs, (ref) => {
291
292
  const schema = schemas === null || schemas === void 0 ? void 0 : schemas[getLastRefName(ref)];
292
293
  if (schema && !schema.isAllowed) {
293
294
  schema.isAllowed = true;
294
- markAllowSchema(JSON.stringify(schema), schemas);
295
+ markAllowedSchema(JSON.stringify(schema), schemas);
295
296
  }
296
297
  });
297
298
  }
package/dist/type.d.ts CHANGED
@@ -31,7 +31,9 @@ export type PathItemObject = Modify<OpenAPIV3.PathItemObject, {
31
31
  }>;
32
32
  export type OperationObject = Modify<OpenAPIV3.OperationObject, {
33
33
  parameters?: (ReferenceObject | ParameterObject)[];
34
- }>;
34
+ }> & {
35
+ 'x-run-in-apifox'?: string;
36
+ };
35
37
  export type ComponentsObject = OpenAPIV3.ComponentsObject;
36
38
  export type OpenAPIObject = OpenAPIV3.Document;
37
39
  export type ParameterObject = Modify<OpenAPIV3.ParameterObject, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Swagger2/OpenAPI3 to TypeScript, request client, request mock service, enum, type field label, JSON Schemas",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",
@@ -4,7 +4,7 @@ import * as {{ namespace }} from './{{ interfaceFileName }}';
4
4
  {{ requestImportStatement }}
5
5
 
6
6
  {% for api in list -%}
7
- /** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
7
+ /** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{ api.method | upper }} {{ api.pathInComment | safe }}{{ ' ' if api.apifoxRunLink else '' }}{{ api.apifoxRunLink | safe }} */
8
8
  export async function {{ api.functionName }}(
9
9
  {%- if api.params and api.hasParams %}
10
10
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)