Domanda

How can I iterate through all request/response DTOs that are setup with a route?

For example a route like this:

[Route("/api/something", "GET")]
public class SomethingGetRequest : IReturn<List<Something>>
{
    public int SomethingId { get; set; }
}

and Response DTO like this:

public class Something
{
    public string A { get; set; }
    public int B { get; set; }
}

I want to have a service action where I can iterate through all setup routes, and retrieve the:

  • Request URL
  • Class name
  • Request properties
  • Response DTO properties

Is there some Servicstack built in way to do this?

In the end I would like to use this to autogenerate ExtJS Store/Models. I'm also interested in a better/alternative approach.

EDIT:

Here is the solution I came up with: gist

On the /extjs/javascript route the service returns extjs store/models and on the /extjs/metadata route the service returns a zip file with a store/model folder you can drop in a newly created Sencha Architect project. The templates are based on what Architect v. 3.0.1.1343 produces.

This assumes a route decorated like this:

[Route("/api/something", "GET", Summary="route description")]
public class SomethingGetRequest : IReturn<List<Something>>
{

    [ApiMember(Name = "SomethingId", ParameterType = "query", IsRequired = true, DataType = "int")]
    public string SomethingId { get; set; }

}

The current implementation only works for simple properties in request/response DTOs. There is room for improvement...

È stato utile?

Soluzione

Have you looked at the ServiceStack.Api.Swagger package (documented here)? That sounds pretty similar to what you want.

If the Swagger UI won't work for you out of the box, you could use the ServiceStack.Api.Swagger package and send requests to /resources and its related URLs to get all the metadata in JSON format and then process that data according to your needs. Or if you want to write something in C#, consult the code for SwaggerApiService and SwaggerResourcesService to see how it retrieves all DTOs and routes and extracts metadata about them.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top