Search code examples
c#servicestack

Is there a way to limit DTOs returned back from /types/typescript?


We have an api which serves 2 SPA sites and we use the models from /types/typescript in both. One of the sites only uses one services worth of DTOs but it has to use the generated file with all DTOs, making it heavier then it needs to be.

Is there a way to reduce/hide models using something either like service or DataMemberAttributes? For example:

types/typescript - returns non tagged dtos types/typescript?service=a - returns DTOS used in service A

types/typescript?member=siteone - return only DTOS with siteone tagged

types/typescript?member=sitetwo - return only DTOS with sitetwo tagged

I am aware we could delete unrelated models after the fact but with how often the DTOs are updated this would be a laborious and possibly error inducing process.


Solution

  • Have a look at the TypeScript Add ServiceStack Reference Docs DTO Customization Options which show all the different Types you can IncludeTypes.

    For this use-case I'd recommend Including Services by Tag Group where you can Group Services by Tag, e.g:

    [Tag("site")]
    public class MyRequest1 : IReturn<MyResponse> {}
    
    [Tag("site2")]
    public class MyRequest2 : IReturn<MyResponse> {}
    

    Then uncomment IncludeTypes in your dtos.ts header options with the tagged services you want to include, e.g:

    /* Options:
    IncludeTypes: {site1}