Open Closed

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


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)
  • 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

  • 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.

  • 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)

  • 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.

  • 0
    ismcagdas created

    @dev_frontrush

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

  • 0
    dev_frontrush created

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

  • 0
    ismcagdas created

    Hi @dev_frontrush

    Is it possible for me to access your project ?

  • 0
    dev_frontrush created

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

  • 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
    {
        /// &lt;summary&gt;
        /// NumericComparisonOperator
        /// &lt;/summary&gt;
        /// &lt;remarks&gt;
        /// NumericComparisonOperator specifies accepted values for numeric comparison operators
        /// &lt;/remarks&gt;
        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.

  • 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&lt;PagedResultDto&lt;SomeResponseDto&gt;> GetSomeResult(MyLargeInputDto input) {  ...  }
    
  • 1
    ismcagdas created

    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.

  • 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.