Search code examples
servicestackswaggerservicestack-bsd

How to create summary/notes without using the Route attribute


I wanted to create the summaries in code behind because all of my routes are currently configured in the AppConfig class, but as far as I can tell, summaries can only be included using the Route attribute.

EX:

[Route("/myrequest/{Id}, "GET", Summary="My Summary", Notes="My Notes")]
public class MyRequest : IReturn<MyResponse>
{
    public int Id { get; set; }
}

yet my routes are configured like:

base.Routes
    .Add<MyRequest>("/myrequest", "GET");

Essentially I'd like to do something like:

base.Routes
    .Add<MyRequest>("/myrequest", "GET", "My Summary", "My Notes");

Is there currently a way to do this?

EDIT:

I'm using ServiceStack version 3.9.71


Solution

  • So I took another look at adding routes and found there actually is an overload that allows you to specify the summary and notes.

    Here's how to do it:

    base.Routes
        .Add(typeof(MyRequest), "/myrequest", "GET", "My Summary", "My Notes");
    

    I really wish ServiceStack would add an overload to the Generic Add method so I wouldn't have to specify the type in this way.

    EDIT:

    I decided to write an extension method to get the method I was initially looking for.

    public static class RouteExtensions
    {
        public static ServiceStack.ServiceHost.IServiceRoutes Add<T>(
            this ServiceStack.ServiceHost.IServiceRoutes route, 
            string restPath,
            string verbs,
            string summary,
            string notes)
        {
            route.Add(typeof(T), restPath, verbs, summary, notes);
    
            return route;
        }
    }
    

    Now I can do this:

    base.Routes
        .Add<MyRequest>("/myrequest", "GET", "My Summary", "My Notes");