Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

DTO is not auto-generated in service-proxies #8707


User avatar
0
dev_frontrush created

What specifically allows DTO classes to be auto-generated in the service-proxies.ts file? I have an input DTO that is used as a parameter in an API method. The signature on the Angular side has all of the DTO properties broken out separately in the signature as opposed to allowing an object to be passed to the API. There are a large number of properties on this DTO and is not convenient to specify each one and ensure they are all in the right order for the service calls in Angular.


12 Answer(s)
  • User Avatar
    0
    smry created

    with your API running, open a cmd console and run angular\nswag\refresh.bat This will refresh your service-proxies.ts file with your updates from your API

  • User Avatar
    1
    dev_frontrush created

    Yes, after running nswag, the service-proxies file is generated and many services and other dto's are present in the file. However, there is one in particular that is not being generated in the file. The signature of the API method has all of the properties of the DTO as parameters, as opposed to one parameter being the DTO. Upon searching the service-proxies.ts file, I find that the dto is not present at all. This is the issue I am looking to resolve.

  • User Avatar
    0
    smry created

    What is your product version? What is your product type (Angular or MVC)? What is product framework type (.net framework or .net core)? Can you share the steps to reproduce the problem?

    (Not for me but they're going to ask before answering so figured id give you a heads start)

  • User Avatar
    0
    dev_frontrush created

    Version: 7.0.0 Angular/.Net Core

    dto class is defined as follows:

    public class MyLargeDto : PagedAndSortedInputDto, IShouldNormalize {
     
          public void Normalize()
            {
                if (Sorting.IsNullOrWhiteSpace())
                {
                    Sorting = "Id ASC";
                }
            }
            
            //lots of properties, some are string, bool? and other primitives, other are based off of other classes
     }
    

    nswag/refresh.bat is working fine for other API methods and dto's.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @dev_frontrush

    Is the method uses this DTO class exists in the interface of application service ?

  • User Avatar
    0
    dev_frontrush created

    Yes, the method is listed in the interface for this service.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @dev_frontrush

    Is it possible for me to access your project ?

  • User Avatar
    0
    dev_frontrush created

    Unfortunately, I do not think this will be possible. Is there an alternative that you could suggest?

  • User Avatar
    0
    dev_frontrush created

    Some details about my dto in question are as follows: There are approximately 50 properties. The types are decimal?, List<int>, string, int?, bool?, DateTime, and NumericComparisonOperator.

    NumericComparisonOperator is defined as follows:

    namespace SomeNamspace.Common.Dto
    {
        /// <summary>
        /// NumericComparisonOperator
        /// </summary>
        /// <remarks>
        /// NumericComparisonOperator specifies accepted values for numeric comparison operators
        /// </remarks>
        public enum NumericComparisonOperator
        {
            LessThan = -2,
            LessThanEqualTo = -1,
            Equal = 0,
            GreaterThanEqualTo = 1,
            GreaterThan = 2
        }
    }
    

    Note, it is interesting that the NumericComparisonOperator enum is present in the service-proxies.ts file.

    I have also tried removing the IShouldNormalize interface, and the associated Normalize method with no change in the proxy file.

  • User Avatar
    0
    dev_frontrush created

    The resulting method is generated in the service-proxies.ts file similar to below:

    getSomeResult(filter: string | null | undefined, firstName: string | null | undefined, lastName: string | null | undefined, satOperator: NumericComparisonOperator | null | undefined, etc,)  {  ....   }
    

    while it is defined in the C# API code similar to this:

     public async Task<PagedResultDto<SomeResponseDto>> GetSomeResult(MyLargeInputDto input) {  ...  }
    
  • User Avatar
    1
    ismcagdas created
    Support Team

    Hi @dev_frontrush

    Got it now. For GET methods, input parameters are added to query string, so no DTO class is generated in service-proxies.ts file.

  • User Avatar
    0
    dev_frontrush created

    Thats it! I changed the method name to not have Get in the name and now I am seeing what I needed to see! Thank you very much for your help.