khellang/Nancy.Swagger — pull request #44 by TimSchlechter (2014-08-23 21:04:58+00:00)
Title: Avoid model id collisions when two types have the same name

This PR provides a solution for the problem @liddellj mentioned in the comments:
```csharp
public static string DefaultModelId(this Type type)
{
// TODO: This won't scale as you'd get collisions between types with the same
// name but different namespace. Could use FullName, but that's a bit fugly.
// perhaps this is a reasonable default but the DSL could provide a facility for
// overriding a given model's ID?
return type.Name
}
```
[Ofcourse](http://www.wikiwand.com/en/Murphy's_law) I ran into this problem immediately when trying Nancy.Swagger with some codebase.
I agree returning type.FullName is not very pretty, so instead I renamed DefaultModelId to ResolveModelId. It returns the type.Name if it wasn't resolved by some other type with the same name first. Else, it prepends the last part of the type's namespace and checks again.

So
```csharp
Console.WriteLine(typeof(SomeNamespace.MyType).ResolveModelId());
Console.WriteLine(typeof(OtherNamespace.MyType).ResolveModelId());
```
will output
```csharp
MyType
OtherNamespaceMyType
```

The one thing I'm not very happy/sure about is it introduces state (_resolvedModelIds) in SwaggerExtensions.