khellang/Nancy.Swagger — pull request #3 by liddellj (2014-06-19 11:31:25+00:00)
Title: DSL and SwaggerModule

Here is what I currently have for describing routes and publishing the corresponding Swagger endpoint. I've added a `SwaggerModule` - which picks up metadata from `IRouteCacheProvider`.

To populate the metadata in the first place, there is an `AsSwagger` extension method on `RouteDescription` - which returns a `SwaggerRouteDataBuilder`. The builder gives you access to the DSL I previewed last week on JabbR and exposes an instance of `SwaggerRouteData`.

Assuming a module called `UserModule` with a named route called *GetUsers*, this can be used with a metadata module like this:
```c#
public class UserMetadataModule : MetadataModule
{
public UserMetadataModule()
{
this.Describe["GetUsers"] = desc =>
{
return desc.AsSwagger(with =>
{
with.ResourcePath("/users");
with.Summary("Search users");
with.Notes("Returns users based on the given search criteria");
with.QueryParam("query", "Query to search by");
with.QueryParam("page", "Page of results to return", defaultValue: 0);
with.QueryParam("pageSize", "Number of results per page", defaultValue: 10);
});
};
}
}
```

In it's current form the easiest steps to get up and running are:
1. Add a reference to this library.
2. Add a reference to the *Nancy.MetaData* NuGet (the name of this package [may](https://github.com/NancyFx/Nancy/pull/1555) change in the future),
3. Implement one or more metadata modules as per the example above.

The DSL is incomplete. In particular, you cannot yet describe a model.