diff --git a/Nancy.Metadata.Swagger.DemoApplication/Modules/RootModule.cs b/Nancy.Metadata.Swagger.DemoApplication/Modules/RootModule.cs index 0327534..2c94e2f 100644 --- a/Nancy.Metadata.Swagger.DemoApplication/Modules/RootModule.cs +++ b/Nancy.Metadata.Swagger.DemoApplication/Modules/RootModule.cs @@ -10,13 +10,13 @@ public class RootModule : NancyModule { public RootModule() : base("/api") { - Get["SimpleRequest", "/hello"] = r => HelloWorld(); - Get["SimpleRequestWithParameter", "/hello/{name}"] = r => Hello(r.name); + Get("/hello", r => HelloWorld(), name:"SimpleRequest"); + Get("/hello/{name}", r => Hello(r.name), name: "SimpleRequestWithParameter"); - Post["SimplePostRequst", "/hello"] = r => HelloPost(); - Post["PostRequestWithModel", "/hello/model"] = r => HelloModel(); + Post("/hello", r => HelloPost(), name:"SimplePostRequest"); + Post("/hello/model", r => HelloModel(), name:"PostRequestWithModel"); - Post["PostRequestWithNestedModel", "/hello/nestedmodel"] = r => HelloNestedModel(); + Post("/hello/nestedmodel", r => HelloNestedModel(), name: "PostRequestWithNestedModel"); } private Response HelloNestedModel() @@ -25,7 +25,7 @@ private Response HelloNestedModel() SimpleResponseModel response = new SimpleResponseModel { - Hello = string.Format("Hello, {0}. We got your name from nested obejct", model.SimpleModel.Name) + Hello = string.Format("Hello, {0}. We got your name from nested object", model.SimpleModel.Name) }; return Response.AsJson(response); @@ -79,29 +79,29 @@ public class RootMetadataModule : MetadataModule public RootMetadataModule() { Describe["SimpleRequest"] = desc => new SwaggerRouteMetadata(desc) - .With(i => i.WithResponseModel("200", typeof(SimpleResponseModel), "Sample response") - .WithSummary("Simple GET example")); + .With(i => SwaggerEndpointInfoBuilder.NewEndpointInfo(i).WithResponseModel("200", typeof(SimpleResponseModel), "Sample response") + .WithSummary("Simple GET example").Build()); Describe["SimpleRequestWithParameter"] = desc => new SwaggerRouteMetadata(desc) - .With(i => i.WithResponseModel("200", typeof(SimpleResponseModel), "Sample response") + .With(i => SwaggerEndpointInfoBuilder.NewEndpointInfo(i).WithResponseModel("200", typeof(SimpleResponseModel), "Sample response") .WithRequestParameter("name") - .WithSummary("Simple GET with parameters")); + .WithSummary("Simple GET with parameters").Build()); - Describe["SimplePostRequst"] = desc => new SwaggerRouteMetadata(desc) - .With(info => info.WithResponseModel("200", typeof(SimpleResponseModel), "Sample response") - .WithSummary("Simple POST example")); + Describe["SimplePostRequest"] = desc => new SwaggerRouteMetadata(desc) + .With(info => SwaggerEndpointInfoBuilder.NewEndpointInfo(info).WithResponseModel("200", typeof(SimpleResponseModel), "Sample response") + .WithSummary("Simple POST example").Build()); Describe["PostRequestWithModel"] = desc => new SwaggerRouteMetadata(desc) - .With(info => info.WithResponseModel("200", typeof(SimpleResponseModel)) + .With(info => SwaggerEndpointInfoBuilder.NewEndpointInfo(info).WithResponseModel("200", typeof(SimpleResponseModel)) .WithResponse("400", "Bad request") .WithSummary("Simple POST example with request model") - .WithRequestModel(typeof(SimpleRequestModel))); + .WithRequestModel(typeof(SimpleRequestModel)).Build()); Describe["PostRequestWithNestedModel"] = desc => new SwaggerRouteMetadata(desc) - .With(info => info.WithResponseModel("200", typeof(SimpleResponseModel)) + .With(info => SwaggerEndpointInfoBuilder.NewEndpointInfo(info).WithResponseModel("200", typeof(SimpleResponseModel)) .WithResponse("400", "Bad request") .WithSummary("Simple POST example with nested request model") - .WithRequestModel(typeof(NestedRequestModel))); + .WithRequestModel(typeof(NestedRequestModel)).Build()); } } } \ No newline at end of file diff --git a/Nancy.Metadata.Swagger.DemoApplication/Nancy.Metadata.Swagger.DemoApplication.csproj b/Nancy.Metadata.Swagger.DemoApplication/Nancy.Metadata.Swagger.DemoApplication.csproj index 08be2e0..d10b676 100644 --- a/Nancy.Metadata.Swagger.DemoApplication/Nancy.Metadata.Swagger.DemoApplication.csproj +++ b/Nancy.Metadata.Swagger.DemoApplication/Nancy.Metadata.Swagger.DemoApplication.csproj @@ -9,7 +9,7 @@ Properties Nancy.Metadata.Swagger.DemoApplication Nancy.Metadata.Swagger.DemoApplication - v4.5 + v4.5.2 512 ..\ @@ -38,24 +38,20 @@ - - ..\packages\Nancy.1.2.0\lib\net40\Nancy.dll - True + + ..\packages\Nancy.2.0.0-clinteastwood\lib\net452\Nancy.dll - - ..\packages\Nancy.Hosting.Self.1.2.0\lib\net40\Nancy.Hosting.Self.dll - True + + ..\packages\Nancy.Hosting.Self.2.0.0-clinteastwood\lib\net452\Nancy.Hosting.Self.dll - - ..\packages\Nancy.Metadata.Modules.1.2.0\lib\net40\Nancy.Metadata.Modules.dll - True + + ..\packages\Nancy.Metadata.Modules.2.0.0-clinteastwood\lib\net452\Nancy.Metadata.Modules.dll - - ..\packages\Nancy.Serialization.JsonNet.1.2.0\lib\net40\Nancy.Serialization.JsonNet.dll - True + + ..\packages\Nancy.Serialization.JsonNet.2.0.0-clinteastwood\lib\net452\Nancy.Serialization.JsonNet.dll - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True @@ -112,7 +108,9 @@ Nancy.Metadata.Swagger - + + + PreserveNewest diff --git a/Nancy.Metadata.Swagger.DemoApplication/Program.cs b/Nancy.Metadata.Swagger.DemoApplication/Program.cs index 6ad0820..3317b0d 100644 --- a/Nancy.Metadata.Swagger.DemoApplication/Program.cs +++ b/Nancy.Metadata.Swagger.DemoApplication/Program.cs @@ -9,7 +9,9 @@ static void Main() { string url = "http://localhost:5000"; - NancyHost host = new NancyHost(new Uri(url)); + var hostConfiguration = new HostConfiguration(); + hostConfiguration.UrlReservations.CreateAutomatically = true; + NancyHost host = new NancyHost(new Uri(url), new DefaultNancyBootstrapper(), hostConfiguration); host.Start(); Console.WriteLine("Nancy host is listening at {0}", url); diff --git a/Nancy.Metadata.Swagger.DemoApplication/app.config b/Nancy.Metadata.Swagger.DemoApplication/app.config index 5316136..f54f344 100644 --- a/Nancy.Metadata.Swagger.DemoApplication/app.config +++ b/Nancy.Metadata.Swagger.DemoApplication/app.config @@ -1,11 +1,11 @@  - + - + diff --git a/Nancy.Metadata.Swagger.DemoApplication/packages.config b/Nancy.Metadata.Swagger.DemoApplication/packages.config index c253cb1..ca90ba1 100644 --- a/Nancy.Metadata.Swagger.DemoApplication/packages.config +++ b/Nancy.Metadata.Swagger.DemoApplication/packages.config @@ -1,8 +1,9 @@  - - - - - + + + + + + \ No newline at end of file diff --git a/Nancy.Metadata.Swagger/Core/IJsonSchemaGenerator.cs b/Nancy.Metadata.Swagger/Core/IJsonSchemaGenerator.cs new file mode 100644 index 0000000..206ab95 --- /dev/null +++ b/Nancy.Metadata.Swagger/Core/IJsonSchemaGenerator.cs @@ -0,0 +1,9 @@ +using System; + +namespace Nancy.Metadata.Swagger.Core +{ + public interface IJsonSchemaGenerator + { + string GenerateSchema(Type modelType); + } +} diff --git a/Nancy.Metadata.Swagger/Core/NewtonsoftJsonSchemaGeneratorAdapter.cs b/Nancy.Metadata.Swagger/Core/NewtonsoftJsonSchemaGeneratorAdapter.cs new file mode 100644 index 0000000..2ad0765 --- /dev/null +++ b/Nancy.Metadata.Swagger/Core/NewtonsoftJsonSchemaGeneratorAdapter.cs @@ -0,0 +1,20 @@ +using System; +using Newtonsoft.Json.Schema.Generation; + +namespace Nancy.Metadata.Swagger.Core +{ + public class NewtonsoftJsonSchemaGeneratorAdapter : IJsonSchemaGenerator + { + private readonly JSchemaGenerator jsonSchemaGenerator; + + public NewtonsoftJsonSchemaGeneratorAdapter(JSchemaGenerator jsonSchemaGenerator) + { + this.jsonSchemaGenerator = jsonSchemaGenerator; + } + + public string GenerateSchema(Type modelType) + { + return jsonSchemaGenerator.Generate(modelType).ToString(); + } + } +} diff --git a/Nancy.Metadata.Swagger/Core/SchemaCache.cs b/Nancy.Metadata.Swagger/Core/SchemaCache.cs index 4dc6aa8..2feff2d 100644 --- a/Nancy.Metadata.Swagger/Core/SchemaCache.cs +++ b/Nancy.Metadata.Swagger/Core/SchemaCache.cs @@ -1,10 +1,11 @@ using System.Collections.Generic; -using Newtonsoft.Json.Schema; namespace Nancy.Metadata.Swagger.Core { + using Newtonsoft.Json.Linq; + public static class SchemaCache { - public static Dictionary Cache = new Dictionary(); + public static Dictionary Cache = new Dictionary(); } } \ No newline at end of file diff --git a/Nancy.Metadata.Swagger/Fluent/SwaggerEndpointInfoBuilder.cs b/Nancy.Metadata.Swagger/Fluent/SwaggerEndpointInfoBuilder.cs new file mode 100644 index 0000000..b493ab6 --- /dev/null +++ b/Nancy.Metadata.Swagger/Fluent/SwaggerEndpointInfoBuilder.cs @@ -0,0 +1,257 @@ +using System; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using Nancy.Metadata.Swagger.Core; +using Nancy.Metadata.Swagger.Model; +using Newtonsoft.Json.Schema.Generation; +using Newtonsoft.Json.Linq; + +namespace Nancy.Metadata.Swagger.Fluent +{ + public class SwaggerEndpointInfoBuilder + { + private readonly SwaggerEndpointInfo baseEndpointInfo; + private readonly IJsonSchemaGenerator jsonSchemaGenerator; + + private Dictionary responseInfos; + private List requestParameters; + private string[] endpointTags; + private string endpointDescription; + private string endpointSummary; + + private SwaggerEndpointInfoBuilder(SwaggerEndpointInfo baseEndpointInfo, IJsonSchemaGenerator jsonSchemaGenerator) + { + this.baseEndpointInfo = baseEndpointInfo; + this.jsonSchemaGenerator = jsonSchemaGenerator; + } + + public static SwaggerEndpointInfoBuilder NewEndpointInfo() + { + return NewEndpointInfo(GetDefaultJsonSchemaGenerator()); + } + + public static SwaggerEndpointInfoBuilder NewEndpointInfo(IJsonSchemaGenerator jsonSchemaGenerator) + { + return NewEndpointInfo(new SwaggerEndpointInfo(), jsonSchemaGenerator); + } + + public static SwaggerEndpointInfoBuilder NewEndpointInfo(SwaggerEndpointInfo baseEndpointInfo) + { + return NewEndpointInfo(baseEndpointInfo, GetDefaultJsonSchemaGenerator()); + } + + public static SwaggerEndpointInfoBuilder NewEndpointInfo(SwaggerEndpointInfo baseEndpointInfo, IJsonSchemaGenerator jsonSchemaGenerato) + { + return new SwaggerEndpointInfoBuilder(baseEndpointInfo, jsonSchemaGenerato); + } + + public SwaggerEndpointInfoBuilder WithResponseModel(string statusCode, Type modelType, string description = null) + { + if (responseInfos == null) + { + responseInfos = new Dictionary(); + } + + responseInfos[statusCode] = GenerateResponseInfo(description, modelType); + + return this; + } + + public SwaggerEndpointInfoBuilder WithDefaultResponse(Type responseType, string description = "Default response") + { + return WithResponseModel("200", responseType, description); + } + + public SwaggerEndpointInfoBuilder WithResponse(string statusCode, string description) + { + if (responseInfos == null) + { + responseInfos = new Dictionary(); + } + + responseInfos[statusCode] = GenerateResponseInfo(description); + + return this; + } + + public SwaggerEndpointInfoBuilder WithRequestParameter(string name, + string type = "string", string format = null, bool required = true, string description = null, + string loc = "path") + { + if (requestParameters == null) + { + requestParameters = new List(); + } + + requestParameters.Add(new SwaggerRequestParameter + { + Required = required, + Description = description, + Format = format, + In = loc, + Name = name, + Type = type + }); + + return this; + } + + public SwaggerEndpointInfoBuilder WithRequestModel(Type requestType, string name = "body", string description = null, bool required = true, string loc = "body") + { + if (requestParameters == null) + { + requestParameters = new List(); + } + + requestParameters.Add(new SwaggerRequestParameter + { + Required = required, + Description = description, + In = loc, + Name = name, + Schema = new SchemaRef + { + Ref = $"#/{SwaggerConstants.ModelDefinitionsKey}/{GetOrSaveSchemaReference(requestType)}" + } + }); + + return this; + } + + public SwaggerEndpointInfoBuilder WithDescription(string description, params string[] tags) + { + if (endpointTags == null) + { + if (tags.Length == 0) + { + tags = new[] { "default" }; + } + + endpointTags = tags; + } + + endpointDescription = description; + + return this; + } + + public SwaggerEndpointInfoBuilder WithSummary(string summary) + { + endpointSummary = summary; + return this; + } + + public SwaggerEndpointInfo Build() + { + baseEndpointInfo.Summary = endpointSummary; + baseEndpointInfo.Description = endpointDescription; + baseEndpointInfo.Tags = endpointTags; + if (responseInfos != null) + { + baseEndpointInfo.ResponseInfos = responseInfos; + } + + if (requestParameters != null) + { + baseEndpointInfo.RequestParameters = requestParameters; + } + + return baseEndpointInfo; + } + + private SwaggerResponseInfo GenerateResponseInfo(string description, Type responseType) + { + return new SwaggerResponseInfo + { + Schema = new SchemaRef + { + Ref = "#/definitions/" + GetOrSaveSchemaReference(responseType) + }, + Description = description + }; + } + + private SwaggerResponseInfo GenerateResponseInfo(string description) + { + return new SwaggerResponseInfo + { + Description = description + }; + } + + private string GetOrSaveSchemaReference(Type type) + { + var key = type.FullName; + + if (SchemaCache.Cache.ContainsKey(key)) + { + return key; + } + + var schema = jsonSchemaGenerator.GenerateSchema(type); + + // I didn't find the way how to disallow JSchemaGenerator to use nullable types, swagger doesn't work with them + var replaceNullableTypesPattern = @"\""type\"":[\s\n\r]*\[[\s\n\r]*\""(\w+)\"",[\s\n\r]*\""null\""[\s\n\r]*\]"; + var fixedNullableTypesSchema = Regex.Replace(schema, replaceNullableTypesPattern, "\"type\": \"$1\""); + var fixedSchema = FixInnerDefinitionReferences(fixedNullableTypesSchema, key); + SchemaCache.Cache[key] = JObject.Parse(fixedSchema); + + return key; + } + + private string FixInnerDefinitionReferences(string jsonSchema, string parentDefinitionKey) + { + var jObject = JObject.Parse(jsonSchema); + FixAllReferences(jObject, parentDefinitionKey); + return jObject.ToString(); + } + + private void FixAllReferences(JObject jObject, string parentDefinitionKey) + { + foreach (var token in jObject) + { + if (token.Key.Equals(SwaggerConstants.SchemaReferenceKey, StringComparison.CurrentCultureIgnoreCase)) + { + UpdateSchemaReference(parentDefinitionKey, token.Value); + } + else + { + var tokenObject = token.Value as JObject; + if (tokenObject != null) + { + FixAllReferences(tokenObject, parentDefinitionKey); + } + var tokenArray = token.Value as JArray; + if (tokenArray != null) + { + foreach (var elementToken in tokenArray) + { + var elementObject = elementToken as JObject; + if (elementObject != null) + { + FixAllReferences(elementObject, parentDefinitionKey); + } + } + } + } + } + } + + private static void UpdateSchemaReference(string parentDefinitionKey, JToken modelReferenceValue) + { + var currentReference = modelReferenceValue.ToString(); + var updatedReference = currentReference.Replace("#/", $"#/definitions/{parentDefinitionKey}/"); + modelReferenceValue.Replace(new JValue(updatedReference)); + } + + private static IJsonSchemaGenerator GetDefaultJsonSchemaGenerator() + { + return new NewtonsoftJsonSchemaGeneratorAdapter( + new JSchemaGenerator + { + SchemaIdGenerationHandling = SchemaIdGenerationHandling.FullTypeName, + SchemaReferenceHandling = SchemaReferenceHandling.None + }); + } + } +} diff --git a/Nancy.Metadata.Swagger/Fluent/SwaggerEndpointInfoExtensions.cs b/Nancy.Metadata.Swagger/Fluent/SwaggerEndpointInfoExtensions.cs deleted file mode 100644 index 945136b..0000000 --- a/Nancy.Metadata.Swagger/Fluent/SwaggerEndpointInfoExtensions.cs +++ /dev/null @@ -1,157 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text.RegularExpressions; -using Nancy.Metadata.Swagger.Core; -using Nancy.Metadata.Swagger.Model; -using Newtonsoft.Json.Schema; -using Newtonsoft.Json.Schema.Generation; - -namespace Nancy.Metadata.Swagger.Fluent -{ - public static class SwaggerEndpointInfoExtensions - { - public static SwaggerEndpointInfo WithResponseModel(this SwaggerEndpointInfo endpointInfo, string statusCode, Type modelType, string description = null) - { - if (endpointInfo.ResponseInfos == null) - { - endpointInfo.ResponseInfos = new Dictionary(); - } - - endpointInfo.ResponseInfos[statusCode] = GenerateResponseInfo(description, modelType); - - return endpointInfo; - } - - public static SwaggerEndpointInfo WithDefaultResponse(this SwaggerEndpointInfo endpointInfo, Type responseType, string description = "Default response") - { - return endpointInfo.WithResponseModel("200", responseType, description); - } - - public static SwaggerEndpointInfo WithResponse(this SwaggerEndpointInfo endpointInfo, string statusCode, string description) - { - if (endpointInfo.ResponseInfos == null) - { - endpointInfo.ResponseInfos = new Dictionary(); - } - - endpointInfo.ResponseInfos[statusCode] = GenerateResponseInfo(description); - - return endpointInfo; - } - - public static SwaggerEndpointInfo WithRequestParameter(this SwaggerEndpointInfo endpointInfo, string name, - string type = "string", string format = null, bool required = true, string description = null, - string loc = "path") - { - if (endpointInfo.RequestParameters == null) - { - endpointInfo.RequestParameters = new List(); - } - - endpointInfo.RequestParameters.Add(new SwaggerRequestParameter - { - Required = required, - Description = description, - Format = format, - In = loc, - Name = name, - Type = type - }); - - return endpointInfo; - } - - public static SwaggerEndpointInfo WithRequestModel(this SwaggerEndpointInfo endpointInfo, Type requestType, string name = "body", string description = null, bool required = true, string loc = "body") - { - if (endpointInfo.RequestParameters == null) - { - endpointInfo.RequestParameters = new List(); - } - - endpointInfo.RequestParameters.Add(new SwaggerRequestParameter - { - Required = required, - Description = description, - In = loc, - Name = name, - Schema = new SchemaRef - { - Ref = "#/definitions/" + GetOrSaveSchemaReference(requestType) - } - }); - - return endpointInfo; - } - - public static SwaggerEndpointInfo WithDescription(this SwaggerEndpointInfo endpointInfo, string description, params string[] tags) - { - if (endpointInfo.Tags == null) - { - if (tags.Length == 0) - { - tags = new[] {"default"}; - } - - endpointInfo.Tags = tags; - } - - endpointInfo.Description = description; - - return endpointInfo; - } - - public static SwaggerEndpointInfo WithSummary(this SwaggerEndpointInfo endpointInfo, string summary) - { - endpointInfo.Summary = summary; - return endpointInfo; - } - - private static SwaggerResponseInfo GenerateResponseInfo(string description, Type responseType) - { - return new SwaggerResponseInfo - { - Schema = new SchemaRef - { - Ref = "#/definitions/" + GetOrSaveSchemaReference(responseType) - }, - Description = description - }; - } - - private static SwaggerResponseInfo GenerateResponseInfo(string description) - { - return new SwaggerResponseInfo - { - Description = description - }; - } - - private static string GetOrSaveSchemaReference(Type type) - { - string key = type.FullName; - - if (SchemaCache.Cache.ContainsKey(key)) - { - return key; - } - - JSchemaGenerator generator = new JSchemaGenerator - { - SchemaIdGenerationHandling = SchemaIdGenerationHandling.FullTypeName, - SchemaReferenceHandling = SchemaReferenceHandling.None - }; - - JSchema schema = generator.Generate(type); - - // I didn't find the way how to disallow JSchemaGenerator to use nullable types, swagger doesn't work with them - - string tmp = schema.ToString(); - string s = @"\""type\"":[\s\n\r]*\[[\s\n\r]*\""(\w+)\"",[\s\n\r]*\""null\""[\s\n\r]*\]"; - tmp = Regex.Replace(tmp, s, "\"type\": \"$1\""); - - SchemaCache.Cache[key] = JSchema.Parse(tmp); - - return key; - } - } -} \ No newline at end of file diff --git a/Nancy.Metadata.Swagger/Fluent/SwaggerRouteMetadataExtensions.cs b/Nancy.Metadata.Swagger/Fluent/SwaggerRouteMetadataExtensions.cs index 195f6ac..6d27c15 100644 --- a/Nancy.Metadata.Swagger/Fluent/SwaggerRouteMetadataExtensions.cs +++ b/Nancy.Metadata.Swagger/Fluent/SwaggerRouteMetadataExtensions.cs @@ -7,9 +7,9 @@ namespace Nancy.Metadata.Swagger.Fluent public static class SwaggerRouteMetadataExtensions { public static SwaggerRouteMetadata With(this SwaggerRouteMetadata routeMetadata, - Func info) + Func endpointInfoBuilder) { - routeMetadata.Info = info(routeMetadata.Info ?? new SwaggerEndpointInfo()); + routeMetadata.Info = endpointInfoBuilder(routeMetadata.Info ?? new SwaggerEndpointInfo()); return routeMetadata; } diff --git a/Nancy.Metadata.Swagger/Model/SwaggerConstants.cs b/Nancy.Metadata.Swagger/Model/SwaggerConstants.cs new file mode 100644 index 0000000..96d680d --- /dev/null +++ b/Nancy.Metadata.Swagger/Model/SwaggerConstants.cs @@ -0,0 +1,10 @@ +namespace Nancy.Metadata.Swagger.Model +{ + public class SwaggerConstants + { + public const string TypePropertiesKey = "properties"; + public const string AllOfKey = "allOf"; + public const string ModelDefinitionsKey = "definitions"; + public const string SchemaReferenceKey = "$ref"; + } +} diff --git a/Nancy.Metadata.Swagger/Model/SwaggerRequestParameter.cs b/Nancy.Metadata.Swagger/Model/SwaggerRequestParameter.cs index 658f0d2..7016f20 100644 --- a/Nancy.Metadata.Swagger/Model/SwaggerRequestParameter.cs +++ b/Nancy.Metadata.Swagger/Model/SwaggerRequestParameter.cs @@ -28,7 +28,7 @@ public class SwaggerRequestParameter public class SchemaRef { - [JsonProperty("$ref")] + [JsonProperty(SwaggerConstants.SchemaReferenceKey)] public string Ref { get; set; } } } \ No newline at end of file diff --git a/Nancy.Metadata.Swagger/Model/SwaggerSpecification.cs b/Nancy.Metadata.Swagger/Model/SwaggerSpecification.cs index c57ce56..03d438f 100644 --- a/Nancy.Metadata.Swagger/Model/SwaggerSpecification.cs +++ b/Nancy.Metadata.Swagger/Model/SwaggerSpecification.cs @@ -1,6 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; -using Newtonsoft.Json.Schema; +using Newtonsoft.Json.Linq; namespace Nancy.Metadata.Swagger.Model { @@ -24,7 +24,7 @@ public class SwaggerSpecification [JsonProperty("paths")] public Dictionary> PathInfos { get; set; } - [JsonProperty("definitions")] - public Dictionary ModelDefinitions { get; set; } + [JsonProperty(SwaggerConstants.ModelDefinitionsKey)] + public Dictionary ModelDefinitions { get; set; } } } \ No newline at end of file diff --git a/Nancy.Metadata.Swagger/Model/SwaggerTypeDefinition.cs b/Nancy.Metadata.Swagger/Model/SwaggerTypeDefinition.cs index 10599b6..f490488 100644 --- a/Nancy.Metadata.Swagger/Model/SwaggerTypeDefinition.cs +++ b/Nancy.Metadata.Swagger/Model/SwaggerTypeDefinition.cs @@ -14,7 +14,7 @@ public class SwaggerTypeDefinition [JsonProperty("required")] public List RequiredProperties { get; set; } - [JsonProperty("properties")] + [JsonProperty(SwaggerConstants.TypePropertiesKey)] public Dictionary Properties { get; set; } } } \ No newline at end of file diff --git a/Nancy.Metadata.Swagger/Modules/SwaggerDocsModuleBase.cs b/Nancy.Metadata.Swagger/Modules/SwaggerDocsModuleBase.cs index c173049..6056672 100644 --- a/Nancy.Metadata.Swagger/Modules/SwaggerDocsModuleBase.cs +++ b/Nancy.Metadata.Swagger/Modules/SwaggerDocsModuleBase.cs @@ -3,7 +3,7 @@ using Nancy.Metadata.Swagger.Model; using Nancy.Routing; using Newtonsoft.Json; -using Newtonsoft.Json.Schema; +using Newtonsoft.Json.Linq; namespace Nancy.Metadata.Swagger.Modules { @@ -34,7 +34,7 @@ protected SwaggerDocsModuleBase(IRouteCacheProvider routeCacheProvider, this.apiBaseUrl = apiBaseUrl; this.schemes = schemes; - Get["/"] = r => GetDocumentation(); + Get("/", r => GetDocumentation()); } public virtual Response GetDocumentation() @@ -90,7 +90,7 @@ private void GenerateSpecification() // add definitions if (swaggerSpecification.ModelDefinitions == null) { - swaggerSpecification.ModelDefinitions = new Dictionary(); + swaggerSpecification.ModelDefinitions = new Dictionary(); } foreach (string key in SchemaCache.Cache.Keys) diff --git a/Nancy.Metadata.Swagger/Nancy.Metadata.Swagger.csproj b/Nancy.Metadata.Swagger/Nancy.Metadata.Swagger.csproj index 980e4a1..164e9eb 100644 --- a/Nancy.Metadata.Swagger/Nancy.Metadata.Swagger.csproj +++ b/Nancy.Metadata.Swagger/Nancy.Metadata.Swagger.csproj @@ -1,93 +1,13 @@ - - - - - Debug - AnyCPU - {3307A948-A2D7-4260-A644-720364E2136D} - Library - Properties - Nancy.Metadata.Swagger - Nancy.Metadata.Swagger - v4.5 - 512 - - ..\ - true - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - false - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - false - - - - ..\packages\Nancy.1.2.0\lib\net40\Nancy.dll - True - - - ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll - True - - - ..\packages\Newtonsoft.Json.Schema.2.0.2\lib\net45\Newtonsoft.Json.Schema.dll - True - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - \ No newline at end of file + + + + netstandard1.6;net452 + + + + + + + + + diff --git a/Nancy.Metadata.Swagger/Properties/AssemblyInfo.cs b/Nancy.Metadata.Swagger/Properties/AssemblyInfo.cs deleted file mode 100644 index 1382275..0000000 --- a/Nancy.Metadata.Swagger/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Nancy.Metadata.Swagger")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Hack & Craft")] -[assembly: AssemblyProduct("Nancy.Metadata.Swagger")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("c3508092-19f2-40fe-b84f-5e7d02845411")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.1")] -[assembly: AssemblyFileVersion("1.0.1")] -[assembly: AssemblyInformationalVersion("1.0.1-alpha")] diff --git a/Nancy.Metadata.Swagger/app.config b/Nancy.Metadata.Swagger/app.config deleted file mode 100644 index 9ca82da..0000000 --- a/Nancy.Metadata.Swagger/app.config +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/Nancy.Metadata.Swagger/packages.config b/Nancy.Metadata.Swagger/packages.config deleted file mode 100644 index a1c8ebb..0000000 --- a/Nancy.Metadata.Swagger/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file