diff --git a/Swashbuckle.OData.Nuget/Swashbuckle.OData.NuGet.nuproj b/Swashbuckle.OData.Nuget/Swashbuckle.OData.NuGet.nuproj index dbc4cff..d0d22a6 100644 --- a/Swashbuckle.OData.Nuget/Swashbuckle.OData.NuGet.nuproj +++ b/Swashbuckle.OData.Nuget/Swashbuckle.OData.NuGet.nuproj @@ -25,12 +25,12 @@ Richard Beauchamp Extends Swashbuckle with OData v4 support! Extends Swashbuckle with OData v4 support! - Supports OData actions that accept an array of Entities or Complex Types. Fixes #59, #60, #62. + Supports decimal parameters, keys and return types. https://github.com/rbeauchamp/Swashbuckle.OData https://github.com/rbeauchamp/Swashbuckle.OData/blob/master/License.txt Copyright 2015 Swashbuckle Swagger SwaggerUi OData Documentation Discovery Help WebApi AspNet AspNetWebApi Docs WebHost IIS - 2.12.5 + 2.13.0 diff --git a/Swashbuckle.OData.Tests/Fixtures/ParameterTests/DecimalParameterAndResponseTests.cs b/Swashbuckle.OData.Tests/Fixtures/ParameterTests/DecimalParameterAndResponseTests.cs index c3a4fdc..470f2b2 100644 --- a/Swashbuckle.OData.Tests/Fixtures/ParameterTests/DecimalParameterAndResponseTests.cs +++ b/Swashbuckle.OData.Tests/Fixtures/ParameterTests/DecimalParameterAndResponseTests.cs @@ -21,7 +21,7 @@ namespace Swashbuckle.OData.Tests public class DecimalParameterAndResponseTests { [Test] - public async Task It_supports_a_decimal_key() + public async Task It_supports_entity_with_a_decimal_key() { using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(DecimalParametersController)))) { @@ -44,6 +44,42 @@ public async Task It_supports_a_decimal_key() } } + [Test] + public async Task It_supports_functions_with_a_decimal_parameter() + { + using (WebApp.Start(HttpClientUtils.BaseAddress, appBuilder => Configuration(appBuilder, typeof(DecimalParametersController)))) + { + // Arrange + var httpClient = HttpClientUtils.GetHttpClient(HttpClientUtils.BaseAddress); + // Verify that the OData route in the test controller is valid + var result = await httpClient.GetJsonAsync>("/odata/DecimalParameters/Default.ResponseTest(param=2.5m)"); + result.Value.Should().Be(2.5m); + + // Act + var swaggerDocument = await httpClient.GetJsonAsync("swagger/docs/v1"); + + // Assert + PathItem pathItem; + swaggerDocument.paths.TryGetValue("/odata/DecimalParameters/Default.ResponseTest(param={param})", out pathItem); + pathItem.Should().NotBeNull(); + pathItem.get.Should().NotBeNull(); + var getResponse = pathItem.get.responses.SingleOrDefault(response => response.Key == "200"); + getResponse.Should().NotBeNull(); + getResponse.Value.schema.@ref.Should().Be("#/definitions/ODataResponse[Decimal]"); + swaggerDocument.definitions.Should().ContainKey("ODataResponse[Decimal]"); + var responseSchema = swaggerDocument.definitions["ODataResponse[Decimal]"]; + responseSchema.Should().NotBeNull(); + responseSchema.properties.Should().NotBeNull(); + responseSchema.properties.Should().ContainKey("@odata.context"); + responseSchema.properties["@odata.context"].type.Should().Be("string"); + responseSchema.properties["value"].type.Should().Be("number"); + responseSchema.properties["value"].format.Should().Be("decimal"); + responseSchema.properties["value"].items.Should().BeNull(); + + await ValidationUtils.ValidateSwaggerJson(); + } + } + private static void Configuration(IAppBuilder appBuilder, Type targetController) { var config = appBuilder.GetStandardHttpConfig(targetController); diff --git a/Swashbuckle.OData/DefaultCompositionRoot.cs b/Swashbuckle.OData/DefaultCompositionRoot.cs index a25f12f..65c8fce 100644 --- a/Swashbuckle.OData/DefaultCompositionRoot.cs +++ b/Swashbuckle.OData/DefaultCompositionRoot.cs @@ -73,7 +73,7 @@ public static SwaggerProviderOptions GetSwaggerProviderOptions(SwaggerDocsConfig swaggerDocsConfig.GetFieldValue("_ignoreObsoleteActions"), swaggerDocsConfig.GetFieldValue>("_groupingKeySelector"), swaggerDocsConfig.GetFieldValue>("_groupingKeyComparer"), - swaggerDocsConfig.GetFieldValue>>("_customSchemaMappings"), + GetODataCustomSchemaMappings(swaggerDocsConfig), swaggerDocsConfig.GetFieldValue>>("_schemaFilters", true).Select(factory => factory()), swaggerDocsConfig.GetFieldValue>>("_modelFilters", true).Select(factory => factory()), swaggerDocsConfig.GetFieldValue("_ignoreObsoleteProperties"), @@ -86,6 +86,18 @@ public static SwaggerProviderOptions GetSwaggerProviderOptions(SwaggerDocsConfig ); } + /// + /// Gets custom schema mappings that will only be applied to OData operations. + /// + /// The swagger docs configuration. + /// + private static IDictionary> GetODataCustomSchemaMappings(SwaggerDocsConfig swaggerDocsConfig) + { + var customSchemaMappings = swaggerDocsConfig.GetFieldValue>>("_customSchemaMappings", true); + customSchemaMappings[typeof(decimal)] = () => new Schema { type = "number", format = "decimal" }; + return customSchemaMappings; + } + /// /// Gets operation filters that will only be applied to OData operations. /// diff --git a/Swashbuckle.OData/Properties/AssemblyInfo.cs b/Swashbuckle.OData/Properties/AssemblyInfo.cs index ebfa4c3..6f0aada 100644 --- a/Swashbuckle.OData/Properties/AssemblyInfo.cs +++ b/Swashbuckle.OData/Properties/AssemblyInfo.cs @@ -37,4 +37,4 @@ [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: AssemblyInformationalVersion("2.12.5")] \ No newline at end of file +[assembly: AssemblyInformationalVersion("2.13.0")] \ No newline at end of file diff --git a/Swashbuckle.OData/SchemaRegistryExtensions.cs b/Swashbuckle.OData/SchemaRegistryExtensions.cs index 7c129aa..d786598 100644 --- a/Swashbuckle.OData/SchemaRegistryExtensions.cs +++ b/Swashbuckle.OData/SchemaRegistryExtensions.cs @@ -179,6 +179,10 @@ private static bool IsResponseWithPrimiveTypeNotSupportedByJson(Type type, Messa { return true; } + if (type == typeof(decimal)) + { + return true; + } } return false; } diff --git a/appveyor.yml b/appveyor.yml index a532fd2..61a705d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.12.5.{build} +version: 2.13.0.{build} before_build: - cmd: nuget restore