ServiceStack - Generate Typescript type generation for specific classes

I work with the backend, primarily oriented to the ServiceStack API and the Typescript front-end interface (with ServiceStack JsonServiceClient) that interacts with it. This is a large project, so scalability is very important, and our goal is to ensure strong application at all levels. So far things have been going well, but I am facing this problem.

We have an object that I will name Gadget:

public class GadgetDto
{
    public int Id { get; set; }
    // other stuff...
}

Through AutoQuery, we have an endpoint that returns a list of Gadgets:

[Route("/query/gadgets", HttpMethods.Get)]
public class QueryableGadget : QueryData<GadgetDto>
{
}

However, there was a need to create several Gadgets classes , so instead I reorganized the gadgets to be derived from the base class and interface:

public interface IGadget
{
    int Id { get; set; }
}

public abstract class GadgetBase : IGadget
{
    public int Id { get; set; }
}

public class TabbedGadget : GadgetBase
{
    public List<Tab> Tabs { get; set; }
}

:

[Route("/query/gadgets", HttpMethods.Get)]
public class QueryableGadget : QueryData<IGadget>

. QueryData, List<IGadget>, , .

, , Typescript, , GadgetBase TabbedGadget. , , API, , Typescript, , IGadget .

, - ServiceStack , "" Typescript (/types/typescript)?

!

+4
1

DTO, , DTO- , DTO.

, Dummy, DTO, :

public class DummyHolder : IReturnVoid
{
    public GadgetDto GadgetDto { get; set; }
    //...
}

public class DummyService : Service
{
    public void Any(DummyHolder request){}
}

ExportTypes NativeTypesFeature AppHost.Configure():

var nativeTypes = this.GetPlugin<NativeTypesFeature>();
nativeTypes.MetadataTypesConfig.ExportTypes.Add(typeof(GadgetDto));
+4

Source: https://habr.com/ru/post/1694254/


All Articles