Skip to content

Commit

Permalink
perf: 新增isCamelCase参数, 支持小驼峰命名或者默认命名 (#129)
Browse files Browse the repository at this point in the history
* perf: 新增isCamelCase参数, 支持小驼峰命名或者默认命名

* perf: 优化默认配置的书写位置
  • Loading branch information
rookie-luochao committed Nov 28, 2023
1 parent 2f34d85 commit d4bc159
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ npm run openapi
| enumStyle || 枚举样式 | string-literal \| enum | string-literal |
| nullable || 使用null代替可选 | boolean | false |
| dataFields || response中数据字段 | string[] | - |
| isCamelCase || 小驼峰命名文件和请求函数 | boolean | true |
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ export type GenerateServiceProps = {
* example: ['result', 'res']
*/
dataFields?: string[];

/**
* 模板文件、请求函数采用小驼峰命名
*/
isCamelCase?: boolean;
};

const converterSwaggerToOpenApi = (swagger: any) => {
Expand Down Expand Up @@ -191,6 +196,7 @@ export const generateService = async ({
requestImportStatement,
enumStyle: 'string-literal',
nullable,
isCamelCase: true,
...rest,
},
openAPI,
Expand Down
4 changes: 2 additions & 2 deletions src/serviceGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class ServiceGenerator {
}

tags.forEach((tagString) => {
const tag = camelCase(resolveTypeName(tagString));
const tag = this.config.isCamelCase ? camelCase(resolveTypeName(tagString)) : resolveTypeName(tagString);

if (!this.apiData[tag]) {
this.apiData[tag] = [];
Expand Down Expand Up @@ -531,7 +531,7 @@ class ServiceGenerator {

return {
...newApi,
functionName: camelCase(functionName),
functionName: this.config.isCamelCase ? camelCase(functionName) : functionName,
typeName: this.getTypeName(newApi),
path: getPrefixPath(),
pathInComment: formattedPath.replace(/\*/g, '*'),
Expand Down

0 comments on commit d4bc159

Please sign in to comment.