khellang/Nancy.Swagger — pull request #8 by TimSchlechter (2014-07-17 14:58:20+00:00)
Title: Metadata by attribute annotations and retrieved using reflection

I created an ISwaggerMetaConverter which gets the route metadata from attribute annotations on routehandler-method and its parameters.

Annotating your api this way comes with one restriction: you can't handle your route using an anonymous method in your module constructor. If I'm correct, there is no way to place attributes on these.

So this Get["/"] _ => () { return "something"; } should be rewritten to Get["/"] _ => SomeConcreteMethod().

At this moment you can place attributes on methods and its parameters. Example:

public class TestModule : NancyModule
{
public TestModule()
: base("test")
{
Get["/{id}"] = _ => GetById(_.id, Request.Query.q);
}

[Get("/{id}",
Notes = "Some notes",
Summary = "Some summary",
Type = typeof(string)
)]
private dynamic GetById(
[PathParam("id", Required = true)] string id,
[QueryParam("q", Description = "Query")] string query)
{
throw new NotImplementedException();
}
}

I'm still working on this, but the current state gives a good idea about the direction I'm going with this. Feedback is highly appreciated.