IronicMuffin
IronicMuffin

Reputation: 4202

How do I properly use the Api Attribute in ServiceStack to name a service in SwaggerUI?

Using Swagger-UI and ServiceStack, I'm trying to use the Api attribute to name my services a little cleaner.

I am having a hard time figuring out where the attribute needs to be for it to add a description property to the api in the resources endpoint created by swagger.

I have a base request that is inherited by a few other requests for my customer end points. The Api attribute works only when placed on this particular request dto. If I move it to another, it stops working. Here is an exmaple of what my swagger page looks like:

enter image description here

Here is the code for that:

enter image description here

And here is the code that doesn't seem to work:

enter image description here

I'd like to have a friendly name for each service. Thanks!

Edit: I did track down some code in the ServiceStack codebase that indicates it is looking for the FirstAttribute. I tried testing by changing the order of things and didn't get the desired results either. I was looking at AttributeExtensions.cs if that helps.

Upvotes: 3

Views: 133

Answers (1)

mythz
mythz

Reputation: 143399

You can use [Api("API Description")] or [Description("API Description")] to add a Description to a single Service although this doesn't always map directly to a Swagger Route Description as the Swagger UI groups multiple routes under a single top-level route which covers multiple different services sharing the top-level route.

But you can specify a Route Summary with the RouteSummary dictionary on SwaggerFeature, e.g:

Plugins.Add(new SwaggerFeature {
    RouteSummary = {
        { "/top-level-path", "Route Summary" }
    }
});

Upvotes: 1

Related Questions