servicestackservicestack-autoquery

Change Autoquery return type in DTO generation


I want to return a custom class from my custom AutoQuery endpoint that inherits QueryResponse<T> but adds a few extra properties.

public class WritingAssignmentBlogLookUpResponse : QueryResponse<BlogDto>, IResponse
{
    public bool Success { get; set; }
    public string Message { get; set; }
    public string DebugMessage { get; set; }
}

But if I specify request like so:

[Route("/assignment/blogs/", "POST")]
public class WritingAssignmentBlogsLookUpRequest : QueryDb<Blog, BlogDto>, IReturn<WritingAssignmentBlogLookUpResponse>
{

}

Then the return type specified in generatd DTO for client.post(req) is QueryResponse<BlogDto> and it doesn't generate WritingAssignmentBlogLookUpResponse at all.

Do I just have to specify return type as any from my typescript service or is there a way to make the types match so I can strongly type it?


Solution

  • You can’t change AutoQuery responses which are already fixed in their service contract definition to return a QueryResponse<T>.

    You can add extra info to the Meta Dictionary of the Response DTO (exists for this reason) otherwise if you need to change the Service Contract you’d need to convert it into a normal (I.e. non-AutoQuery) API which could use the Service Gateway to call an existing AutoQuery API that decorates the response.