GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Swagger API Swagger API
Demis Bellot edited this page
This page has moved to docs.servicestack.net/swagger-apiSwagger is a specification and complete framework implementation for describing, producing, consuming, and visualizing RESTful web services. ServiceStack implements the Swagger 1.2 Spec back-end and embeds the Swagger UI front-end in a separate plugin which is available under Swagger NuGet package: You can enable Swagger by registering the public override void Configure(Container container) { ... Plugins.Add(new SwaggerFeature()); // uncomment CORS feature if it's has to be available from external sites //Plugins.Add(new CorsFeature()); ... } Then you will be able to view the Swagger UI from If you're Hosting ServiceStack with MVC then you'll need to tell MVC to ignore the path where ServiceStack is hosted, e.g: routes.IgnoreRoute("api/{*pathInfo}"); For MVC4 projects, you'll also need to disable WebAPI: //WebApiConfig.Register(GlobalConfiguration.Configuration);Each route could have a separate summary and description. You can set it with [Route("/hello", Summary = @"Default hello service.", Notes = "Longer description for hello service.")] You can set specific description for each HTTP method like shown below: [Route("/hello/{Name}", "GET", Summary="Says 'Hello' to provided Name", Notes = "Longer description of the GET method which says 'Hello'")] [Route("/hello/{Name}", "POST", Summary="Says 'Hello' to provided Name", Notes = "Longer description of the POST method which says 'Hello'")] You can further document your services in the Swagger UI with the new [Api("Service Description")] [ApiResponse(HttpStatusCode.BadRequest, "Your request was not understood")] [ApiResponse(HttpStatusCode.InternalServerError, "Oops, something broke")] [Route("/swagger/{Name}", "GET", Summary = "GET Summary", Notes = "Notes")] [Route("/swagger/{Name}", "POST", Summary = "POST Summary", Notes="Notes")] public class MyRequestDto { [ApiMember(Name="Name", Description = "Name Description", ParameterType = "path", DataType = "string", IsRequired = true)] [ApiAllowableValues("Name", typeof(Color))] //Enum public string Name { get; set; } } You can Exclude properties from being listed in Swagger with: [IgnoreDataMember] Exclude properties from being listed in Swagger Schema Body with: [ApiMember(ExcludeInSchema=true)] Or exclude entire Services from showing up in Swagger or any other Metadata Services (i.e. Metadata Pages, Postman, NativeTypes, etc) by annotating Request DTO's with: [Exclude(Feature.Metadata)] public class MyRequestDto { ... } The docs on the Virtual File System shows how to override embedded resources: ServiceStack's Virtual File System supports multiple file source locations where you can override Swagger's embedded files by including your own custom files in the same location as the existing embedded files. This lets you replace built-in ServiceStack embedded resources with your own by simply copying the /swagger-ui or /swagger-ui-bootstrap files you want to customize and placing them in your Website Directory at:
Users can call protected Services using the Username and Password fields in Swagger UI. Swagger sends these credentials with every API request using HTTP Basic Auth, which can be enabled in your AppHost with: Plugins.Add(new AuthFeature(..., new IAuthProvider[] { new BasicAuthProvider(), //Allow Sign-ins with HTTP Basic Auth })); Alternatively users can login outside of Swagger, to access protected Services in Swagger UI. ServiceStack.UseCases project contains example SwaggerHelloWorld. It demonstrates how to use and integrate ServiceStack.Api.Swagger. Take a look at README.txt for more details.
Clone this wiki locally |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |