epam-cross-platform-lab / swagger-dart-code-generator

Swagger/OpenAPI code generator based on Chopper and JsonAnnotation for Flutter
Apache License 2.0
266 stars 124 forks source link

[BUG] duplicate method's name when generate model. #720

Open YeomDongUk opened 9 months ago

YeomDongUk commented 9 months ago

Describe the bug When generating Swagger models with property names that share the same prefix, such as "orderStatus" and "orderStatusList," where the latter ends with "List," it creates duplicate function names.

To Reproduce

스크린샷 2024-01-31 오전 11 21 06
String? searchOrderDtoRequestOrderStatusListToJson(
    enums.SearchOrderDtoRequestOrderStatusList? searchOrderDtoRequestOrderStatusList) {
  return searchOrderDtoRequestOrderStatusList?.value;
}

enums.SearchOrderDtoRequestOrderStatusList searchOrderDtoRequestOrderStatusListFromJson(
  Object? searchOrderDtoRequestOrderStatusList, [
  enums.SearchOrderDtoRequestOrderStatusList? defaultValue,
]) {
  return enums.SearchOrderDtoRequestOrderStatusList.values.firstWhereOrNull(
          (e) => e.value.toString().toLowerCase() == searchOrderDtoRequestOrderStatusList?.toString().toLowerCase()) ??
      defaultValue ??
      enums.SearchOrderDtoRequestOrderStatusList.swaggerGeneratedUnknown;
}

List<String> searchOrderDtoRequestOrderStatusListToJson(
    List<enums.SearchOrderDtoRequestOrderStatus>? searchOrderDtoRequestOrderStatus) {
  if (searchOrderDtoRequestOrderStatus == null) {
    return [];
  }

  return searchOrderDtoRequestOrderStatus.map((e) => e.value!).toList();
}

List<enums.SearchOrderDtoRequestOrderStatus> searchOrderDtoRequestOrderStatusListFromJson(
  List? searchOrderDtoRequestOrderStatus, [
  List<enums.SearchOrderDtoRequestOrderStatus>? defaultValue,
]) {
  if (searchOrderDtoRequestOrderStatus == null) {
    return defaultValue ?? [];
  }

  return searchOrderDtoRequestOrderStatus.map((e) => searchOrderDtoRequestOrderStatusFromJson(e.toString())).toList();
}

Expected behavior

Does not generate duplicate function names.

Swagger specification link I can't provide it because it's within the internal network.

Library version used: swagger_dart_code_generator: 2.11.11

Vovanella95 commented 8 months ago

Hi @YeomDongUk , can you provide swagger file with such issue?