I am trying to get my Web API project to use Swagger 'pretty' documentation, etc. (http://swagger.io/)
I'm using Swashbuckle for .NET, installed from NuGet and the version I am using is 4.0.1
I've been able to install and use Swagger. Everything seems normal at this point. The only hurdle I have is to disable API key's and have the ability to use OAuth, like in the PetStore sample (http://petstore.swagger.wordnik.com/#!/pet/addPet)
I've tried everything I could find on the web. Let me list them below:
First, Here is my Startup.cs
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
WebApiConfig.Register(config);
Swashbuckle.Bootstrapper.Init(config);
}
Now, my SwaggerConfig.cs:
public static void Register()
{
Swashbuckle.Bootstrapper.Init(GlobalConfiguration.Configuration);
SwaggerSpecConfig.Customize(c =>
{
c.IgnoreObsoleteActions();
c.IncludeXmlComments(GetXmlCommentsPath());
c.ApiInfo(new Info
{
Title = "Work you",
Description = "testing some stuffs",
Contact = "[email protected]"
});
c.Authorization("oauth2", new Authorization
{
Type = "oauth2",
Scopes = new List<Scope>
{
new Scope { ScopeId = "products.read", Description = "View products" },
new Scope { ScopeId = "products.manage", Description = "Manage products" }
},
GrantTypes = new GrantTypes
{
ImplicitGrant = new ImplicitGrant
{
LoginEndpoint = new LoginEndpoint
{
Url = "https://www.mysecure.website.com"
},
TokenName = "access_token"
}
}
});
});
SwaggerUiConfig.Customize(c =>
{
c.EnableOAuth2Support("client_id", "test-realm", "app Name");
var thisAssembly = typeof(SwaggerConfig).Assembly;
c.SupportHeaderParams = true;
c.DocExpansion = DocExpansion.List;
c.SupportedSubmitMethods = new[] { HttpMethod.Get, HttpMethod.Post, HttpMethod.Put, HttpMethod.Head };
c.EnableDiscoveryUrlSelector();
});
}
I have a SwaggerExtensions folder, in there I have the files that should be required. For example:
I have classes decorated with:
[ScopeAuthorize("this.scope")]
However, the OAuth option never displays for me on the swagger page. I can't see where I am supposed to be able to enter custom headers either.
I do see the title and documentation description, email address, etc is being read from the SwaggerConfig.cs so I know its at least being read.
I can't figure it out. :(
Any ideas?