Skip to content

Proxy Generator Incorrectly Replaces Specific Enum Type with Generic "enum" Keyword when Enum Type is from other service #22408

Open
@davidsi02

Description

@davidsi02

Is there an existing issue for this?

  • I have searched the existing issues

Description

When generating client-side proxies for a microservices project where one service ("MyProject") depends on an enum ("MyEntityType") defined in another service ("MySecondService"), the proxy generator successfully imports the enum. However, during the generation of method parameter types, the specific OrganizationUnitType is incorrectly replaced with the generic enum keyword.

Reproduction Steps

Project Setup:

Create a microservices project with two services: "MyProject" and "MySecondService". "MyProject" will expose an API endpoint that utilizes an enum defined in "MySecondService".

1. Define the Enum in MySecondService:
In the "MySecondService" project, create a C# enum named MyEntityType within the MyApp.MySecondService namespace. Add enum members: A = 0, B = 1, C = 2.

// MyApp.MySecondService/MyEntityType.cs
namespace MyApp.MySecondService
{
    public enum MyEntityType
    {
        A = 0,
        B = 1,
        C = 2
    }
}

2. Create an API Endpoint in MyProject:
In the "MyProject" project, create an API controller (OrganizationUnitController) that depends on an application service (IMyEntityAppService). Create a Get endpoint that receives the enum MyEntityType as an optional parameter. The endpoint should forward the call to the application service.

// MyApp.MyService/OrganizationUnitController.cs
using MyApp.MySecondService; // Add reference to MySecondService
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace MyApp.MyService
{
    [Route("api/my-service/my-entity")]
    [ApiController]
    public class OrganizationUnitController : ControllerBase
    {
        private readonly IMyEntityAppService MyEntityAppService;

        public OrganizationUnitController(IMyEntityAppService myEntityAppService)
        {
            MyEntityAppService = myEntityAppService;
        }

        [HttpGet("tree")]
        public async Task<MyEntityDto> GetTreeAsync(MyEntityType? type = null)
        {
            // Assuming MyEntityAppService has a GetTreeAsync method that takes MyEntityType?
            return await MyEntityAppService.GetTreeAsync(type);
        }
    }

    public interface IMyEntityAppService{
        Task<MyEntityDto> GetTreeAsync(MyEntityType? type = null);
    }
    public class MyEntityDto{
        //DTO Properties
    }
}

3. Reference MySecondService in MyProject:
Add a project reference from "MyProject" to "MySecondService" to allow "MyProject" to use the MyEntityType enum.

4. Generate Proxies:
Use abp proxy-generation tool to update proxies.

Expected behavior

After successful proxy generation, the MyService in the client application should be generated with the following characteristics:

Enum Import:

The generated service should correctly import the EntityType enum from the appropriate location.
Methods that accept EntityType as a parameter should use the imported EntityType type in their parameter definitions.

For example:

getChildren = (path: string, type?: EntityType, config?: Partial<Rest.Config>) => ...

Actual behavior

The proxy generation tool successfully imports the OrganizationUnitType enum from the correct location:
import type { MyEnumType } from '../my-second-service/my-entity/my-entity-type.enum';
Incorrect Type Replacement:

However, when the generated service uses MyEntityType as a parameter type in its methods, the proxy generation tool replaces it with the generic enum type.

For example, instead of:

getChildren = (path: string, type?: MyEntityType, config?: Partial<Rest.Config>) => ... The generated code becomes:

getChildren = (path: string, type?: enum, config?: Partial<Rest.Config>) => ... Impact:

The generated code is notfunctional, because the generic keyword enum is not a valid typescript type.

Regression?

This worked with "@abp/ng.schematics": "5.1.2",

Known Workarounds

No response

Version

9.0.5

User Interface

Angular

Database Provider

EF Core (Default)

Tiered or separate authentication server

Separate Auth Server

Operation System

Windows (Default)

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions