domaindrivendev/Swashbuckle — pull request #59 by ghys (2014-07-24 17:10:19+00:00)
Title: Added support for API metadata (Info object) and OAuth2 authorization

We use OAuth2 authentication in our API with [Thinktecture Authorization Server](https://github.com/thinktecture/Thinktecture.AuthorizationServer) so I wanted my Swagger docs to describe it.
I added the missing objects related to authorization (mainly focused on OAuth2) of the spec and added new extensibility options to feed the info to Swashbuckle.
While at it I also added the Info object (API metadata) in the same manner.

Here's an example:

Swashbuckle.Application.SwaggerSpecConfig.Customize(c =>
{
c.ApiInfo(new Swashbuckle.Swagger.Info
{
Title = "Pets API",
Description = "This API manages your pets",
Contact = "you@example.org"
});
c.SetOAuth2Authorization(new Swashbuckle.Swagger.Authorization
{
Type = "oauth2",
Scopes = new List {
new Swashbuckle.Swagger.Scope { ScopeId = "pets.read", Description = "Read your pets" },
new Swashbuckle.Swagger.Scope { ScopeId = "pets.write", Description = "Modify your pets" }
},
GrantTypes = new Swashbuckle.Swagger.GrantTypes {
ImplicitGrant = new Swashbuckle.Swagger.ImplicitGrant {
LoginEndpoint = new Swashbuckle.Swagger.LoginEndpoint {
Url = "https://yourapi/oauth/authorize"
},
TokenName = "access_token"
}
}
});
}

Lastly, I added new unofficial XML comments tags to describe scopes:

/// Read your pets
/// Modify your pets

Note that the Swagger UI OAuth2 initialization function is currently commented out; you'll find it in index.html, if you reenable it and change your client_id etc, I can confirm it works. The o2c.html redirect target must be copied to the root of your domain though.