Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/red-cups-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openapi-ts-request': patch
---

perf: typeName upperFist
12 changes: 8 additions & 4 deletions src/generator/serviceGenarator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isFunction,
isObject,
keys,
lowerFirst,
map,
upperFirst,
} from 'lodash';
Expand Down Expand Up @@ -238,9 +239,10 @@ export default class ServiceGenerator {
}
}

const tagTypeName = resolveTypeName(tag);
const tagKey = this.config.isCamelCase
? camelCase(resolveTypeName(tag))
: resolveTypeName(tag);
? camelCase(tagTypeName)
: lowerFirst(tagTypeName);

if (!this.apiData[tagKey]) {
this.apiData[tagKey] = [];
Expand Down Expand Up @@ -610,7 +612,7 @@ export default class ServiceGenerator {

if (this.config.isGenJsonSchemas) {
this.schemaList.push({
typeName: `$${resolveTypeName(schemaKey)}`,
typeName: `$${lowerFirst(resolveTypeName(schemaKey))}`,
type: JSON.stringify(
patchSchema<SchemaObject>(
schema,
Expand Down Expand Up @@ -933,7 +935,9 @@ export default class ServiceGenerator {
const typeName =
this.config?.hook?.customTypeName?.(data) || this.getFunctionName(data);

return resolveTypeName(`${namespace}${typeName ?? data.operationId}Params`);
return upperFirst(
resolveTypeName(`${namespace}${typeName ?? data.operationId}Params`)
);
}

private getBodyTP(requestBody: RequestBodyObject, namespace?: string) {
Expand Down
5 changes: 3 additions & 2 deletions src/generator/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
isUndefined,
keys,
map,
upperFirst,
} from 'lodash';
import ReservedDict from 'reserved-words';
import pinyin from 'tiny-pinyin';
Expand Down Expand Up @@ -97,12 +98,12 @@ export function resolveTypeName(typeName: string) {
}

if (!/[\u3220-\uFA29]/.test(name) && !/^\d$/.test(name)) {
return name;
return upperFirst(name);
}

const noBlankName = name.replace(/ +/g, '');

return pinyin.convertToPinyin(noBlankName, '', true);
return upperFirst(pinyin.convertToPinyin(noBlankName, '', true));
}

export function getRefName(refObject: ReferenceObject | string) {
Expand Down
48 changes: 24 additions & 24 deletions test/__snapshots__/common/小驼峰命名文件和请求函数.snap
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export async function petPetIdUsingGet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.petPetIdUsingGetParams;
params: API.PetPetIdUsingGetParams;
options?: { [key: string]: unknown };
}) {
const { petId: param0, ...queryParams } = params;
Expand All @@ -85,7 +85,7 @@ export async function petPetIdUsingPost({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.petPetIdUsingPostParams;
params: API.PetPetIdUsingPostParams;
options?: { [key: string]: unknown };
}) {
const { petId: param0, ...queryParams } = params;
Expand All @@ -105,7 +105,7 @@ export async function petPetIdUsingDelete({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.petPetIdUsingDeleteParams;
params: API.PetPetIdUsingDeleteParams;
options?: { [key: string]: unknown };
}) {
const { petId: param0, ...queryParams } = params;
Expand All @@ -124,7 +124,7 @@ export async function petPetIdUploadImageUsingPost({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.petPetIdUploadImageUsingPostParams;
params: API.PetPetIdUploadImageUsingPostParams;
body: API.PetPetIdUploadImageUsingPostBody;
options?: { [key: string]: unknown };
}) {
Expand All @@ -149,7 +149,7 @@ export async function petFindByStatusUsingGet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.petFindByStatusUsingGetParams;
params: API.PetFindByStatusUsingGetParams;
options?: { [key: string]: unknown };
}) {
return request<API.Pet[]>('/pet/findByStatus', {
Expand All @@ -169,7 +169,7 @@ export async function petFindByTagsUsingGet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.petFindByTagsUsingGetParams;
params: API.PetFindByTagsUsingGetParams;
options?: { [key: string]: unknown };
}) {
return request<API.Pet[]>('/pet/findByTags', {
Expand Down Expand Up @@ -222,7 +222,7 @@ export async function storeOrderOrderIdUsingGet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.storeOrderOrderIdUsingGetParams;
params: API.StoreOrderOrderIdUsingGetParams;
options?: { [key: string]: unknown };
}) {
const { orderId: param0, ...queryParams } = params;
Expand All @@ -240,7 +240,7 @@ export async function storeOrderOrderIdUsingDelete({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.storeOrderOrderIdUsingDeleteParams;
params: API.StoreOrderOrderIdUsingDeleteParams;
options?: { [key: string]: unknown };
}) {
const { orderId: param0, ...queryParams } = params;
Expand Down Expand Up @@ -285,36 +285,36 @@ export type Pet = {
status?: 'available' | 'pending' | 'sold';
};

export type petFindByStatusUsingGetParams = {
export type PetFindByStatusUsingGetParams = {
/** Status values that need to be considered for filter */
status?: 'available' | 'pending' | 'sold';
};

export type petFindByTagsUsingGetParams = {
export type PetFindByTagsUsingGetParams = {
/** Tags to filter by */
tags?: string[];
};

export type PetPetIdUploadImageUsingPostBody = string;

export type petPetIdUploadImageUsingPostParams = {
export type PetPetIdUploadImageUsingPostParams = {
/** ID of pet to update */
petId: number;
/** Additional Metadata */
additionalMetadata?: string;
};

export type petPetIdUsingDeleteParams = {
export type PetPetIdUsingDeleteParams = {
/** Pet id to delete */
petId: number;
};

export type petPetIdUsingGetParams = {
export type PetPetIdUsingGetParams = {
/** ID of pet to return */
petId: number;
};

export type petPetIdUsingPostParams = {
export type PetPetIdUsingPostParams = {
/** ID of pet that needs to be updated */
petId: number;
/** Name of pet that needs to be updated */
Expand All @@ -339,12 +339,12 @@ export enum StatusEnum2 {

export type IStatusEnum2 = keyof typeof StatusEnum2;

export type storeOrderOrderIdUsingDeleteParams = {
export type StoreOrderOrderIdUsingDeleteParams = {
/** ID of the order that needs to be deleted */
orderId: number;
};

export type storeOrderOrderIdUsingGetParams = {
export type StoreOrderOrderIdUsingGetParams = {
/** ID of order that needs to be fetched */
orderId: number;
};
Expand All @@ -368,24 +368,24 @@ export type User = {

export type UserCreateWithListUsingPostBody = User[];

export type userLoginUsingGetParams = {
export type UserLoginUsingGetParams = {
/** The user name for login */
username?: string;
/** The password for login in clear text */
password?: string;
};

export type userUsernameUsingDeleteParams = {
export type UserUsernameUsingDeleteParams = {
/** The name that needs to be deleted */
username: string;
};

export type userUsernameUsingGetParams = {
export type UserUsernameUsingGetParams = {
/** The name that needs to be fetched. Use user1 for testing. */
username: string;
};

export type userUsernameUsingPutParams = {
export type UserUsernameUsingPutParams = {
/** name that needs to be updated */
username: string;
};
Expand Down Expand Up @@ -419,7 +419,7 @@ export async function userUsernameUsingGet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.userUsernameUsingGetParams;
params: API.UserUsernameUsingGetParams;
options?: { [key: string]: unknown };
}) {
const { username: param0, ...queryParams } = params;
Expand All @@ -438,7 +438,7 @@ export async function userUsernameUsingPut({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.userUsernameUsingPutParams;
params: API.UserUsernameUsingPutParams;
body: API.User;
options?: { [key: string]: unknown };
}) {
Expand All @@ -461,7 +461,7 @@ export async function userUsernameUsingDelete({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.userUsernameUsingDeleteParams;
params: API.UserUsernameUsingDeleteParams;
options?: { [key: string]: unknown };
}) {
const { username: param0, ...queryParams } = params;
Expand Down Expand Up @@ -497,7 +497,7 @@ export async function userLoginUsingGet({
options,
}: {
// 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
params: API.userLoginUsingGetParams;
params: API.UserLoginUsingGetParams;
options?: { [key: string]: unknown };
}) {
return request<string>('/user/login', {
Expand Down
Loading