khellang/Nancy.Swagger — pull request #56 by TimSchlechter (2014-10-30 21:55:47+00:00)
Title: Distinguish between SwaggerMetadataConverter and SwaggerMetadataProvider

This is a follow up after the feedback on PR #52. I have some ideas about how we could deal with attributes of well known packages (fo example: Newtonsoft.Json, System.ComponentModel.DataAnnotations). But first I need the refactorings in this PR, which I think are good on their own.

Currently SwaggerMetadataConverter fulfills two responsibility:
- Providing the Swagger meta data
- Converting the meta data to the Swagger API model

I added ISwaggerMetadataProvider to define the behaviour of providing metadata:
```csharp
public interface ISwaggerMetadataProvider
{
IList RetrieveSwaggerModelData();
IList RetrieveSwaggerRouteData();
}
```

This automatically results in refactoring some things:
- moved the RetrieveSwaggerRouteData and RetrieveSwaggerModelData implementation from SwaggerMetadataConverter to a new class DefaultSwaggerMetadataProvider
- renamed DefaultSwaggerMetadataConverter to DefaultSwaggerMetadataProvider
- renamed SwaggerMetadataConverter to DefaultSwaggerMetadataConverter
- renamed SwaggerAnnotationsConverter to SwaggerAnnotationsProvider
- renamed some things in the test projects

This way we have a better separation of concerns. If you would like to implement your own strategy of providing metadata, you just need to implement ISwaggerMetadataProvider.

If you would want to add support for, lets say Newtonsoft.Json attributes :wink:, you could easily create a class which encapsulates some ISwaggerMetadataProvider implementation (like DefaultSwaggerMetadataProvider or SwaggerAnnotationsProvider) and manipulates its output:
```csharp
public class JsonNetProvider : SwaggerMetadataProvider
{
private ISwaggerMetadataProvider _internalProvider;

public JsonNetProvider(ISwaggerMetadataProvider internalProvider)
{
_internalProvider = internalProvider;
}

public override IList RetrieveSwaggerModelData()
{
var models = _internalProvider.RetrieveSwaggerModelData();

// add information to the models and their properties

return models;
}

public override IList RetrieveSwaggerRouteData()
{
return _internalProvider.RetrieveSwaggerRouteData();
}
}
```