Open Closed

How to override or better handle generate-proxy ng output for custom ActionResult endpoints? #8857


User avatar
0
david1 created

Is there a suggested way to handle ActionResult custom endpoints e.g. suppose I have a custom controller with a custom endpoint:

namespace Core.Models.Transmittal
{
    [RemoteService(Name = "Core")]
    [Area("core")]
    [ControllerName("Transmittal")]
    [Route("api/core/transmittals")]

    public class TransmittalController : TransmittalControllerBase, ITransmittalsAppService
    {
        [HttpGet]
        [Route("my-custom-endpoint")]
        public async Task<ActionResult<PagedResultDto<string>>> GetMyCustomEndpoint() { ... }

Upon running abp generate-proxy -t ng -m core -u https://localhost:44311 the output is a separate and invalid .ts file:

mvc\models.ts (note: this is invalid Typescript output; the below file does not compile)


export interface ActionResult {
}

export interface ActionResult<TValue> {
  result: ActionResult;
  value: TValue;
}

export interface IActionResult {
}

And in the generated proxy output transmittal.service.ts:

    this.restService.request<any, ActionResult<PagedResultDto<string>>>({
      method: 'GET',
      url: '/api/core/transmittals/my-custom-endpoint',
      params: { },
    },
    { apiName: this.apiName,...config });

The endpoint only uses ActionResult to change the status response e.g. Ok() or NoContent() or some custom status code response but the actual output should just be the PagedResultDto<string>

Is there something I'm missing here? ActionResult<T> responses are a special exception so I'm not entirely sure why the mvc\models.ts output is showing the generated output of ActionResult<TValue> with a result self-referencing itself (this is invalid Typescript generation too so the output does not compile).

  • ABP Framework version: v 9.0.52, (cli: 0.9.23 )
  • UI Type: Angular
  • Database System: EF Core
  • Tiered (for MVC) or Auth Server Separated (for Angular): Auth Server Separated
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

1 Answer(s)
  • User Avatar
    0
    sumeyye.kurtulus created
    Support Team Angular Expert

    Hello, as far as I have understood you will need to use ActionResult in the controller in some way.

    To resolve this problem, you can consider using a structured base class like ActionResultBase. This ensures a consistent response format while maintaining compatibility with ABP’s proxy generation. Here’s an example implementation:

    using Ticket8857.Controllers;
    using System.Threading.Tasks;
    using System.Collections.Generic;
    using Microsoft.AspNetCore.Mvc;
    using Volo.Abp.Application.Dtos;
    
    public class ActionResultBase
    {
        public bool Success { get; set; }
        public string ErrorMessage { get; set; }
        public List<string> ValidationErrors { get; set; }
    
        public ActionResultBase()
        {
            ValidationErrors = new List<string>();
        }
    }
    
    public class ActionResult<TValue> : ActionResultBase
    {
        public ActionResultBase Result { get; set; }
        public TValue Value { get; set; }
    
        public ActionResult(ActionResultBase result, TValue value)
        {
            Result = result;
            Value = value;
        }
    }
    
    namespace Ticket8857.HttpApi.Controllers
    {
        public class MyCustomController : Ticket8857Controller
        {
            [HttpGet("get-something")]
            public async Task<ActionResult<PagedResultDto<string>>> GetSomethingAsync()
            {
                var result = new PagedResultDto<string>(
                    totalCount: 1,
                    items: new List<string> { "Success" }
                );
    
                return new ActionResult<PagedResultDto<string>>(new ActionResultBase(), result);
            }
            
        }
    }
    
    

    If you think that this does not cover your case, I can assist you further.

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
Do you need assistance from an ABP expert?
Schedule a Meeting
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v9.2.0-preview. Updated on March 17, 2025, 10:38