How to enable swagger in ServiceStack?

2019-06-17 06:52发布

I found mention of swagger in the Introductory Slides. But nowhere else. Is is something not finished yet?

Edit: Apparently it's on To Do List.

Is there any good way to document the RestAPI automatically?

5条回答
ゆ 、 Hurt°
2楼-- · 2019-06-17 07:05

As I'm using .Net Core ServiceStack, So I have installed ServiceStack.Api.Swagger.Core nuget for Swagger UI.

But That was giving me '500: Undefined Error'.

Then i have removed ServiceStack.Api.Swagger.Core & installed ServiceStack.Api.Swagger.

That's works perfectly.

查看更多
做个烂人
3楼-- · 2019-06-17 07:09

To enable Swagger for your Service Stack, follow the Swagger API page on Service Stack wiki.

Detailed Steps:

  1. Run Install-Package ServiceStack.Api.Swagger in your package manager console.
  2. Enable Swagger plugin in your AppHost.cs with:

    using ServiceStack.Api.Swagger;
    
    public override void Configure(Container container)
    {
      ...
      Plugins.Add(new SwaggerFeature());
      ...
    }
    
  3. Access Swagger UI with http://localhost:port/swagger-ui/index.html

查看更多
爱情/是我丢掉的垃圾
4楼-- · 2019-06-17 07:15

Hmm...sorry if I misunderstood this:

Is there any good way to document the RestAPI automatically?

...but when I decorate my DTO or service with attributes this:

[Route("/hello","GET")]
[Route("/hello/{Name}","POST,GET")]
public class Hello : IReturn<HelloResponse>
{
    public string Name { get; set; }
}

The default metadata page generated by servicestack documents the usage:

enter image description here

Is this not what you are looking for ?

查看更多
乱世女痞
5楼-- · 2019-06-17 07:21

According to Trello it was a "Doing" but has then been moved back to "To Do"; and there's a Swagger.Api module in the github repo, so assuming it's only partially finished.

Edit

As pointed out already (but for the sake of completeness, as this was the accepted answer), SwaggerUI is ready for service stack (and holy moly is it awesome). The Github wiki has been filled out in the last few days, and it's super easy to get it up & running.

查看更多
聊天终结者
6楼-- · 2019-06-17 07:21

Looks like it's complete and ready now, check out the release notes for v3.9.35 @ https://github.com/ServiceStack/ServiceStack/wiki/Release-Notes

查看更多
登录 后发表回答