From 71fc4728b58c5d2e64975007089ba8461cd07eff Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Sun, 19 May 2019 15:19:35 +0200 Subject: [PATCH 01/20] Use latest NJS and Namotion.Reflection --- .../NSwag.AspNet.Owin.csproj | 2 +- .../NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.AssemblyLoader.csproj | 4 +- .../NSwag.CodeGeneration.CSharp.csproj | 4 +- .../NSwag.CodeGeneration.TypeScript.csproj | 4 +- .../NSwag.CodeGeneration.csproj | 4 +- src/NSwag.Commands/NSwag.Commands.csproj | 14 +- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core/NSwag.Core.csproj | 4 +- src/NSwag.Min.sln | 100 +++++++++++++ .../AspNetCoreToSwaggerGenerator.cs | 5 +- .../NSwag.SwaggerGeneration.AspNetCore.csproj | 2 +- ...pNetCoreOperationSecurityScopeProcessor.cs | 1 + .../Processors/OperationParameterProcessor.cs | 23 +-- .../Processors/OperationResponseProcessor.cs | 9 +- .../NSwag.SwaggerGeneration.WebApi.csproj | 2 +- .../Processors/OperationParameterProcessor.cs | 52 +++---- .../WebApiToSwaggerGenerator.cs | 11 +- .../NSwag.SwaggerGeneration.csproj | 2 +- .../Processors/ApiVersionProcessor.cs | 3 +- .../DocumentExtensionDataProcessor.cs | 3 +- .../OperationExtensionDataProcessor.cs | 5 +- .../OperationResponseProcessorBase.cs | 56 +++----- ...OperationSummaryAndDescriptionProcessor.cs | 5 + .../Processors/OperationTagsProcessor.cs | 19 ++- .../SwaggerGenerator.cs | 17 +-- .../SwaggerGeneratorSettings.cs | 1 + .../SwaggerJsonSchemaGenerator.cs | 36 ++--- src/switcher.json | 132 +++++++++++++++++- 29 files changed, 390 insertions(+), 134 deletions(-) diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index b070d6b9e3..d177ac014b 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -46,10 +46,10 @@ - + diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index f7d7d39d31..cd9412fb88 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -21,11 +21,11 @@ TRACE;DEBUG;NET45 - + \ No newline at end of file diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index 487c9449dd..24bd6dc3c0 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -24,7 +24,6 @@ TRACE;RELEASE;FullNet;NET451 - @@ -36,4 +35,7 @@ 4.3.0 + + + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index 774132d134..6f921f9d1b 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -43,13 +43,11 @@ - - - + diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index ca8ab681b1..fe5c9394e3 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -39,13 +39,11 @@ - - - + diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 3831c86a92..1c4773c963 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -19,13 +19,13 @@ - - + + \ No newline at end of file diff --git a/src/NSwag.Commands/NSwag.Commands.csproj b/src/NSwag.Commands/NSwag.Commands.csproj index 55f1588bd3..e7dee4d904 100644 --- a/src/NSwag.Commands/NSwag.Commands.csproj +++ b/src/NSwag.Commands/NSwag.Commands.csproj @@ -26,7 +26,6 @@ - @@ -64,22 +63,19 @@ - - - - - - - - + + + + + diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index 9a4c0c29d4..c4993c90e6 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -16,10 +16,10 @@ NSwag - + \ No newline at end of file diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 0616064a03..4af0d9a9da 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -23,7 +23,6 @@ - @@ -33,4 +32,7 @@ + + + \ No newline at end of file diff --git a/src/NSwag.Min.sln b/src/NSwag.Min.sln index 6d68256729..79a2fe0c80 100644 --- a/src/NSwag.Min.sln +++ b/src/NSwag.Min.sln @@ -77,6 +77,16 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NSwag.Sample.NETCore22", "N EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSwag.Sample.NETCore30", "NSwag.Sample.NETCore30\NSwag.Sample.NETCore30.csproj", "{BEE63487-C130-4337-BB01-E3661D830CA6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema", "..\..\NJsonSchema\src\NJsonSchema\NJsonSchema.csproj", "{CD3840EC-6930-458C-B119-ED8509629B4C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.Yaml", "..\..\NJsonSchema\src\NJsonSchema.Yaml\NJsonSchema.Yaml.csproj", "{A3034424-FB36-4E0F-935D-CA0B00A699AD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.CodeGeneration", "..\..\NJsonSchema\src\NJsonSchema.CodeGeneration\NJsonSchema.CodeGeneration.csproj", "{1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.CodeGeneration.CSharp", "..\..\NJsonSchema\src\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj", "{72C7B587-9B92-4C78-83E4-9DB2AC091244}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.CodeGeneration.TypeScript", "..\..\NJsonSchema\src\NJsonSchema.CodeGeneration.TypeScript\NJsonSchema.CodeGeneration.TypeScript.csproj", "{7FBFD522-1E27-45E0-844C-C6C8AECE04D0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -628,6 +638,96 @@ Global {BEE63487-C130-4337-BB01-E3661D830CA6}.ReleaseTypeScriptStrict|x64.Build.0 = Release|Any CPU {BEE63487-C130-4337-BB01-E3661D830CA6}.ReleaseTypeScriptStrict|x86.ActiveCfg = Release|Any CPU {BEE63487-C130-4337-BB01-E3661D830CA6}.ReleaseTypeScriptStrict|x86.Build.0 = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x64.ActiveCfg = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x64.Build.0 = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x86.ActiveCfg = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x86.Build.0 = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|Any CPU.Build.0 = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x64.ActiveCfg = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x64.Build.0 = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x86.ActiveCfg = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x86.Build.0 = Release|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU + {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x64.ActiveCfg = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x64.Build.0 = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x86.ActiveCfg = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x86.Build.0 = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|Any CPU.Build.0 = Release|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x64.ActiveCfg = Release|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x64.Build.0 = Release|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x86.ActiveCfg = Release|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x86.Build.0 = Release|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU + {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x64.ActiveCfg = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x64.Build.0 = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x86.ActiveCfg = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x86.Build.0 = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|Any CPU.Build.0 = Release|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x64.ActiveCfg = Release|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x64.Build.0 = Release|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x86.ActiveCfg = Release|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x86.Build.0 = Release|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU + {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x64.ActiveCfg = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x64.Build.0 = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x86.ActiveCfg = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x86.Build.0 = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|Any CPU.Build.0 = Release|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x64.ActiveCfg = Release|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x64.Build.0 = Release|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x86.ActiveCfg = Release|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x86.Build.0 = Release|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU + {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x64.ActiveCfg = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x64.Build.0 = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x86.ActiveCfg = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x86.Build.0 = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|Any CPU.Build.0 = Release|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x64.ActiveCfg = Release|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x64.Build.0 = Release|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x86.ActiveCfg = Release|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x86.Build.0 = Release|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU + {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs b/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs index 0cf506d120..b42ea36c57 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs @@ -16,6 +16,7 @@ using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Namotion.Reflection; using Newtonsoft.Json; using NJsonSchema; using NJsonSchema.Infrastructure; @@ -303,11 +304,11 @@ private async Task RunOperationProcessorsAsync(SwaggerDocument document, A .GetCustomAttributes() // 3. Run from method attributes .Concat(methodInfo.GetCustomAttributes()) - .Where(a => a.GetType().IsAssignableTo("SwaggerOperationProcessorAttribute", TypeNameStyle.Name)); + .Where(a => a.GetType().IsAssignableToTypeName("SwaggerOperationProcessorAttribute", TypeNameStyle.Name)); foreach (dynamic attribute in operationProcessorAttribute) { - var operationProcessor = ReflectionExtensions.HasProperty(attribute, "Parameters") ? + var operationProcessor = ObjectExtensions.HasProperty(attribute, "Parameters") ? (IOperationProcessor)Activator.CreateInstance(attribute.Type, attribute.Parameters) : (IOperationProcessor)Activator.CreateInstance(attribute.Type); diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj index 4095e7c0d2..de95308d03 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj +++ b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj @@ -25,12 +25,12 @@ - + \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/AspNetCoreOperationSecurityScopeProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/AspNetCoreOperationSecurityScopeProcessor.cs index ac92705db8..0c52ca9a0c 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/AspNetCoreOperationSecurityScopeProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/AspNetCoreOperationSecurityScopeProcessor.cs @@ -13,6 +13,7 @@ using Microsoft.AspNetCore.Authorization; using NSwag.SwaggerGeneration.AspNetCore; using NJsonSchema.Infrastructure; +using Namotion.Reflection; namespace NSwag.SwaggerGeneration.Processors.Security { diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index 7f94393b49..67484079b6 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -15,6 +15,7 @@ using Microsoft.AspNetCore.Mvc.Abstractions; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.ModelBinding; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Annotations; using NJsonSchema.Generation; @@ -236,7 +237,7 @@ private bool IsNullable(ParameterInfo parameter) private async Task TryAddFileParameterAsync( OperationProcessorContext context, ExtendedApiParameterDescription extendedApiParameter) { - var typeInfo = _settings.ReflectionService.GetDescription(extendedApiParameter.ParameterType, extendedApiParameter.Attributes, _settings); + var typeInfo = _settings.ReflectionService.GetDescription(extendedApiParameter.ParameterType.ToContextualType(extendedApiParameter.Attributes), _settings); var isFileArray = IsFileArray(extendedApiParameter.ApiParameter.Type, typeInfo); @@ -244,7 +245,7 @@ private async Task TryAddFileParameterAsync( .Union(extendedApiParameter.ParameterType.GetTypeInfo().GetCustomAttributes()); var hasSwaggerFileAttribute = attributes.Any(a => - a.GetType().IsAssignableTo("SwaggerFileAttribute", TypeNameStyle.Name)); + a.GetType().IsAssignableToTypeName("SwaggerFileAttribute", TypeNameStyle.Name)); if (typeInfo.Type == JsonObjectType.File || typeInfo.Format == JsonFormatStrings.Binary || @@ -276,7 +277,7 @@ private bool IsFileArray(Type type, JsonTypeDescription typeInfo) if (typeInfo.Type == JsonObjectType.Array && type.GenericTypeArguments.Any()) { - var description = _settings.ReflectionService.GetDescription(type.GenericTypeArguments[0], null, _settings); + var description = _settings.ReflectionService.GetDescription(type.GenericTypeArguments[0].ToContextualType(), _settings); if (description.Type == JsonObjectType.File || description.Format == JsonFormatStrings.Binary) { return true; @@ -290,13 +291,15 @@ private async Task AddBodyParameterAsync(OperationProcessorCon { SwaggerParameter operationParameter; - var typeDescription = _settings.ReflectionService.GetDescription( - extendedApiParameter.ParameterType, extendedApiParameter.Attributes, _settings); + var contextualParameterType = extendedApiParameter.ParameterType + .ToContextualType(extendedApiParameter.Attributes); + + var typeDescription = _settings.ReflectionService.GetDescription(contextualParameterType, _settings); var isNullable = _settings.AllowNullableBodyParameters && typeDescription.IsNullable; var operation = context.OperationDescription.Operation; var parameterType = extendedApiParameter.ParameterType; - if (parameterType.Name == "XmlDocument" || parameterType.InheritsFrom("XmlDocument", TypeNameStyle.Name)) + if (parameterType.Name == "XmlDocument" || parameterType.InheritsFromTypeName("XmlDocument", TypeNameStyle.Name)) { operation.TryAddConsumes("application/xml"); operationParameter = new SwaggerParameter @@ -313,7 +316,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon Description = await extendedApiParameter.GetDocumentationAsync().ConfigureAwait(false) }; } - else if (parameterType.IsAssignableTo("System.IO.Stream", TypeNameStyle.FullName)) + else if (parameterType.IsAssignableToTypeName("System.IO.Stream", TypeNameStyle.FullName)) { operation.TryAddConsumes("application/octet-stream"); operationParameter = new SwaggerParameter @@ -341,7 +344,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon IsNullableRaw = isNullable, Description = await extendedApiParameter.GetDocumentationAsync().ConfigureAwait(false), Schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( - extendedApiParameter.ParameterType, extendedApiParameter.Attributes, isNullable, schemaResolver: context.SchemaResolver).ConfigureAwait(false) + contextualParameterType, isNullable, schemaResolver: context.SchemaResolver).ConfigureAwait(false) }; } @@ -427,11 +430,11 @@ public async Task GetDocumentationAsync() var parameterDocumentation = string.Empty; if (ParameterInfo != null) { - parameterDocumentation = await ParameterInfo.GetDescriptionAsync(Attributes).ConfigureAwait(false); + parameterDocumentation = await ParameterInfo.ToContextualParameter().GetDescriptionAsync().ConfigureAwait(false); } else if (PropertyInfo != null) { - parameterDocumentation = await PropertyInfo.GetDescriptionAsync(Attributes).ConfigureAwait(false); + parameterDocumentation = await PropertyInfo.ToContextualProperty().GetDescriptionAsync().ConfigureAwait(false); } return parameterDocumentation; diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs index 20f63d154a..91f3a70e97 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors; @@ -70,15 +71,15 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso if (IsVoidResponse(returnType) == false) { + var contextualReturnType = returnType.ToContextualType(context.MethodInfo.ReturnParameter.GetCustomAttributes(false).OfType()); + var typeDescription = _settings.ReflectionService.GetDescription( - returnType, GetParameterAttributes(context.MethodInfo.ReturnParameter), - _settings.DefaultResponseReferenceTypeNullHandling, _settings); + contextualReturnType, _settings.DefaultResponseReferenceTypeNullHandling, _settings); response.IsNullableRaw = typeDescription.IsNullable; response.Schema = await context.SchemaGenerator - .GenerateWithReferenceAndNullabilityAsync( - returnType, null, typeDescription.IsNullable, context.SchemaResolver) + .GenerateWithReferenceAndNullabilityAsync(contextualReturnType, typeDescription.IsNullable, context.SchemaResolver) .ConfigureAwait(false); } diff --git a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj index 244f453f23..f443b3af04 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj @@ -22,12 +22,12 @@ - + \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index 8e4eaead0d..a5142e5feb 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -13,6 +13,7 @@ using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Generation; using NJsonSchema.Infrastructure; @@ -51,13 +52,13 @@ public async Task ProcessAsync(OperationProcessorContext context) var parameterName = parameter.Name; var attributes = parameter.GetCustomAttributes().ToList(); - dynamic fromRouteAttribute = attributes.TryGetIfAssignableTo("Microsoft.AspNetCore.Mvc.FromRouteAttribute"); - dynamic fromHeaderAttribute = attributes.TryGetIfAssignableTo("Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); - dynamic fromFormAttribute = attributes.TryGetIfAssignableTo("Microsoft.AspNetCore.Mvc.FromFormAttribute"); + dynamic fromRouteAttribute = attributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromRouteAttribute"); + dynamic fromHeaderAttribute = attributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); + dynamic fromFormAttribute = attributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromFormAttribute"); - var fromBodyAttribute = attributes.TryGetIfAssignableTo("FromBodyAttribute", TypeNameStyle.Name); - var fromUriAttribute = attributes.TryGetIfAssignableTo("FromUriAttribute", TypeNameStyle.Name) ?? - attributes.TryGetIfAssignableTo("FromQueryAttribute", TypeNameStyle.Name); + var fromBodyAttribute = attributes.TryGetAssignableToTypeName("FromBodyAttribute", TypeNameStyle.Name); + var fromUriAttribute = attributes.TryGetAssignableToTypeName("FromUriAttribute", TypeNameStyle.Name) ?? + attributes.TryGetAssignableToTypeName("FromQueryAttribute", TypeNameStyle.Name); string bodyParameterName = fromBodyAttribute.TryGetPropertyValue("Name") ?? parameterName; string uriParameterName = fromUriAttribute.TryGetPropertyValue("Name") ?? parameterName; @@ -80,7 +81,7 @@ public async Task ProcessAsync(OperationProcessorContext context) } else { - var parameterInfo = _settings.ReflectionService.GetDescription(parameter.ParameterType, parameter.GetCustomAttributes(), _settings); + var parameterInfo = _settings.ReflectionService.GetDescription(parameter.ToContextualParameter(), _settings); operationParameter = await TryAddFileParameterAsync(context, parameterInfo, parameter).ConfigureAwait(false); if (operationParameter == null) @@ -117,12 +118,12 @@ public async Task ProcessAsync(OperationProcessorContext context) if (parameterInfo.IsComplexType) { // Check for a custom ParameterBindingAttribute (OWIN/WebAPI only) - var parameterBindingAttribute = attributes.TryGetIfAssignableTo("ParameterBindingAttribute", TypeNameStyle.Name); + var parameterBindingAttribute = attributes.TryGetAssignableToTypeName("ParameterBindingAttribute", TypeNameStyle.Name); if (parameterBindingAttribute != null && fromBodyAttribute == null && fromUriAttribute == null && !_settings.IsAspNetCore) { // Try to find a [WillReadBody] attribute on either the action parameter or the bindingAttribute's class var willReadBodyAttribute = attributes.Concat(parameterBindingAttribute.GetType().GetTypeInfo().GetCustomAttributes()) - .TryGetIfAssignableTo("WillReadBodyAttribute", TypeNameStyle.Name); + .TryGetAssignableToTypeName("WillReadBodyAttribute", TypeNameStyle.Name); if (willReadBodyAttribute == null) operationParameter = await AddBodyParameterAsync(context, bodyParameterName, parameter).ConfigureAwait(false); @@ -229,7 +230,7 @@ private async Task TryAddFileParameterAsync( .Union(parameter.ParameterType.GetTypeInfo().GetCustomAttributes()); var hasSwaggerFileAttribute = attributes.Any(a => - a.GetType().IsAssignableTo("SwaggerFileAttribute", TypeNameStyle.Name)); + a.GetType().IsAssignableToTypeName("SwaggerFileAttribute", TypeNameStyle.Name)); if (typeInfo.Type == JsonObjectType.File || typeInfo.Format == JsonFormatStrings.Binary || @@ -244,12 +245,12 @@ private async Task TryAddFileParameterAsync( private async Task AddFileParameterAsync(OperationProcessorContext context, ParameterInfo parameter, bool isFileArray) { - var attributes = parameter.GetCustomAttributes().ToList(); + var contextualParameter = parameter.ToContextualParameter(); // TODO: Check if there is a way to control the property name - var parameterDocumentation = await parameter.GetDescriptionAsync(parameter.GetCustomAttributes()).ConfigureAwait(false); + var parameterDocumentation = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false); var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync( - parameter.Name, parameterDocumentation, parameter.ParameterType, attributes).ConfigureAwait(false); + parameter.Name, parameterDocumentation, parameter.ParameterType, contextualParameter.ContextAttributes).ConfigureAwait(false); InitializeFileParameter(operationParameter, isFileArray); context.OperationDescription.Operation.Parameters.Add(operationParameter); @@ -266,8 +267,8 @@ private bool IsFileArray(Type type, JsonTypeDescription typeInfo) if (typeInfo.Type == JsonObjectType.Array && type.GenericTypeArguments.Any()) { - var description = _settings.ReflectionService.GetDescription(type.GenericTypeArguments[0], null, _settings); - if (description.Type == JsonObjectType.File || + var description = _settings.ReflectionService.GetDescription(type.ToContextualType(), _settings); + if (description.Type == JsonObjectType.File || description.Format == JsonFormatStrings.Binary) { return true; @@ -280,13 +281,14 @@ private bool IsFileArray(Type type, JsonTypeDescription typeInfo) private async Task AddBodyParameterAsync(OperationProcessorContext context, string name, ParameterInfo parameter) { SwaggerParameter operationParameter; + var contextualParameter = parameter.ToContextualParameter(); var attributes = parameter.GetCustomAttributes(); - var typeDescription = _settings.ReflectionService.GetDescription(parameter.ParameterType, attributes, _settings); + var typeDescription = _settings.ReflectionService.GetDescription(contextualParameter, _settings); var isNullable = _settings.AllowNullableBodyParameters && typeDescription.IsNullable; var operation = context.OperationDescription.Operation; - if (parameter.ParameterType.Name == "XmlDocument" || parameter.ParameterType.InheritsFrom("XmlDocument", TypeNameStyle.Name)) + if (parameter.ParameterType.Name == "XmlDocument" || parameter.ParameterType.InheritsFromTypeName("XmlDocument", TypeNameStyle.Name)) { operation.TryAddConsumes("application/xml"); operationParameter = new SwaggerParameter @@ -300,11 +302,11 @@ private async Task AddBodyParameterAsync(OperationProcessorCon }, IsNullableRaw = isNullable, IsRequired = parameter.HasDefaultValue == false, - Description = await parameter.GetDescriptionAsync(parameter.GetCustomAttributes()).ConfigureAwait(false) + Description = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false) }; operation.Parameters.Add(operationParameter); } - else if (parameter.ParameterType.IsAssignableTo("System.IO.Stream", TypeNameStyle.FullName)) + else if (parameter.ParameterType.IsAssignableToTypeName("System.IO.Stream", TypeNameStyle.FullName)) { operation.TryAddConsumes("application/octet-stream"); operationParameter = new SwaggerParameter @@ -319,7 +321,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon }, IsNullableRaw = isNullable, IsRequired = parameter.HasDefaultValue == false, - Description = await parameter.GetDescriptionAsync(parameter.GetCustomAttributes()).ConfigureAwait(false) + Description = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false) }; operation.Parameters.Add(operationParameter); } @@ -331,9 +333,9 @@ private async Task AddBodyParameterAsync(OperationProcessorCon Kind = SwaggerParameterKind.Body, IsRequired = true, // FromBody parameters are always required IsNullableRaw = isNullable, - Description = await parameter.GetDescriptionAsync(attributes).ConfigureAwait(false), + Description = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false), Schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( - parameter.ParameterType, parameter.GetCustomAttributes(), isNullable, schemaResolver: context.SchemaResolver).ConfigureAwait(false) + contextualParameter, isNullable, schemaResolver: context.SchemaResolver).ConfigureAwait(false) }; operation.Parameters.Add(operationParameter); } @@ -343,12 +345,14 @@ private async Task AddBodyParameterAsync(OperationProcessorCon private async Task AddPrimitiveParametersFromUriAsync(OperationProcessorContext context, string httpPath, string name, ParameterInfo parameter, JsonTypeDescription typeDescription) { + var contextualParameter = parameter.ToContextualParameter(); var operation = context.OperationDescription.Operation; + if (typeDescription.Type.HasFlag(JsonObjectType.Array)) { var attributes = parameter.GetCustomAttributes(); - var parameterDocumentation = await parameter.GetDescriptionAsync(attributes).ConfigureAwait(false); + var parameterDocumentation = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false); var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync( name, parameterDocumentation, parameter.ParameterType, attributes).ConfigureAwait(false); @@ -381,7 +385,7 @@ private async Task AddPrimitiveParametersFromUriAsync(Operatio // TODO: Check if required can be controlled with mechanisms other than RequiredAttribute - var parameterInfo = _settings.ReflectionService.GetDescription(property.PropertyType, attributes, _settings); + var parameterInfo = _settings.ReflectionService.GetDescription(property.ToContextualProperty(), _settings); var isFileArray = IsFileArray(property.PropertyType, parameterInfo); if (parameterInfo.Type == JsonObjectType.File || isFileArray) diff --git a/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs b/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs index f49f9bdc74..f3d8dddc7b 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs @@ -12,6 +12,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors; @@ -50,8 +51,8 @@ public static IEnumerable GetControllerClasses(Assembly assembly) return assembly.ExportedTypes .Where(t => t.GetTypeInfo().IsAbstract == false) .Where(t => t.Name.EndsWith("Controller") || - t.InheritsFrom("ApiController", TypeNameStyle.Name) || - t.InheritsFrom("ControllerBase", TypeNameStyle.Name)) // in ASP.NET Core, a Web API controller inherits from Controller + t.InheritsFromTypeName("ApiController", TypeNameStyle.Name) || + t.InheritsFromTypeName("ControllerBase", TypeNameStyle.Name)) // in ASP.NET Core, a Web API controller inherits from Controller .Where(t => t.GetTypeInfo().ImplementedInterfaces.All(i => i.FullName != "System.Web.Mvc.IController")) // no MVC controllers (legacy ASP.NET) .Where(t => { @@ -165,7 +166,7 @@ private async Task GenerateForControllerAsync(SwaggerDocument document, Ty operations.Any(o => o.Item1.Path == httpPath && o.Item1.Method == httpMethod && o.Item2.DeclaringType != currentControllerType && - o.Item2.DeclaringType.IsAssignableTo(currentControllerType.FullName, TypeNameStyle.FullName)); + o.Item2.DeclaringType.IsAssignableToTypeName(currentControllerType.FullName, TypeNameStyle.FullName)); if (isPathAlreadyDefinedInInheritanceHierarchy == false) { @@ -240,11 +241,11 @@ private async Task RunOperationProcessorsAsync(SwaggerDocument document, T .GetCustomAttributes() // 3. Run from method attributes .Concat(methodInfo.GetCustomAttributes()) - .Where(a => a.GetType().IsAssignableTo("SwaggerOperationProcessorAttribute", TypeNameStyle.Name)); + .Where(a => a.GetType().IsAssignableToTypeName("SwaggerOperationProcessorAttribute", TypeNameStyle.Name)); foreach (dynamic attribute in operationProcessorAttribute) { - var operationProcessor = ReflectionExtensions.HasProperty(attribute, "Parameters") ? + var operationProcessor = ObjectExtensions.HasProperty(attribute, "Parameters") ? (IOperationProcessor)Activator.CreateInstance(attribute.Type, attribute.Parameters) : (IOperationProcessor)Activator.CreateInstance(attribute.Type); diff --git a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj index e3c3ac5d3f..3565ee2ae3 100644 --- a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj +++ b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj @@ -22,12 +22,12 @@ - + \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration/Processors/ApiVersionProcessor.cs b/src/NSwag.SwaggerGeneration/Processors/ApiVersionProcessor.cs index 63825e4547..336470547e 100644 --- a/src/NSwag.SwaggerGeneration/Processors/ApiVersionProcessor.cs +++ b/src/NSwag.SwaggerGeneration/Processors/ApiVersionProcessor.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors.Contexts; @@ -98,7 +99,7 @@ private string[] GetVersions(OperationProcessorContext context, string attribute var versionAttributes = context.MethodInfo.GetCustomAttributes() .Concat(context.MethodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes()) .Concat(context.ControllerType.GetTypeInfo().GetCustomAttributes(true)) - .Where(a => a.GetType().IsAssignableTo(attributeType, TypeNameStyle.Name) && a.HasProperty("Versions")) + .Where(a => a.GetType().IsAssignableToTypeName(attributeType, TypeNameStyle.Name) && a.HasProperty("Versions")) .SelectMany((dynamic a) => ((IEnumerable)a.Versions).OfType().Select(v => v.ToString())) .ToArray(); diff --git a/src/NSwag.SwaggerGeneration/Processors/DocumentExtensionDataProcessor.cs b/src/NSwag.SwaggerGeneration/Processors/DocumentExtensionDataProcessor.cs index 8acac8e7ec..e902779350 100644 --- a/src/NSwag.SwaggerGeneration/Processors/DocumentExtensionDataProcessor.cs +++ b/src/NSwag.SwaggerGeneration/Processors/DocumentExtensionDataProcessor.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors.Contexts; @@ -32,7 +33,7 @@ public Task ProcessAsync(DocumentProcessorContext context) foreach (var extensionDataAttribute in from type in context.AllControllerTypes from extensionDataAttribute in type.GetTypeInfo().GetCustomAttributes(true) - .Where(a => a.GetType().IsAssignableTo("SwaggerExtensionDataAttribute", TypeNameStyle.Name)) + .Where(a => a.GetType().IsAssignableToTypeName("SwaggerExtensionDataAttribute", TypeNameStyle.Name)) select (dynamic)extensionDataAttribute) { string key = extensionDataAttribute.Key; diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationExtensionDataProcessor.cs b/src/NSwag.SwaggerGeneration/Processors/OperationExtensionDataProcessor.cs index 58fa6551cc..72b88b9ff8 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationExtensionDataProcessor.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationExtensionDataProcessor.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors.Contexts; @@ -34,7 +35,7 @@ public Task ProcessAsync(OperationProcessorContext context) foreach (var extensionDataAttribute in from extensionDataAttribute in context.MethodInfo.GetCustomAttributes() - .Where(a => a.GetType().IsAssignableTo("SwaggerExtensionDataAttribute", TypeNameStyle.Name)) + .Where(a => a.GetType().IsAssignableToTypeName("SwaggerExtensionDataAttribute", TypeNameStyle.Name)) select (dynamic)extensionDataAttribute) { string key = extensionDataAttribute.Key; @@ -53,7 +54,7 @@ in context.MethodInfo.GetCustomAttributes() foreach (var extensionDataAttribute in from extensionDataAttribute in parameter.Key.GetCustomAttributes(true) - .Where(a => a.GetType().IsAssignableTo("SwaggerExtensionDataAttribute", TypeNameStyle.Name)) + .Where(a => a.GetType().IsAssignableToTypeName("SwaggerExtensionDataAttribute", TypeNameStyle.Name)) select (dynamic)extensionDataAttribute) { string key = extensionDataAttribute.Key; diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index a4b46ff7e9..f7113fc899 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -12,6 +12,7 @@ using System.Reflection; using System.Threading.Tasks; using System.Xml.Linq; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors.Contexts; @@ -42,33 +43,15 @@ public async Task ProcessResponseTypeAttributes(OperationProcessorContext operat { var returnParameter = operationProcessorContext.MethodInfo.ReturnParameter; - var returnParameterAttributes = GetParameterAttributes(returnParameter); - var successResponseDescription = await returnParameter.GetDescriptionAsync(returnParameterAttributes) + var successResponseDescription = await returnParameter + .ToContextualParameter() + .GetDescriptionAsync() .ConfigureAwait(false) ?? string.Empty; var responseDescriptions = GetOperationResponseDescriptions(responseTypeAttributes, successResponseDescription); await ProcessOperationDescriptionsAsync(responseDescriptions, returnParameter, operationProcessorContext, successResponseDescription); } - /// Gets all attributes of the given parameter. - /// The parameter. - /// The attributes. - protected IEnumerable GetParameterAttributes(ParameterInfo parameter) - { - try - { - return parameter?.GetCustomAttributes(true)?.Cast() ?? - parameter?.GetCustomAttributes(false)?.Cast() ?? - new Attribute[0]; - } - catch - { - // in some environments, the call to GetCustomAttributes(true) fails - return parameter?.GetCustomAttributes(false)?.Cast() ?? - new Attribute[0]; - } - } - /// Updates the response description based on the return parameter or the response tags in the method's xml docs. /// The context. /// The task. @@ -77,7 +60,9 @@ protected async Task UpdateResponseDescriptionAsync(OperationProcessorContext op var returnParameter = operationProcessorContext.MethodInfo.ReturnParameter; var operationXmlDocs = await operationProcessorContext.MethodInfo.GetXmlDocumentationAsync(); var operationXmlDocsNodes = operationXmlDocs?.Nodes()?.OfType(); - var returnParameterXmlDocs = await returnParameter.GetDescriptionAsync(returnParameter.GetCustomAttributes(false).Cast()) + var returnParameterXmlDocs = await returnParameter + .ToContextualParameter() + .GetDescriptionAsync() .ConfigureAwait(false) ?? string.Empty; if (!string.IsNullOrEmpty(returnParameterXmlDocs) || operationXmlDocsNodes?.Any() == true) @@ -152,12 +137,14 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable r.StatusCode)) { var httpStatusCode = statusCodeGroup.Key; - var returnType = statusCodeGroup.Select(r => r.ResponseType).FindCommonBaseType(); + + var returnType = statusCodeGroup.Select(r => r.ResponseType).GetCommonBaseType(); + var contextualReturnType = returnType.ToContextualType(returnParameter.GetCustomAttributes(false).OfType()); + var description = string.Join("\nor\n", statusCodeGroup.Select(r => r.Description)); var typeDescription = _settings.ReflectionService.GetDescription( - returnType, GetParameterAttributes(returnParameter), - _settings.DefaultResponseReferenceTypeNullHandling, _settings); + contextualReturnType, _settings.DefaultResponseReferenceTypeNullHandling, _settings); var response = new SwaggerResponse { @@ -171,7 +158,7 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable(returnType, null, isNullable, context.SchemaResolver) + .GenerateWithReferenceAndNullabilityAsync(contextualReturnType, isNullable, context.SchemaResolver) .ConfigureAwait(false); } @@ -188,9 +175,9 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable a.GetType().IsAssignableTo("SwaggerDefaultResponseAttribute", TypeNameStyle.Name)) || + .Any(a => a.GetType().IsAssignableToTypeName("SwaggerDefaultResponseAttribute", TypeNameStyle.Name)) || context.MethodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes() - .Any(a => a.GetType().IsAssignableTo("SwaggerDefaultResponseAttribute", TypeNameStyle.Name)); + .Any(a => a.GetType().IsAssignableToTypeName("SwaggerDefaultResponseAttribute", TypeNameStyle.Name)); } else { @@ -210,9 +197,11 @@ private async Task> GenerateExpectedSchemasAsync var expectedSchemas = new List(); foreach (var response in group) { - var isNullable = _settings.ReflectionService.GetDescription(response.ResponseType, null, _settings).IsNullable; + var contextualResponseType = response.ResponseType.ToContextualType(); + + var isNullable = _settings.ReflectionService.GetDescription(contextualResponseType, _settings).IsNullable; var schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( - response.ResponseType, null, isNullable, context.SchemaResolver) + contextualResponseType, isNullable, context.SchemaResolver) .ConfigureAwait(false); expectedSchemas.Add(new JsonExpectedSchema @@ -245,10 +234,11 @@ private async Task LoadDefaultSuccessResponseAsync(ParameterInfo returnParameter } else { - var returnParameterAttributes = GetParameterAttributes(returnParameter); - var typeDescription = _settings.ReflectionService.GetDescription(returnType, returnParameterAttributes, _settings); + var contextualReturnParameter = returnType.ToContextualType(returnParameter.GetCustomAttributes(false).OfType()); + + var typeDescription = _settings.ReflectionService.GetDescription(contextualReturnParameter, _settings); var responseSchema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( - returnType, returnParameterAttributes, typeDescription.IsNullable, context.SchemaResolver).ConfigureAwait(false); + contextualReturnParameter, typeDescription.IsNullable, context.SchemaResolver).ConfigureAwait(false); operation.Responses["200"] = new SwaggerResponse { diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs b/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs index c1c2b24cf7..5d44d0691f 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors; using NSwag.SwaggerGeneration.Processors.Contexts; @@ -27,7 +28,9 @@ public async Task ProcessAsync(OperationProcessorContext context) .SingleOrDefault(a => a.GetType().Name == "DescriptionAttribute"); if (descriptionAttribute != null) + { context.OperationDescription.Operation.Summary = descriptionAttribute.Description; + } else { var summary = await context.MethodInfo.GetXmlSummaryAsync().ConfigureAwait(false); @@ -37,7 +40,9 @@ public async Task ProcessAsync(OperationProcessorContext context) var remarks = await context.MethodInfo.GetXmlRemarksAsync().ConfigureAwait(false); if (remarks != string.Empty) + { context.OperationDescription.Operation.Description = remarks; + } return true; } diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationTagsProcessor.cs b/src/NSwag.SwaggerGeneration/Processors/OperationTagsProcessor.cs index a8066c9618..0f049d5faa 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationTagsProcessor.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationTagsProcessor.cs @@ -10,6 +10,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema.Infrastructure; using NSwag.SwaggerGeneration.Processors.Contexts; @@ -27,7 +28,9 @@ public Task ProcessAsync(OperationProcessorContext context) ProcessSwaggerTagAttributes(context.Document, context.OperationDescription, context.MethodInfo); if (!context.OperationDescription.Operation.Tags.Any()) + { AddControllerNameTag(context); + } return Task.FromResult(true); } @@ -38,7 +41,9 @@ protected virtual void AddControllerNameTag(OperationProcessorContext context) { var controllerName = context.ControllerType.Name; if (controllerName.EndsWith("Controller")) + { controllerName = controllerName.Substring(0, controllerName.Length - 10); + } context.OperationDescription.Operation.Tags.Add(controllerName); } @@ -50,10 +55,14 @@ private void ProcessSwaggerTagAttributes(SwaggerDocument document, SwaggerOperat .Select(a => (dynamic)a)) { if (operationDescription.Operation.Tags.All(t => t != tagAttribute.Name)) + { operationDescription.Operation.Tags.Add(tagAttribute.Name); + } - if (ReflectionExtensions.HasProperty(tagAttribute, "AddToDocument") && tagAttribute.AddToDocument) + if (ObjectExtensions.HasProperty(tagAttribute, "AddToDocument") && tagAttribute.AddToDocument) + { DocumentTagsProcessor.AddTagFromSwaggerTagAttribute(document, tagAttribute); + } } } @@ -69,15 +78,21 @@ private void ProcessSwaggerTagsAttribute(SwaggerDocument document, SwaggerOperat foreach (var tag in tags) { if (operationDescription.Operation.Tags.All(t => t != tag)) + { operationDescription.Operation.Tags.Add(tag); + } - if (ReflectionExtensions.HasProperty(tagsAttribute, "AddToDocument") && tagsAttribute.AddToDocument) + if (ObjectExtensions.HasProperty(tagsAttribute, "AddToDocument") && tagsAttribute.AddToDocument) { if (document.Tags == null) + { document.Tags = new List(); + } if (document.Tags.All(t => t.Name != tag)) + { document.Tags.Add(new SwaggerTag { Name = tag }); + } } } } diff --git a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs index 6ccb45b0f1..16a472d7ad 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs @@ -11,6 +11,7 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Generation; using NJsonSchema.Infrastructure; @@ -70,9 +71,8 @@ public SwaggerParameter CreateUntypedPathParameter(string parameterName, string /// The parameter. public async Task CreatePrimitiveParameterAsync(string name, ParameterInfo parameter) { - var attributes = parameter.GetCustomAttributes(); - var documentation = await parameter.GetDescriptionAsync(attributes).ConfigureAwait(false); - return await CreatePrimitiveParameterAsync(name, documentation, parameter.ParameterType, attributes) + var documentation = await parameter.ToContextualParameter().GetDescriptionAsync().ConfigureAwait(false); + return await CreatePrimitiveParameterAsync(name, documentation, parameter.ParameterType, parameter.GetCustomAttributes(false).OfType()) .ConfigureAwait(false); } @@ -87,11 +87,12 @@ public async Task CreatePrimitiveParameterAsync( { SwaggerParameter operationParameter; - var typeDescription = _settings.ReflectionService.GetDescription(parameterType, parentAttributes, _settings); + var contextualParameterType = parameterType.ToContextualType(parentAttributes); + var typeDescription = _settings.ReflectionService.GetDescription(contextualParameterType, _settings); if (typeDescription.RequiresSchemaReference(_settings.TypeMappers)) { var schema = await _schemaGenerator - .GenerateAsync(parameterType, parentAttributes, _schemaResolver) + .GenerateAsync(contextualParameterType, _schemaResolver) .ConfigureAwait(false); operationParameter = new SwaggerParameter(); @@ -128,7 +129,7 @@ public async Task CreatePrimitiveParameterAsync( if (_settings.SchemaType == SchemaType.Swagger2) { operationParameter = await _schemaGenerator - .GenerateAsync(parameterType, parentAttributes, _schemaResolver) + .GenerateAsync(contextualParameterType, _schemaResolver) .ConfigureAwait(false); } else @@ -137,14 +138,14 @@ public async Task CreatePrimitiveParameterAsync( { Schema = await _schemaGenerator .GenerateWithReferenceAndNullabilityAsync( - parameterType, parentAttributes, typeDescription.IsNullable, _schemaResolver) + contextualParameterType, typeDescription.IsNullable, _schemaResolver) .ConfigureAwait(false) }; } } operationParameter.Name = name; - operationParameter.IsRequired = parentAttributes.TryGetIfAssignableTo("RequiredAttribute", TypeNameStyle.Name) != null; + operationParameter.IsRequired = parentAttributes.TryGetAssignableToTypeName("RequiredAttribute", TypeNameStyle.Name) != null; if (typeDescription.Type.HasFlag(JsonObjectType.Array)) operationParameter.CollectionFormat = SwaggerParameterCollectionFormat.Multi; diff --git a/src/NSwag.SwaggerGeneration/SwaggerGeneratorSettings.cs b/src/NSwag.SwaggerGeneration/SwaggerGeneratorSettings.cs index f7bc65eee0..c4013d15a2 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerGeneratorSettings.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerGeneratorSettings.cs @@ -6,6 +6,7 @@ // Rico Suter, mail@rsuter.com //----------------------------------------------------------------------- +using Namotion.Reflection; using Newtonsoft.Json; using NJsonSchema; using NJsonSchema.Generation; diff --git a/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs b/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs index d8a25802bc..a7eae42a47 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Namotion.Reflection; using NJsonSchema; using NJsonSchema.Generation; using NJsonSchema.Infrastructure; @@ -56,26 +57,29 @@ protected override async Task GenerateObjectAsync(Type type, JsonTypeDescription /// Generetes a schema directly or referenced for the requested schema type; also adds nullability if required. /// The resulted schema type which may reference the actual schema. - /// The type of the schema to generate. - /// The parent attributes (e.g. property or paramter attributes). + /// The type of the schema to generate. /// Specifies whether the property, parameter or requested schema type is nullable. /// The schema resolver. /// An action to transform the resulting schema (e.g. property or parameter) before the type of reference is determined (with $ref or allOf/oneOf). /// The requested schema object. public override async Task GenerateWithReferenceAndNullabilityAsync( - Type type, IEnumerable parentAttributes, bool isNullable, + ContextualType contextualType, bool isNullable, JsonSchemaResolver schemaResolver, Func transformation = null) { - if (type.Name == "Task`1") - type = type.GenericTypeArguments[0]; - - if (type.Name == "JsonResult`1") - type = type.GenericTypeArguments[0]; - - if (type.Name == "ActionResult`1") - type = type.GenericTypeArguments[0]; + if (contextualType.TypeName == "Task`1") + { + contextualType = contextualType.OriginalGenericArguments[0]; + } + else if (contextualType.TypeName == "JsonResult`1") + { + contextualType = contextualType.OriginalGenericArguments[0]; + } + else if (contextualType.TypeName == "ActionResult`1") + { + contextualType = contextualType.OriginalGenericArguments[0]; + } - if (IsFileResponse(type)) + if (IsFileResponse(contextualType)) { if (Settings.SchemaType == SchemaType.Swagger2) { @@ -87,17 +91,17 @@ public override async Task GenerateWithReferenceAndNullabilityAsync } } - return await base.GenerateWithReferenceAndNullabilityAsync(type, parentAttributes, isNullable, schemaResolver, transformation); + return await base.GenerateWithReferenceAndNullabilityAsync(contextualType, isNullable, schemaResolver, transformation); } private bool IsFileResponse(Type returnType) { - return returnType.IsAssignableTo("FileResult", TypeNameStyle.Name) || + return returnType.IsAssignableToTypeName("FileResult", TypeNameStyle.Name) || returnType.Name == "IActionResult" || returnType.Name == "IHttpActionResult" || returnType.Name == "HttpResponseMessage" || - returnType.IsAssignableTo("ActionResult", TypeNameStyle.Name) || - returnType.InheritsFrom("HttpResponseMessage", TypeNameStyle.Name); + returnType.IsAssignableToTypeName("ActionResult", TypeNameStyle.Name) || + returnType.InheritsFromTypeName("HttpResponseMessage", TypeNameStyle.Name); } } } \ No newline at end of file diff --git a/src/switcher.json b/src/switcher.json index 2a88f4ff03..2af1c9550a 100644 --- a/src/switcher.json +++ b/src/switcher.json @@ -6,5 +6,135 @@ "NJsonSchema.CodeGeneration": "../../NJsonSchema/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj", "NJsonSchema.CodeGeneration.CSharp": "../../NJsonSchema/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj", "NJsonSchema.CodeGeneration.TypeScript": "../../NJsonSchema/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj" - } + }, + "restore": [ + { + "name": "NSwag.CodeGeneration", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + }, + { + "packageName": "NJsonSchema.CodeGeneration", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.Core", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.AspNet.Owin", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.AspNet.WebApi", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.SwaggerGeneration", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.CodeGeneration.CSharp", + "packages": [ + { + "packageName": "NJsonSchema.CodeGeneration.CSharp", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.CodeGeneration.TypeScript", + "packages": [ + { + "packageName": "NJsonSchema.CodeGeneration.TypeScript", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.SwaggerGeneration.WebApi", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.Core.Yaml", + "packages": [ + { + "packageName": "NJsonSchema.Yaml", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.SwaggerGeneration.AspNetCore", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.Commands", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + }, + { + "packageName": "NJsonSchema.Yaml", + "version": "9.14.1" + }, + { + "packageName": "NJsonSchema.CodeGeneration", + "version": "9.14.1" + }, + { + "packageName": "NJsonSchema.CodeGeneration.CSharp", + "version": "9.14.1" + }, + { + "packageName": "NJsonSchema.CodeGeneration.TypeScript", + "version": "9.14.1" + } + ] + }, + { + "name": "NSwag.AssemblyLoader", + "packages": [ + { + "packageName": "NJsonSchema", + "version": "9.14.1" + } + ] + } + ] } \ No newline at end of file From cf7a8e118c8f5bcf5ee1af8e010367a37e78ffbf Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 10:49:58 +0200 Subject: [PATCH 02/20] Fix comments --- .../Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs | 2 +- .../Processors/OperationResponseProcessor.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs b/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs index da23356795..bb48fa1c2a 100644 --- a/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs +++ b/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs @@ -55,7 +55,7 @@ public ReferenceTypeNullHandling DefaultReferenceTypeNullHandling set => Settings.DefaultReferenceTypeNullHandling = value; } - [Argument(Name = nameof(DefaultResponseReferenceTypeNullHandling), IsRequired = false, Description = "The default response reference type null handling (if NotNullAttribute and CanBeNullAttribute are missing, default: Null, Null or NotNull).")] + [Argument(Name = nameof(DefaultResponseReferenceTypeNullHandling), IsRequired = false, Description = "The default response reference type null handling (if NotNullAttribute and CanBeNullAttribute are missing, default: Default, Null or NotNull).")] public ReferenceTypeNullHandling DefaultResponseReferenceTypeNullHandling { get => Settings.DefaultResponseReferenceTypeNullHandling; diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs index 91f3a70e97..9973b440ea 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs @@ -77,7 +77,6 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso contextualReturnType, _settings.DefaultResponseReferenceTypeNullHandling, _settings); response.IsNullableRaw = typeDescription.IsNullable; - response.Schema = await context.SchemaGenerator .GenerateWithReferenceAndNullabilityAsync(contextualReturnType, typeDescription.IsNullable, context.SchemaResolver) .ConfigureAwait(false); From c7c02b8d524b51d9988f8f7efc1546a12c6bec4c Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 12:37:09 +0200 Subject: [PATCH 03/20] Use more contextual types --- .../Processors/OperationParameterProcessor.cs | 8 +- .../Processors/OperationParameterProcessor.cs | 153 ++++++++++-------- .../SwaggerGenerator.cs | 31 ++-- 3 files changed, 102 insertions(+), 90 deletions(-) diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index 67484079b6..5e1b0081fa 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -356,11 +356,11 @@ private async Task CreatePrimitiveParameterAsync( OperationProcessorContext context, ExtendedApiParameterDescription extendedApiParameter) { + var contextualParameter = extendedApiParameter.ParameterType.ToContextualType(extendedApiParameter.Attributes); + + var description = await extendedApiParameter.GetDocumentationAsync().ConfigureAwait(false); var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync( - extendedApiParameter.ApiParameter.Name, - await extendedApiParameter.GetDocumentationAsync().ConfigureAwait(false), - extendedApiParameter.ParameterType, - extendedApiParameter.Attributes).ConfigureAwait(false); + extendedApiParameter.ApiParameter.Name, description, contextualParameter).ConfigureAwait(false); if (extendedApiParameter.ParameterInfo?.HasDefaultValue == true) { diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index a5142e5feb..5c471f852e 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -44,21 +44,21 @@ public async Task ProcessAsync(OperationProcessorContext context) var parameters = context.MethodInfo.GetParameters().ToList(); var position = 1; - foreach (var parameter in parameters.Where(p => p.ParameterType != typeof(CancellationToken) && - p.GetCustomAttributes().All(a => a.GetType().Name != "SwaggerIgnoreAttribute") && - p.GetCustomAttributes().All(a => a.GetType().Name != "FromServicesAttribute") && - p.GetCustomAttributes().All(a => a.GetType().Name != "BindNeverAttribute"))) + foreach (var contextualParameter in parameters.Select(p => p.ToContextualParameter()) + .Where(p => p.Type != typeof(CancellationToken) && + p.ContextAttributes.All(a => a.GetType().Name != "SwaggerIgnoreAttribute") && + p.ContextAttributes.All(a => a.GetType().Name != "FromServicesAttribute") && + p.ContextAttributes.All(a => a.GetType().Name != "BindNeverAttribute"))) { - var parameterName = parameter.Name; - var attributes = parameter.GetCustomAttributes().ToList(); + var parameterName = contextualParameter.Name; - dynamic fromRouteAttribute = attributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromRouteAttribute"); - dynamic fromHeaderAttribute = attributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); - dynamic fromFormAttribute = attributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromFormAttribute"); + dynamic fromRouteAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromRouteAttribute"); + dynamic fromHeaderAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); + dynamic fromFormAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromFormAttribute"); - var fromBodyAttribute = attributes.TryGetAssignableToTypeName("FromBodyAttribute", TypeNameStyle.Name); - var fromUriAttribute = attributes.TryGetAssignableToTypeName("FromUriAttribute", TypeNameStyle.Name) ?? - attributes.TryGetAssignableToTypeName("FromQueryAttribute", TypeNameStyle.Name); + var fromBodyAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("FromBodyAttribute", TypeNameStyle.Name); + var fromUriAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("FromUriAttribute", TypeNameStyle.Name) ?? + contextualParameter.ContextAttributes.TryGetAssignableToTypeName("FromQueryAttribute", TypeNameStyle.Name); string bodyParameterName = fromBodyAttribute.TryGetPropertyValue("Name") ?? parameterName; string uriParameterName = fromUriAttribute.TryGetPropertyValue("Name") ?? parameterName; @@ -70,27 +70,29 @@ public async Task ProcessAsync(OperationProcessorContext context) if (lowerHttpPath.Contains("{" + uriParameterNameLower + "}") || lowerHttpPath.Contains("{" + uriParameterNameLower + ":")) // path parameter { - operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(uriParameterName, parameter).ConfigureAwait(false); + operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(uriParameterName, contextualParameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.Path; operationParameter.IsRequired = true; // Path is always required => property not needed if (_settings.SchemaType == SchemaType.Swagger2) + { operationParameter.IsNullableRaw = false; + } context.OperationDescription.Operation.Parameters.Add(operationParameter); } else { - var parameterInfo = _settings.ReflectionService.GetDescription(parameter.ToContextualParameter(), _settings); + var parameterInfo = _settings.ReflectionService.GetDescription(contextualParameter, _settings); - operationParameter = await TryAddFileParameterAsync(context, parameterInfo, parameter).ConfigureAwait(false); + operationParameter = await TryAddFileParameterAsync(context, parameterInfo, contextualParameter).ConfigureAwait(false); if (operationParameter == null) { if (fromRouteAttribute != null) { - parameterName = !string.IsNullOrEmpty(fromRouteAttribute.Name) ? fromRouteAttribute.Name : parameter.Name; + parameterName = !string.IsNullOrEmpty(fromRouteAttribute.Name) ? fromRouteAttribute.Name : contextualParameter.Name; - operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(parameterName, parameter).ConfigureAwait(false); + operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(parameterName, contextualParameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.Path; operationParameter.IsNullableRaw = false; operationParameter.IsRequired = true; @@ -99,16 +101,16 @@ public async Task ProcessAsync(OperationProcessorContext context) } else if (fromHeaderAttribute != null) { - parameterName = !string.IsNullOrEmpty(fromHeaderAttribute.Name) ? fromHeaderAttribute.Name : parameter.Name; + parameterName = !string.IsNullOrEmpty(fromHeaderAttribute.Name) ? fromHeaderAttribute.Name : contextualParameter.Name; - operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(parameterName, parameter).ConfigureAwait(false); + operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(parameterName, contextualParameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.Header; context.OperationDescription.Operation.Parameters.Add(operationParameter); } else if (fromFormAttribute != null) { - operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(parameterName, parameter).ConfigureAwait(false); + operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(parameterName, contextualParameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.FormData; context.OperationDescription.Operation.Parameters.Add(operationParameter); @@ -118,43 +120,52 @@ public async Task ProcessAsync(OperationProcessorContext context) if (parameterInfo.IsComplexType) { // Check for a custom ParameterBindingAttribute (OWIN/WebAPI only) - var parameterBindingAttribute = attributes.TryGetAssignableToTypeName("ParameterBindingAttribute", TypeNameStyle.Name); + var parameterBindingAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("ParameterBindingAttribute", TypeNameStyle.Name); if (parameterBindingAttribute != null && fromBodyAttribute == null && fromUriAttribute == null && !_settings.IsAspNetCore) { // Try to find a [WillReadBody] attribute on either the action parameter or the bindingAttribute's class - var willReadBodyAttribute = attributes.Concat(parameterBindingAttribute.GetType().GetTypeInfo().GetCustomAttributes()) + var willReadBodyAttribute = contextualParameter.ContextAttributes.Concat(parameterBindingAttribute.GetType().GetTypeInfo().GetCustomAttributes()) .TryGetAssignableToTypeName("WillReadBodyAttribute", TypeNameStyle.Name); if (willReadBodyAttribute == null) - operationParameter = await AddBodyParameterAsync(context, bodyParameterName, parameter).ConfigureAwait(false); + operationParameter = await AddBodyParameterAsync(context, bodyParameterName, contextualParameter).ConfigureAwait(false); else { // Try to get a boolean property value from the attribute which explicity tells us whether to read from the body // If no such property exists, then default to false since WebAPI's HttpParameterBinding.WillReadBody defaults to false var willReadBody = willReadBodyAttribute.TryGetPropertyValue("WillReadBody", true); if (willReadBody) - operationParameter = await AddBodyParameterAsync(context, bodyParameterName, parameter).ConfigureAwait(false); + operationParameter = await AddBodyParameterAsync(context, bodyParameterName, contextualParameter).ConfigureAwait(false); else { // If we are not reading from the body, then treat this as a primitive. // This may seem odd, but it allows for primitive -> custom complex-type bindings which are very common // In this case, the API author should use a TypeMapper to define the parameter - operationParameter = await AddPrimitiveParameterAsync(uriParameterName, context.OperationDescription.Operation, parameter, context.SwaggerGenerator).ConfigureAwait(false); + operationParameter = await AddPrimitiveParameterAsync(uriParameterName, context.OperationDescription.Operation, contextualParameter, context.SwaggerGenerator).ConfigureAwait(false); } } } else if (fromBodyAttribute != null || (fromUriAttribute == null && _settings.IsAspNetCore == false)) - operationParameter = await AddBodyParameterAsync(context, bodyParameterName, parameter).ConfigureAwait(false); + { + operationParameter = await AddBodyParameterAsync(context, bodyParameterName, contextualParameter).ConfigureAwait(false); + } else + { operationParameter = await AddPrimitiveParametersFromUriAsync( - context, httpPath, uriParameterName, parameter, parameterInfo).ConfigureAwait(false); + context, httpPath, uriParameterName, contextualParameter, parameterInfo).ConfigureAwait(false); + } } else { if (fromBodyAttribute != null) - operationParameter = await AddBodyParameterAsync(context, bodyParameterName, parameter).ConfigureAwait(false); + { + operationParameter = await AddBodyParameterAsync(context, bodyParameterName, contextualParameter).ConfigureAwait(false); + } else - operationParameter = await AddPrimitiveParameterAsync(uriParameterName, context.OperationDescription.Operation, parameter, context.SwaggerGenerator).ConfigureAwait(false); + { + operationParameter = await AddPrimitiveParameterAsync( + uriParameterName, context.OperationDescription.Operation, contextualParameter, context.SwaggerGenerator).ConfigureAwait(false); + } } } } @@ -170,7 +181,7 @@ public async Task ProcessAsync(OperationProcessorContext context) operationParameter.IsNullableRaw = null; } - ((Dictionary)context.Parameters)[parameter] = operationParameter; + ((Dictionary)context.Parameters)[contextualParameter.ParameterInfo] = operationParameter; } } @@ -222,35 +233,29 @@ private void RemoveUnusedPathParameters(SwaggerOperationDescription operationDes } private async Task TryAddFileParameterAsync( - OperationProcessorContext context, JsonTypeDescription typeInfo, ParameterInfo parameter) + OperationProcessorContext context, JsonTypeDescription typeInfo, ContextualParameterInfo contextualParameter) { - var isFileArray = IsFileArray(parameter.ParameterType, typeInfo); - - var attributes = parameter.GetCustomAttributes() - .Union(parameter.ParameterType.GetTypeInfo().GetCustomAttributes()); - - var hasSwaggerFileAttribute = attributes.Any(a => - a.GetType().IsAssignableToTypeName("SwaggerFileAttribute", TypeNameStyle.Name)); + var isFileArray = IsFileArray(contextualParameter.Type, typeInfo); + var hasSwaggerFileAttribute = contextualParameter.Attributes + .Any(a => a.GetType().IsAssignableToTypeName("SwaggerFileAttribute", TypeNameStyle.Name)); if (typeInfo.Type == JsonObjectType.File || typeInfo.Format == JsonFormatStrings.Binary || hasSwaggerFileAttribute || isFileArray) { - return await AddFileParameterAsync(context, parameter, isFileArray).ConfigureAwait(false); + return await AddFileParameterAsync(context, contextualParameter, isFileArray).ConfigureAwait(false); } return null; } - private async Task AddFileParameterAsync(OperationProcessorContext context, ParameterInfo parameter, bool isFileArray) + private async Task AddFileParameterAsync(OperationProcessorContext context, ContextualParameterInfo contextualParameter, bool isFileArray) { - var contextualParameter = parameter.ToContextualParameter(); - // TODO: Check if there is a way to control the property name var parameterDocumentation = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false); var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync( - parameter.Name, parameterDocumentation, parameter.ParameterType, contextualParameter.ContextAttributes).ConfigureAwait(false); + contextualParameter.Name, parameterDocumentation, contextualParameter).ConfigureAwait(false); InitializeFileParameter(operationParameter, isFileArray); context.OperationDescription.Operation.Parameters.Add(operationParameter); @@ -278,17 +283,15 @@ private bool IsFileArray(Type type, JsonTypeDescription typeInfo) return false; } - private async Task AddBodyParameterAsync(OperationProcessorContext context, string name, ParameterInfo parameter) + private async Task AddBodyParameterAsync(OperationProcessorContext context, string name, ContextualParameterInfo contextualParameter) { SwaggerParameter operationParameter; - var contextualParameter = parameter.ToContextualParameter(); - var attributes = parameter.GetCustomAttributes(); var typeDescription = _settings.ReflectionService.GetDescription(contextualParameter, _settings); var isNullable = _settings.AllowNullableBodyParameters && typeDescription.IsNullable; var operation = context.OperationDescription.Operation; - if (parameter.ParameterType.Name == "XmlDocument" || parameter.ParameterType.InheritsFromTypeName("XmlDocument", TypeNameStyle.Name)) + if (contextualParameter.TypeName == "XmlDocument" || contextualParameter.Type.InheritsFromTypeName("XmlDocument", TypeNameStyle.Name)) { operation.TryAddConsumes("application/xml"); operationParameter = new SwaggerParameter @@ -301,12 +304,12 @@ private async Task AddBodyParameterAsync(OperationProcessorCon IsNullableRaw = isNullable }, IsNullableRaw = isNullable, - IsRequired = parameter.HasDefaultValue == false, + IsRequired = contextualParameter.ParameterInfo.HasDefaultValue == false, Description = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false) }; operation.Parameters.Add(operationParameter); } - else if (parameter.ParameterType.IsAssignableToTypeName("System.IO.Stream", TypeNameStyle.FullName)) + else if (contextualParameter.Type.IsAssignableToTypeName("System.IO.Stream", TypeNameStyle.FullName)) { operation.TryAddConsumes("application/octet-stream"); operationParameter = new SwaggerParameter @@ -320,7 +323,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon IsNullableRaw = isNullable }, IsNullableRaw = isNullable, - IsRequired = parameter.HasDefaultValue == false, + IsRequired = contextualParameter.ParameterInfo.HasDefaultValue == false, Description = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false) }; operation.Parameters.Add(operationParameter); @@ -343,18 +346,16 @@ private async Task AddBodyParameterAsync(OperationProcessorCon return operationParameter; } - private async Task AddPrimitiveParametersFromUriAsync(OperationProcessorContext context, string httpPath, string name, ParameterInfo parameter, JsonTypeDescription typeDescription) + private async Task AddPrimitiveParametersFromUriAsync( + OperationProcessorContext context, string httpPath, string name, ContextualParameterInfo contextualParameter, JsonTypeDescription typeDescription) { - var contextualParameter = parameter.ToContextualParameter(); var operation = context.OperationDescription.Operation; if (typeDescription.Type.HasFlag(JsonObjectType.Array)) { - var attributes = parameter.GetCustomAttributes(); - var parameterDocumentation = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false); var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync( - name, parameterDocumentation, parameter.ParameterType, attributes).ConfigureAwait(false); + name, parameterDocumentation, contextualParameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.Query; operation.Parameters.Add(operationParameter); @@ -362,31 +363,33 @@ private async Task AddPrimitiveParametersFromUriAsync(Operatio } else { - foreach (var property in parameter.ParameterType.GetRuntimeProperties()) + foreach (var contextualProperty in contextualParameter.Type.GetContextualRuntimeProperties()) { - var attributes = property.GetCustomAttributes().ToList(); - if (attributes.All(a => a.GetType().Name != "SwaggerIgnoreAttribute" && a.GetType().Name != "JsonIgnoreAttribute")) + if (contextualProperty.ContextAttributes.All(a => a.GetType().Name != "SwaggerIgnoreAttribute" && a.GetType().Name != "JsonIgnoreAttribute")) { - var fromQueryAttribute = attributes.SingleOrDefault(a => a.GetType().Name == "FromQueryAttribute"); + var fromQueryAttribute = contextualProperty.ContextAttributes.SingleOrDefault(a => a.GetType().Name == "FromQueryAttribute"); var propertyName = fromQueryAttribute.TryGetPropertyValue("Name") ?? - context.SchemaGenerator.GetPropertyName(null, property); + context.SchemaGenerator.GetPropertyName(null, contextualProperty.MemberInfo); - dynamic fromRouteAttribute = attributes.SingleOrDefault(a => a.GetType().FullName == "Microsoft.AspNetCore.Mvc.FromRouteAttribute"); + dynamic fromRouteAttribute = contextualProperty.ContextAttributes.SingleOrDefault(a => a.GetType().FullName == "Microsoft.AspNetCore.Mvc.FromRouteAttribute"); if (fromRouteAttribute != null && !string.IsNullOrEmpty(fromRouteAttribute?.Name)) + { propertyName = fromRouteAttribute?.Name; + } - dynamic fromHeaderAttribute = attributes.SingleOrDefault(a => a.GetType().FullName == "Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); + dynamic fromHeaderAttribute = contextualProperty.ContextAttributes.SingleOrDefault(a => a.GetType().FullName == "Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); if (fromHeaderAttribute != null && !string.IsNullOrEmpty(fromHeaderAttribute?.Name)) + { propertyName = fromHeaderAttribute?.Name; + } - var propertySummary = await property.GetXmlSummaryAsync().ConfigureAwait(false); - var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync( - propertyName, propertySummary, property.PropertyType, attributes).ConfigureAwait(false); + var propertySummary = await contextualProperty.PropertyInfo.GetXmlSummaryAsync().ConfigureAwait(false); + var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(propertyName, propertySummary, contextualProperty).ConfigureAwait(false); // TODO: Check if required can be controlled with mechanisms other than RequiredAttribute - var parameterInfo = _settings.ReflectionService.GetDescription(property.ToContextualProperty(), _settings); - var isFileArray = IsFileArray(property.PropertyType, parameterInfo); + var parameterInfo = _settings.ReflectionService.GetDescription(contextualProperty, _settings); + var isFileArray = IsFileArray(contextualProperty.Type, parameterInfo); if (parameterInfo.Type == JsonObjectType.File || isFileArray) { @@ -401,9 +404,13 @@ private async Task AddPrimitiveParametersFromUriAsync(Operatio operationParameter.IsRequired = true; // Path is always required => property not needed } else if (fromHeaderAttribute != null) + { operationParameter.Kind = SwaggerParameterKind.Header; + } else + { operationParameter.Kind = SwaggerParameterKind.Query; + } operation.Parameters.Add(operationParameter); } @@ -414,14 +421,16 @@ private async Task AddPrimitiveParametersFromUriAsync(Operatio } private async Task AddPrimitiveParameterAsync( - string name, SwaggerOperation operation, ParameterInfo parameter, SwaggerGenerator swaggerGenerator) + string name, SwaggerOperation operation, ContextualParameterInfo parameter, SwaggerGenerator swaggerGenerator) { var operationParameter = await swaggerGenerator.CreatePrimitiveParameterAsync(name, parameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.Query; - operationParameter.IsRequired = operationParameter.IsRequired || parameter.HasDefaultValue == false; + operationParameter.IsRequired = operationParameter.IsRequired || parameter.ParameterInfo.HasDefaultValue == false; - if (parameter.HasDefaultValue) - operationParameter.Default = parameter.DefaultValue; + if (parameter.ParameterInfo.HasDefaultValue) + { + operationParameter.Default = parameter.ParameterInfo.DefaultValue; + } operation.Parameters.Add(operationParameter); return operationParameter; @@ -433,7 +442,9 @@ private void InitializeFileParameter(SwaggerParameter operationParameter, bool i operationParameter.Kind = SwaggerParameterKind.FormData; if (isFileArray) + { operationParameter.CollectionFormat = SwaggerParameterCollectionFormat.Multi; + } } } } diff --git a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs index 16a472d7ad..d8cf154c01 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs @@ -67,32 +67,29 @@ public SwaggerParameter CreateUntypedPathParameter(string parameterName, string /// Creates a primitive parameter for the given parameter information reflection object. /// The name. - /// The parameter information. + /// The parameter. /// The parameter. - public async Task CreatePrimitiveParameterAsync(string name, ParameterInfo parameter) + public async Task CreatePrimitiveParameterAsync(string name, ContextualParameterInfo contextualParameter) { - var documentation = await parameter.ToContextualParameter().GetDescriptionAsync().ConfigureAwait(false); - return await CreatePrimitiveParameterAsync(name, documentation, parameter.ParameterType, parameter.GetCustomAttributes(false).OfType()) - .ConfigureAwait(false); + var documentation = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false); + return await CreatePrimitiveParameterAsync(name, documentation, contextualParameter).ConfigureAwait(false); } /// Creates a primitive parameter for the given parameter information reflection object. /// The name. /// The description. - /// Type of the parameter. - /// The parent attributes. + /// Type of the parameter. /// The parameter. public async Task CreatePrimitiveParameterAsync( - string name, string description, Type parameterType, IEnumerable parentAttributes) + string name, string description, ContextualType contextualParameter) { SwaggerParameter operationParameter; - var contextualParameterType = parameterType.ToContextualType(parentAttributes); - var typeDescription = _settings.ReflectionService.GetDescription(contextualParameterType, _settings); + var typeDescription = _settings.ReflectionService.GetDescription(contextualParameter, _settings); if (typeDescription.RequiresSchemaReference(_settings.TypeMappers)) { var schema = await _schemaGenerator - .GenerateAsync(contextualParameterType, _schemaResolver) + .GenerateAsync(contextualParameter, _schemaResolver) .ConfigureAwait(false); operationParameter = new SwaggerParameter(); @@ -129,7 +126,7 @@ public async Task CreatePrimitiveParameterAsync( if (_settings.SchemaType == SchemaType.Swagger2) { operationParameter = await _schemaGenerator - .GenerateAsync(contextualParameterType, _schemaResolver) + .GenerateAsync(contextualParameter, _schemaResolver) .ConfigureAwait(false); } else @@ -138,23 +135,27 @@ public async Task CreatePrimitiveParameterAsync( { Schema = await _schemaGenerator .GenerateWithReferenceAndNullabilityAsync( - contextualParameterType, typeDescription.IsNullable, _schemaResolver) + contextualParameter, typeDescription.IsNullable, _schemaResolver) .ConfigureAwait(false) }; } } operationParameter.Name = name; - operationParameter.IsRequired = parentAttributes.TryGetAssignableToTypeName("RequiredAttribute", TypeNameStyle.Name) != null; + operationParameter.IsRequired = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("RequiredAttribute", TypeNameStyle.Name) != null; if (typeDescription.Type.HasFlag(JsonObjectType.Array)) + { operationParameter.CollectionFormat = SwaggerParameterCollectionFormat.Multi; + } operationParameter.IsNullableRaw = typeDescription.IsNullable; - _schemaGenerator.ApplyDataAnnotations(operationParameter, typeDescription, parentAttributes); + _schemaGenerator.ApplyDataAnnotations(operationParameter, typeDescription, contextualParameter.ContextAttributes); if (description != string.Empty) + { operationParameter.Description = description; + } return operationParameter; } From e6e66183cfe389b20809ef53e05cfd8b51bd040e Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 16:52:57 +0200 Subject: [PATCH 04/20] Refactor NJS types --- .../ControllerGenerationFormatTests.cs | 22 +++++++++---------- .../Models/CSharpClientTemplateModel.cs | 4 ++-- .../Models/CSharpOperationModel.cs | 2 +- .../Models/CSharpResponseModel.cs | 2 +- .../SwaggerToCSharpGeneratorBase.cs | 2 +- .../SwaggerToCSharpGeneratorSettings.cs | 18 +-------------- .../CodeGenerationTests.cs | 4 ++-- .../OperationParameterTests.cs | 1 + .../Models/TypeScriptOperationModel.cs | 2 +- .../Models/TypeScriptResponseModel.cs | 2 +- .../SwaggerToTypeScriptClientGenerator.cs | 2 +- .../TypeScriptTypeNameGenerator.cs | 2 +- .../ClientGeneratorBase.cs | 2 +- src/NSwag.CodeGeneration/IClientGenerator.cs | 2 +- .../JsonSchemaExtensions.cs | 6 ++--- .../Models/OperationModelBase.cs | 6 ++--- .../Models/ParameterModelBase.cs | 2 +- .../Models/PropertyModel.cs | 4 ++-- .../Models/ResponseModelBase.cs | 8 +++---- .../JsonSchemaToSwaggerCommand.cs | 2 +- .../Commands/InputOutputCommandBase.cs | 8 +++---- .../Commands/IsolatedCommandBase.cs | 4 ++-- .../AspNetCore/AspNetCoreToSwaggerCommand.cs | 1 + .../SwaggerGeneratorCommandBase.cs | 1 + .../Commands/Tooling/VersionCommand.cs | 2 +- src/NSwag.Commands/NSwagCommandProcessor.cs | 2 +- .../ComponentsSerializationTests.cs | 6 ++--- .../MediaTypesSerializationTests.cs | 2 +- .../RequestBodySerializationTests.cs | 8 +++---- src/NSwag.Core/JsonExpectedSchema.cs | 2 +- src/NSwag.Core/OpenApiComponents.cs | 8 +++---- src/NSwag.Core/OpenApiMediaType.cs | 4 ++-- .../SwaggerDocument.Serialization.cs | 4 ++-- src/NSwag.Core/SwaggerHeaders.cs | 2 +- src/NSwag.Core/SwaggerParameter.cs | 10 ++++----- src/NSwag.Core/SwaggerResponse.cs | 4 ++-- src/NSwag.Core/SwaggerSchemaResolver.cs | 2 +- .../Responses/NullableResponseTests.cs | 1 + .../AspNetCoreToSwaggerGenerator.cs | 2 +- .../Processors/OperationParameterProcessor.cs | 6 ++--- .../Processors/OperationResponseProcessor.cs | 4 ++-- .../Processors/OperationParameterProcessor.cs | 6 ++--- .../WebApiToSwaggerGenerator.cs | 2 +- .../OperationResponseProcessorBase.cs | 6 ++--- .../SwaggerGenerator.cs | 10 ++++----- .../SwaggerJsonSchemaGenerator.cs | 4 ++-- 46 files changed, 97 insertions(+), 109 deletions(-) diff --git a/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs b/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs index 6238f0ef5e..af4bd23438 100644 --- a/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs +++ b/src/NSwag.CodeGeneration.CSharp.Tests/ControllerGenerationFormatTests.cs @@ -255,21 +255,21 @@ public async Task When_the_generation_of_dto_classes_are_disabled_then_file_is_g private async Task GetSwaggerDocument() { - JsonSchema4 complexTypeSchema = new JsonSchema4(); + JsonSchema complexTypeSchema = new JsonSchema(); complexTypeSchema.Title = "ComplexType"; - complexTypeSchema.Properties["Prop1"] = new JsonProperty { Type = JsonObjectType.String, IsRequired = true }; - complexTypeSchema.Properties["Prop2"] = new JsonProperty { Type = JsonObjectType.Integer, IsRequired = true }; - complexTypeSchema.Properties["Prop3"] = new JsonProperty { Type = JsonObjectType.Boolean, IsRequired = true }; - complexTypeSchema.Properties["Prop4"] = new JsonProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true }; + complexTypeSchema.Properties["Prop1"] = new JsonSchemaProperty { Type = JsonObjectType.String, IsRequired = true }; + complexTypeSchema.Properties["Prop2"] = new JsonSchemaProperty { Type = JsonObjectType.Integer, IsRequired = true }; + complexTypeSchema.Properties["Prop3"] = new JsonSchemaProperty { Type = JsonObjectType.Boolean, IsRequired = true }; + complexTypeSchema.Properties["Prop4"] = new JsonSchemaProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true }; - JsonSchema4 complexTypeReponseSchema = new JsonSchema4(); + JsonSchema complexTypeReponseSchema = new JsonSchema(); complexTypeReponseSchema.Title = "ComplexTypeResponse"; - complexTypeReponseSchema.Properties["Prop1"] = new JsonProperty { Type = JsonObjectType.String, IsRequired = true }; - complexTypeReponseSchema.Properties["Prop2"] = new JsonProperty { Type = JsonObjectType.Integer, IsRequired = true }; - complexTypeReponseSchema.Properties["Prop3"] = new JsonProperty { Type = JsonObjectType.Boolean, IsRequired = true }; - complexTypeReponseSchema.Properties["Prop4"] = new JsonProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true }; + complexTypeReponseSchema.Properties["Prop1"] = new JsonSchemaProperty { Type = JsonObjectType.String, IsRequired = true }; + complexTypeReponseSchema.Properties["Prop2"] = new JsonSchemaProperty { Type = JsonObjectType.Integer, IsRequired = true }; + complexTypeReponseSchema.Properties["Prop3"] = new JsonSchemaProperty { Type = JsonObjectType.Boolean, IsRequired = true }; + complexTypeReponseSchema.Properties["Prop4"] = new JsonSchemaProperty { Type = JsonObjectType.Object, Reference = complexTypeSchema, IsRequired = true }; - var typeString = await JsonSchema4.FromTypeAsync(typeof(string)); + var typeString = await JsonSchema.FromTypeAsync(typeof(string)); var document = new SwaggerDocument(); document.Paths["Foo"] = new SwaggerPathItem diff --git a/src/NSwag.CodeGeneration.CSharp/Models/CSharpClientTemplateModel.cs b/src/NSwag.CodeGeneration.CSharp/Models/CSharpClientTemplateModel.cs index be07927bbc..53e896c6d2 100644 --- a/src/NSwag.CodeGeneration.CSharp/Models/CSharpClientTemplateModel.cs +++ b/src/NSwag.CodeGeneration.CSharp/Models/CSharpClientTemplateModel.cs @@ -17,7 +17,7 @@ namespace NSwag.CodeGeneration.CSharp.Models public class CSharpClientTemplateModel : CSharpTemplateModelBase { private readonly SwaggerDocument _document; - private readonly JsonSchema4 _exceptionSchema; + private readonly JsonSchema _exceptionSchema; private readonly SwaggerToCSharpClientGeneratorSettings _settings; /// Initializes a new instance of the class. @@ -31,7 +31,7 @@ public CSharpClientTemplateModel( string controllerName, string controllerClassName, IEnumerable operations, - JsonSchema4 exceptionSchema, + JsonSchema exceptionSchema, SwaggerDocument document, SwaggerToCSharpClientGeneratorSettings settings) : base(controllerName, settings) diff --git a/src/NSwag.CodeGeneration.CSharp/Models/CSharpOperationModel.cs b/src/NSwag.CodeGeneration.CSharp/Models/CSharpOperationModel.cs index 9ae04be45f..613e21e9bb 100644 --- a/src/NSwag.CodeGeneration.CSharp/Models/CSharpOperationModel.cs +++ b/src/NSwag.CodeGeneration.CSharp/Models/CSharpOperationModel.cs @@ -243,7 +243,7 @@ protected override string ResolveParameterType(SwaggerParameter parameter) /// The resolver. /// The settings. /// - protected override CSharpResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings) + protected override CSharpResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings) { return new CSharpResponseModel(this, operation, statusCode, response, response == GetSuccessResponse().Value, exceptionSchema, generator, resolver, settings.CodeGeneratorSettings); } diff --git a/src/NSwag.CodeGeneration.CSharp/Models/CSharpResponseModel.cs b/src/NSwag.CodeGeneration.CSharp/Models/CSharpResponseModel.cs index 334466e343..b2fc1752eb 100644 --- a/src/NSwag.CodeGeneration.CSharp/Models/CSharpResponseModel.cs +++ b/src/NSwag.CodeGeneration.CSharp/Models/CSharpResponseModel.cs @@ -26,7 +26,7 @@ public class CSharpResponseModel : ResponseModelBase /// The resolver. /// The settings. public CSharpResponseModel(IOperationModel operationModel, SwaggerOperation operation, string statusCode, SwaggerResponse response, - bool isPrimarySuccessResponse, JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, CodeGeneratorSettingsBase settings) + bool isPrimarySuccessResponse, JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, CodeGeneratorSettingsBase settings) : base(operationModel, operation, statusCode, response, isPrimarySuccessResponse, exceptionSchema, resolver, settings, generator) { } diff --git a/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorBase.cs b/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorBase.cs index 5f4fe20979..1868eaef1e 100644 --- a/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorBase.cs +++ b/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorBase.cs @@ -39,7 +39,7 @@ protected SwaggerToCSharpGeneratorBase(SwaggerDocument document, SwaggerToCSharp /// Specifies whether the type is nullable.. /// The type name hint. /// The type name. - public override string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint) + public override string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint) { if (schema == null) return "void"; diff --git a/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorSettings.cs b/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorSettings.cs index 03ea93d093..6c13e6c2a2 100644 --- a/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorSettings.cs +++ b/src/NSwag.CodeGeneration.CSharp/SwaggerToCSharpGeneratorSettings.cs @@ -23,23 +23,7 @@ protected SwaggerToCSharpGeneratorSettings() CSharpGeneratorSettings = new CSharpGeneratorSettings { Namespace = "MyNamespace", - SchemaType = SchemaType.Swagger2, - - // TODO: Remove these defaults when NJS is updated with them - ClassStyle = CSharpClassStyle.Poco, - - DateType = "System.DateTimeOffset", - DateTimeType = "System.DateTimeOffset", - TimeType = "System.TimeSpan", - TimeSpanType = "System.TimeSpan", - - ArrayType = "System.Collections.Generic.ICollection", - ArrayInstanceType = "System.Collections.ObjectModel.Collection", - ArrayBaseType = "System.Collections.ObjectModel.Collection", - - DictionaryType = "System.Collections.Generic.IDictionary", - DictionaryInstanceType = "System.Collections.Generic.Dictionary", - DictionaryBaseType = "System.Collections.Generic.Dictionary" + SchemaType = SchemaType.Swagger2 }; CSharpGeneratorSettings.TemplateFactory = new DefaultTemplateFactory(CSharpGeneratorSettings, new[] diff --git a/src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs b/src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs index bef39f4d46..5b2b5f8bf5 100644 --- a/src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs +++ b/src/NSwag.CodeGeneration.Tests/CodeGenerationTests.cs @@ -88,7 +88,7 @@ public async Task When_using_json_schema_with_references_in_service_then_referen }"; //// Act - var schema = await JsonSchema4.FromJsonAsync(jsonSchema); + var schema = await JsonSchema.FromJsonAsync(jsonSchema); var document = new SwaggerDocument(); document.Definitions["Foo"] = schema; @@ -125,7 +125,7 @@ private static async Task CreateDocumentAsync() { "200", new SwaggerResponse { - Schema = new JsonSchema4 + Schema = new JsonSchema { Reference = await generator.GenerateAsync(typeof(Person), new SwaggerSchemaResolver(document, settings)) } diff --git a/src/NSwag.CodeGeneration.TypeScript.Tests/OperationParameterTests.cs b/src/NSwag.CodeGeneration.TypeScript.Tests/OperationParameterTests.cs index 79c176fe8a..47f67e95f2 100644 --- a/src/NSwag.CodeGeneration.TypeScript.Tests/OperationParameterTests.cs +++ b/src/NSwag.CodeGeneration.TypeScript.Tests/OperationParameterTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using NJsonSchema; +using NJsonSchema.Generation; using NSwag.SwaggerGeneration.WebApi; using Xunit; diff --git a/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptOperationModel.cs b/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptOperationModel.cs index f3b90223e6..5cca48ad3d 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptOperationModel.cs +++ b/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptOperationModel.cs @@ -185,7 +185,7 @@ protected override string ResolveParameterType(SwaggerParameter parameter) /// The settings. /// protected override TypeScriptResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, - JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings) + JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings) { return new TypeScriptResponseModel(this, operation, statusCode, response, response == GetSuccessResponse().Value, exceptionSchema, generator, resolver, (SwaggerToTypeScriptClientGeneratorSettings)settings); diff --git a/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptResponseModel.cs b/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptResponseModel.cs index fae1b25640..2d3f4516eb 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptResponseModel.cs +++ b/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptResponseModel.cs @@ -29,7 +29,7 @@ public class TypeScriptResponseModel : ResponseModelBase /// The resolver. /// The settings. public TypeScriptResponseModel(IOperationModel operationModel, SwaggerOperation operation, string statusCode, SwaggerResponse response, bool isPrimarySuccessResponse, - JsonSchema4 exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, SwaggerToTypeScriptClientGeneratorSettings settings) + JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, SwaggerToTypeScriptClientGeneratorSettings settings) : base(operationModel, operation, statusCode, response, isPrimarySuccessResponse, exceptionSchema, resolver, settings.TypeScriptGeneratorSettings, generator) { _settings = settings; diff --git a/src/NSwag.CodeGeneration.TypeScript/SwaggerToTypeScriptClientGenerator.cs b/src/NSwag.CodeGeneration.TypeScript/SwaggerToTypeScriptClientGenerator.cs index 4970f68c81..777a8c1135 100644 --- a/src/NSwag.CodeGeneration.TypeScript/SwaggerToTypeScriptClientGenerator.cs +++ b/src/NSwag.CodeGeneration.TypeScript/SwaggerToTypeScriptClientGenerator.cs @@ -63,7 +63,7 @@ public SwaggerToTypeScriptClientGenerator(SwaggerDocument document, SwaggerToTyp /// Specifies whether the type is nullable.. /// The type name hint. /// The type name. - public override string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint) + public override string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint) { if (schema == null) return "void"; diff --git a/src/NSwag.CodeGeneration.TypeScript/TypeScriptTypeNameGenerator.cs b/src/NSwag.CodeGeneration.TypeScript/TypeScriptTypeNameGenerator.cs index 528e58221d..0fb5e4437a 100644 --- a/src/NSwag.CodeGeneration.TypeScript/TypeScriptTypeNameGenerator.cs +++ b/src/NSwag.CodeGeneration.TypeScript/TypeScriptTypeNameGenerator.cs @@ -17,7 +17,7 @@ public class TypeScriptTypeNameGenerator : DefaultTypeNameGenerator /// The schema. /// The type name hint. /// The type name. - protected override string Generate(JsonSchema4 schema, string typeNameHint) + protected override string Generate(JsonSchema schema, string typeNameHint) { if (typeNameHint == "Error") typeNameHint = "ErrorDto"; diff --git a/src/NSwag.CodeGeneration/ClientGeneratorBase.cs b/src/NSwag.CodeGeneration/ClientGeneratorBase.cs index 637b0f78ce..0c2ad7ccc3 100644 --- a/src/NSwag.CodeGeneration/ClientGeneratorBase.cs +++ b/src/NSwag.CodeGeneration/ClientGeneratorBase.cs @@ -55,7 +55,7 @@ public virtual string GetBinaryResponseTypeName() /// Specifies whether the type is nullable.. /// The type name hint. /// The type name. - public abstract string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint); + public abstract string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint); /// Generates the the whole file containing all needed types. /// The code diff --git a/src/NSwag.CodeGeneration/IClientGenerator.cs b/src/NSwag.CodeGeneration/IClientGenerator.cs index ac3d4c77c8..99bd3713b7 100644 --- a/src/NSwag.CodeGeneration/IClientGenerator.cs +++ b/src/NSwag.CodeGeneration/IClientGenerator.cs @@ -18,7 +18,7 @@ public interface IClientGenerator /// Specifies whether the type is nullable.. /// The type name hint. /// The type name. - string GetTypeName(JsonSchema4 schema, bool isNullable, string typeNameHint); + string GetTypeName(JsonSchema schema, bool isNullable, string typeNameHint); /// Gets the file/binary response type name. /// The type name. diff --git a/src/NSwag.CodeGeneration/JsonSchemaExtensions.cs b/src/NSwag.CodeGeneration/JsonSchemaExtensions.cs index d7ccc1857f..32f2f10f46 100644 --- a/src/NSwag.CodeGeneration/JsonSchemaExtensions.cs +++ b/src/NSwag.CodeGeneration/JsonSchemaExtensions.cs @@ -18,12 +18,12 @@ public static class JsonSchema4Extensions /// Checks whether the schema uses an object schema somewhere (i.e. does it require a DTO class). /// The schema. /// true or false - public static bool UsesComplexObjectSchema(this JsonSchema4 schema) + public static bool UsesComplexObjectSchema(this JsonSchema schema) { - return UsesComplexObjectSchema(schema, new List()); + return UsesComplexObjectSchema(schema, new List()); } - private static bool UsesComplexObjectSchema(this JsonSchema4 schema, List checkedSchemas) + private static bool UsesComplexObjectSchema(this JsonSchema schema, List checkedSchemas) { schema = schema.ActualTypeSchema; diff --git a/src/NSwag.CodeGeneration/Models/OperationModelBase.cs b/src/NSwag.CodeGeneration/Models/OperationModelBase.cs index 2f927f9d45..f5ffc602b3 100644 --- a/src/NSwag.CodeGeneration/Models/OperationModelBase.cs +++ b/src/NSwag.CodeGeneration/Models/OperationModelBase.cs @@ -30,7 +30,7 @@ public abstract class OperationModelBase : IOpe /// The resolver. /// The generator. /// The settings. - protected OperationModelBase(JsonSchema4 exceptionSchema, SwaggerOperation operation, TypeResolverBase resolver, IClientGenerator generator, ClientGeneratorBaseSettings settings) + protected OperationModelBase(JsonSchema exceptionSchema, SwaggerOperation operation, TypeResolverBase resolver, IClientGenerator generator, ClientGeneratorBaseSettings settings) { _operation = operation; _resolver = resolver; @@ -58,7 +58,7 @@ protected OperationModelBase(JsonSchema4 exceptionSchema, SwaggerOperation opera /// The resolver. /// The settings. /// The response model. - protected abstract TResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema4 exceptionSchema, IClientGenerator generator, + protected abstract TResponseModel CreateResponseModel(SwaggerOperation operation, string statusCode, SwaggerResponse response, JsonSchema exceptionSchema, IClientGenerator generator, TypeResolverBase resolver, ClientGeneratorBaseSettings settings); /// Gets the operation ID. @@ -307,7 +307,7 @@ protected virtual string ResolveParameterType(SwaggerParameter parameter) if (parameter.CollectionFormat == SwaggerParameterCollectionFormat.Multi && !schema.Type.HasFlag(JsonObjectType.Array)) { - schema = new JsonSchema4 { Type = JsonObjectType.Array, Item = schema }; + schema = new JsonSchema { Type = JsonObjectType.Array, Item = schema }; } var typeNameHint = !schema.HasTypeNameTitle ? ConversionUtilities.ConvertToUpperCamelCase(parameter.Name, true) : null; diff --git a/src/NSwag.CodeGeneration/Models/ParameterModelBase.cs b/src/NSwag.CodeGeneration/Models/ParameterModelBase.cs index 017e148acc..da3d914c22 100644 --- a/src/NSwag.CodeGeneration/Models/ParameterModelBase.cs +++ b/src/NSwag.CodeGeneration/Models/ParameterModelBase.cs @@ -108,7 +108,7 @@ public IEnumerable CollectionPropertyNames public string Description => ConversionUtilities.TrimWhiteSpaces(_parameter.Description); /// Gets the schema. - public JsonSchema4 Schema => _parameter.ActualSchema; + public JsonSchema Schema => _parameter.ActualSchema; /// Gets a value indicating whether the parameter is required. public bool IsRequired => _parameter.IsRequired; diff --git a/src/NSwag.CodeGeneration/Models/PropertyModel.cs b/src/NSwag.CodeGeneration/Models/PropertyModel.cs index 73b1f3eb11..2593a0cae0 100644 --- a/src/NSwag.CodeGeneration/Models/PropertyModel.cs +++ b/src/NSwag.CodeGeneration/Models/PropertyModel.cs @@ -15,7 +15,7 @@ public class PropertyModel /// /// The represented by this /// - public JsonProperty JsonProperty { get; } + public JsonSchemaProperty JsonProperty { get; } /// /// The generated property name suitable for use in the target language @@ -28,7 +28,7 @@ public class PropertyModel public bool IsCollection => JsonProperty.Type == JsonObjectType.Array; /// - public PropertyModel(string key, JsonProperty jsonProperty, string name) + public PropertyModel(string key, JsonSchemaProperty jsonProperty, string name) { Key = key; JsonProperty = jsonProperty; diff --git a/src/NSwag.CodeGeneration/Models/ResponseModelBase.cs b/src/NSwag.CodeGeneration/Models/ResponseModelBase.cs index d2b26f093f..03fbbc2b87 100644 --- a/src/NSwag.CodeGeneration/Models/ResponseModelBase.cs +++ b/src/NSwag.CodeGeneration/Models/ResponseModelBase.cs @@ -19,7 +19,7 @@ public abstract class ResponseModelBase private readonly IOperationModel _operationModel; private readonly SwaggerResponse _response; private readonly SwaggerOperation _operation; - private readonly JsonSchema4 _exceptionSchema; + private readonly JsonSchema _exceptionSchema; private readonly IClientGenerator _generator; private readonly CodeGeneratorSettingsBase _settings; private readonly TypeResolverBase _resolver; @@ -37,7 +37,7 @@ public abstract class ResponseModelBase protected ResponseModelBase(IOperationModel operationModel, SwaggerOperation operation, string statusCode, SwaggerResponse response, bool isPrimarySuccessResponse, - JsonSchema4 exceptionSchema, TypeResolverBase resolver, CodeGeneratorSettingsBase settings, IClientGenerator generator) + JsonSchema exceptionSchema, TypeResolverBase resolver, CodeGeneratorSettingsBase settings, IClientGenerator generator) { _response = response; _operation = operation; @@ -56,7 +56,7 @@ protected ResponseModelBase(IOperationModel operationModel, public string StatusCode { get; } /// Gets the actual response schema. - public JsonSchema4 ActualResponseSchema { get; } + public JsonSchema ActualResponseSchema { get; } /// Gets a value indicating whether to check for the chunked HTTP status code (206, true when file response and 200/204). public bool CheckChunkedStatusCode => IsFile && (StatusCode == "200" || StatusCode == "204"); @@ -96,7 +96,7 @@ public bool IsDate "A server side error occurred."; /// Gets the response schema. - public JsonSchema4 ResolvableResponseSchema => _response.Schema != null ? _resolver.GetResolvableSchema(_response.Schema) : null; + public JsonSchema ResolvableResponseSchema => _response.Schema != null ? _resolver.GetResolvableSchema(_response.Schema) : null; /// Gets a value indicating whether the response is nullable. public bool IsNullable => _response.IsNullable(_settings.SchemaType); diff --git a/src/NSwag.Commands/Commands/CodeGeneration/JsonSchemaToSwaggerCommand.cs b/src/NSwag.Commands/Commands/CodeGeneration/JsonSchemaToSwaggerCommand.cs index 0e6d5292e6..81dd7f4839 100644 --- a/src/NSwag.Commands/Commands/CodeGeneration/JsonSchemaToSwaggerCommand.cs +++ b/src/NSwag.Commands/Commands/CodeGeneration/JsonSchemaToSwaggerCommand.cs @@ -23,7 +23,7 @@ public override async Task RunAsync(CommandLineProcessor processor, ICon public async Task RunAsync() { - var schema = await JsonSchema4.FromJsonAsync(Schema).ConfigureAwait(false); + var schema = await JsonSchema.FromJsonAsync(Schema).ConfigureAwait(false); var document = new SwaggerDocument(); var rootSchemaName = string.IsNullOrEmpty(Name) && Regex.IsMatch(schema.Title ?? string.Empty, "^[a-zA-Z0-9_]*$") ? schema.Title : Name; diff --git a/src/NSwag.Commands/Commands/InputOutputCommandBase.cs b/src/NSwag.Commands/Commands/InputOutputCommandBase.cs index cb9c7a257e..a654dac5e0 100644 --- a/src/NSwag.Commands/Commands/InputOutputCommandBase.cs +++ b/src/NSwag.Commands/Commands/InputOutputCommandBase.cs @@ -62,19 +62,19 @@ protected async Task GetInputSwaggerDocument() } /// The argument 'Input' was empty. - protected async Task GetJsonSchemaAsync() + protected async Task GetJsonSchemaAsync() { var input = Input.ToString(); if (string.IsNullOrEmpty(input)) throw new ArgumentException("The argument 'Input' was empty."); if (IsJson(input)) - return await JsonSchema4.FromJsonAsync(input).ConfigureAwait(false); + return await JsonSchema.FromJsonAsync(input).ConfigureAwait(false); if (await DynamicApis.FileExistsAsync(input).ConfigureAwait(false)) - return await JsonSchema4.FromFileAsync(input).ConfigureAwait(false); + return await JsonSchema.FromFileAsync(input).ConfigureAwait(false); - return await JsonSchema4.FromUrlAsync(input).ConfigureAwait(false); + return await JsonSchema.FromUrlAsync(input).ConfigureAwait(false); } } } \ No newline at end of file diff --git a/src/NSwag.Commands/Commands/IsolatedCommandBase.cs b/src/NSwag.Commands/Commands/IsolatedCommandBase.cs index c7dafd9f81..06bc48e48a 100644 --- a/src/NSwag.Commands/Commands/IsolatedCommandBase.cs +++ b/src/NSwag.Commands/Commands/IsolatedCommandBase.cs @@ -110,7 +110,7 @@ public IEnumerable GetAssemblies(string assemblyDirectory) public IEnumerable GetAssemblies(string assemblyDirectory) { yield return typeof(JToken).GetTypeInfo().Assembly; - yield return typeof(JsonSchema4).GetTypeInfo().Assembly; + yield return typeof(JsonSchema).GetTypeInfo().Assembly; yield return typeof(SwaggerDocument).GetTypeInfo().Assembly; yield return typeof(InputOutputCommandBase).GetTypeInfo().Assembly; yield return typeof(SwaggerJsonSchemaGenerator).GetTypeInfo().Assembly; @@ -124,7 +124,7 @@ public IEnumerable GetBindingRedirects() { #if NET461 yield return new BindingRedirect("Newtonsoft.Json", typeof(JToken), "30ad4fe6b2a6aeed"); - yield return new BindingRedirect("NJsonSchema", typeof(JsonSchema4), "c2f9c3bdfae56102"); + yield return new BindingRedirect("NJsonSchema", typeof(JsonSchema), "c2f9c3bdfae56102"); yield return new BindingRedirect("NSwag.Core", typeof(SwaggerDocument), "c2d88086e098d109"); yield return new BindingRedirect("NSwag.SwaggerGeneration", typeof(SwaggerJsonSchemaGenerator), "c2d88086e098d109"); yield return new BindingRedirect("NSwag.SwaggerGeneration.WebApi", typeof(WebApiToSwaggerGenerator), "c2d88086e098d109"); diff --git a/src/NSwag.Commands/Commands/SwaggerGeneration/AspNetCore/AspNetCoreToSwaggerCommand.cs b/src/NSwag.Commands/Commands/SwaggerGeneration/AspNetCore/AspNetCoreToSwaggerCommand.cs index 98e983c173..375b6e8bed 100644 --- a/src/NSwag.Commands/Commands/SwaggerGeneration/AspNetCore/AspNetCoreToSwaggerCommand.cs +++ b/src/NSwag.Commands/Commands/SwaggerGeneration/AspNetCore/AspNetCoreToSwaggerCommand.cs @@ -23,6 +23,7 @@ using Microsoft.AspNetCore.Hosting; using NSwag.SwaggerGeneration; using NSwag.SwaggerGeneration.Processors; +using NJsonSchema.Generation; #if NETCOREAPP || NETSTANDARD using System.Runtime.Loader; diff --git a/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs b/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs index bb48fa1c2a..36047526c1 100644 --- a/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs +++ b/src/NSwag.Commands/Commands/SwaggerGeneration/SwaggerGeneratorCommandBase.cs @@ -21,6 +21,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using NJsonSchema; +using NJsonSchema.Generation; using NJsonSchema.Infrastructure; using NSwag.AssemblyLoader.Utilities; using NSwag.SwaggerGeneration; diff --git a/src/NSwag.Commands/Commands/Tooling/VersionCommand.cs b/src/NSwag.Commands/Commands/Tooling/VersionCommand.cs index 1e4e9ac3d2..303ab5a390 100644 --- a/src/NSwag.Commands/Commands/Tooling/VersionCommand.cs +++ b/src/NSwag.Commands/Commands/Tooling/VersionCommand.cs @@ -23,7 +23,7 @@ public class VersionCommand : IConsoleCommand public Task RunAsync(CommandLineProcessor processor, IConsoleHost host) { host.WriteMessage("\nNSwag version: " + SwaggerDocument.ToolchainVersion + "\n"); - host.WriteMessage("NJsonSchema version: " + JsonSchema4.ToolchainVersion + "\n"); + host.WriteMessage("NJsonSchema version: " + JsonSchema.ToolchainVersion + "\n"); return Task.FromResult(null); } } diff --git a/src/NSwag.Commands/NSwagCommandProcessor.cs b/src/NSwag.Commands/NSwagCommandProcessor.cs index 8416aff13f..a20b729dbb 100644 --- a/src/NSwag.Commands/NSwagCommandProcessor.cs +++ b/src/NSwag.Commands/NSwagCommandProcessor.cs @@ -34,7 +34,7 @@ public NSwagCommandProcessor(IConsoleHost host) public int Process(string[] args) { _host.WriteMessage("toolchain v" + SwaggerDocument.ToolchainVersion + - " (NJsonSchema v" + JsonSchema4.ToolchainVersion + ")\n"); + " (NJsonSchema v" + JsonSchema.ToolchainVersion + ")\n"); _host.WriteMessage("Visit http://NSwag.org for more information.\n"); WriteBinDirectory(); diff --git a/src/NSwag.Core.Tests/Serialization/ComponentsSerializationTests.cs b/src/NSwag.Core.Tests/Serialization/ComponentsSerializationTests.cs index dc8a1f5a83..5147436d05 100644 --- a/src/NSwag.Core.Tests/Serialization/ComponentsSerializationTests.cs +++ b/src/NSwag.Core.Tests/Serialization/ComponentsSerializationTests.cs @@ -98,19 +98,19 @@ public async Task When_openapi3_has_nullable_schema_then_it_is_read_correctly() private static SwaggerDocument CreateDocument() { - var schema = new JsonSchema4 + var schema = new JsonSchema { Type = JsonObjectType.String }; var document = new SwaggerDocument(); document.Definitions["Foo"] = schema; - document.Definitions["Bar"] = new JsonSchema4 + document.Definitions["Bar"] = new JsonSchema { Type = JsonObjectType.Object, Properties = { - { "Foo", new JsonProperty { Reference = schema } } + { "Foo", new JsonSchemaProperty { Reference = schema } } } }; diff --git a/src/NSwag.Core.Tests/Serialization/MediaTypesSerializationTests.cs b/src/NSwag.Core.Tests/Serialization/MediaTypesSerializationTests.cs index 06d63e5d17..b5496d227d 100644 --- a/src/NSwag.Core.Tests/Serialization/MediaTypesSerializationTests.cs +++ b/src/NSwag.Core.Tests/Serialization/MediaTypesSerializationTests.cs @@ -169,7 +169,7 @@ private static SwaggerDocument CreateDocument(JsonObjectType type) new SwaggerResponse { Examples = 123, - Schema = new JsonSchema4 + Schema = new JsonSchema { Type = type }, diff --git a/src/NSwag.Core.Tests/Serialization/RequestBodySerializationTests.cs b/src/NSwag.Core.Tests/Serialization/RequestBodySerializationTests.cs index 2b3c5f4610..bb26f1f113 100644 --- a/src/NSwag.Core.Tests/Serialization/RequestBodySerializationTests.cs +++ b/src/NSwag.Core.Tests/Serialization/RequestBodySerializationTests.cs @@ -93,7 +93,7 @@ public async Task When_body_parameter_is_changed_then_request_body_Schema_is_upd var parameter = document.Paths["/baz"][SwaggerOperationMethod.Get].Parameters .Single(p => p.Kind == SwaggerParameterKind.Body); - parameter.Schema = new JsonSchema4 { Title = "blub" }; + parameter.Schema = new JsonSchema { Title = "blub" }; //// Assert var requestBody = document.Paths["/baz"][SwaggerOperationMethod.Get].RequestBody; @@ -178,7 +178,7 @@ public async Task When_request_body_is_changed_then_body_parameter_Content_is_up var requestBody = document.Paths["/baz"][SwaggerOperationMethod.Get].RequestBody; requestBody.Content["application/json"] = new OpenApiMediaType { - Schema = new JsonSchema4 { Title = "blub" } + Schema = new JsonSchema { Title = "blub" } }; //// Assert @@ -210,7 +210,7 @@ public async Task When_request_body_is_changed_then_body_parameter_Description_i private static SwaggerDocument CreateDocument() { - var schema = new JsonSchema4 + var schema = new JsonSchema { Type = JsonObjectType.String }; @@ -237,7 +237,7 @@ private static SwaggerDocument CreateDocument() "application/json", new OpenApiMediaType { - Schema = new JsonSchema4 { Reference = schema } + Schema = new JsonSchema { Reference = schema } } } } diff --git a/src/NSwag.Core/JsonExpectedSchema.cs b/src/NSwag.Core/JsonExpectedSchema.cs index 9287804ca1..aa9026863b 100644 --- a/src/NSwag.Core/JsonExpectedSchema.cs +++ b/src/NSwag.Core/JsonExpectedSchema.cs @@ -20,6 +20,6 @@ public class JsonExpectedSchema /// Gets or sets the schema. [JsonProperty(PropertyName = "schema", DefaultValueHandling = DefaultValueHandling.Ignore)] - public JsonSchema4 Schema { get; set; } + public JsonSchema Schema { get; set; } } } \ No newline at end of file diff --git a/src/NSwag.Core/OpenApiComponents.cs b/src/NSwag.Core/OpenApiComponents.cs index 29d7465d49..9fae90f72d 100644 --- a/src/NSwag.Core/OpenApiComponents.cs +++ b/src/NSwag.Core/OpenApiComponents.cs @@ -21,7 +21,7 @@ public class OpenApiComponents /// public OpenApiComponents(SwaggerDocument document) { - var schemas = new ObservableDictionary(); + var schemas = new ObservableDictionary(); schemas.CollectionChanged += (sender, args) => { foreach (var pair in schemas.ToArray()) @@ -56,7 +56,7 @@ public OpenApiComponents(SwaggerDocument document) Examples = new Dictionary(); - var headers = new ObservableDictionary(); + var headers = new ObservableDictionary(); headers.CollectionChanged += (sender, args) => { foreach (var pair in headers.ToArray()) @@ -80,7 +80,7 @@ public OpenApiComponents(SwaggerDocument document) /// Gets or sets the types. [JsonProperty(PropertyName = "schemas", DefaultValueHandling = DefaultValueHandling.Ignore)] - public IDictionary Schemas { get; } + public IDictionary Schemas { get; } /// Gets or sets the responses which can be used for all operations. [JsonProperty(PropertyName = "responses", DefaultValueHandling = DefaultValueHandling.Ignore)] @@ -96,7 +96,7 @@ public OpenApiComponents(SwaggerDocument document) /// Gets or sets the types. [JsonProperty(PropertyName = "headers", DefaultValueHandling = DefaultValueHandling.Ignore)] - public IDictionary Headers { get; } + public IDictionary Headers { get; } /// Gets or sets the security definitions. [JsonProperty(PropertyName = "securitySchemes", DefaultValueHandling = DefaultValueHandling.Ignore)] diff --git a/src/NSwag.Core/OpenApiMediaType.cs b/src/NSwag.Core/OpenApiMediaType.cs index 0f10ed2d0a..8475396ec4 100644 --- a/src/NSwag.Core/OpenApiMediaType.cs +++ b/src/NSwag.Core/OpenApiMediaType.cs @@ -15,7 +15,7 @@ namespace NSwag /// The Swagger media type (OpenAPI only). public class OpenApiMediaType { - private JsonSchema4 _schema; + private JsonSchema _schema; private object _example; [JsonIgnore] @@ -23,7 +23,7 @@ public class OpenApiMediaType /// Gets or sets the schema. [JsonProperty(PropertyName = "schema", DefaultValueHandling = DefaultValueHandling.Ignore)] - public JsonSchema4 Schema + public JsonSchema Schema { get => _schema; set diff --git a/src/NSwag.Core/SwaggerDocument.Serialization.cs b/src/NSwag.Core/SwaggerDocument.Serialization.cs index 6995b4075b..f4a7c152e6 100644 --- a/src/NSwag.Core/SwaggerDocument.Serialization.cs +++ b/src/NSwag.Core/SwaggerDocument.Serialization.cs @@ -45,7 +45,7 @@ public static PropertyRenameAndIgnoreSerializerContractResolver GetJsonSerialize private static PropertyRenameAndIgnoreSerializerContractResolver CreateJsonSerializerContractResolver(SchemaType schemaType) { - var resolver = JsonSchema4.CreateJsonSerializerContractResolver(schemaType); + var resolver = JsonSchema.CreateJsonSerializerContractResolver(schemaType); if (schemaType == SchemaType.Swagger2) { @@ -197,7 +197,7 @@ private void UpdateServers(ICollection schemes, string host, stri /// Gets or sets the types (Swagger only). [JsonProperty(PropertyName = "definitions", Order = 13, DefaultValueHandling = DefaultValueHandling.Ignore)] - public IDictionary Definitions => Components.Schemas; + public IDictionary Definitions => Components.Schemas; /// Gets or sets the parameters which can be used for all operations (Swagger only). [JsonProperty(PropertyName = "parameters", Order = 14, DefaultValueHandling = DefaultValueHandling.Ignore)] diff --git a/src/NSwag.Core/SwaggerHeaders.cs b/src/NSwag.Core/SwaggerHeaders.cs index 6fd01049e2..ee5605f3f0 100644 --- a/src/NSwag.Core/SwaggerHeaders.cs +++ b/src/NSwag.Core/SwaggerHeaders.cs @@ -12,7 +12,7 @@ namespace NSwag { /// A collection of headers. - public class SwaggerHeaders : ObservableDictionary + public class SwaggerHeaders : ObservableDictionary { } diff --git a/src/NSwag.Core/SwaggerParameter.cs b/src/NSwag.Core/SwaggerParameter.cs index d27bb2eb50..90af8ca8a9 100644 --- a/src/NSwag.Core/SwaggerParameter.cs +++ b/src/NSwag.Core/SwaggerParameter.cs @@ -15,13 +15,13 @@ namespace NSwag { /// Describes an operation parameter. - public class SwaggerParameter : JsonSchema4 + public class SwaggerParameter : JsonSchema { private string _name; private SwaggerParameterKind _kind; private SwaggerParameterStyle _style; private bool _isRequired = false; - private JsonSchema4 _schema; + private JsonSchema _schema; private IDictionary _examples; private bool _explode; private int? _position; @@ -127,7 +127,7 @@ public IDictionary Examples /// Gets or sets the schema which is only available when == body. [JsonProperty(PropertyName = "schema", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] - public JsonSchema4 Schema + public JsonSchema Schema { get => _schema; set @@ -139,7 +139,7 @@ public JsonSchema4 Schema /// Gets or sets the custom schema which is used when != body. [JsonProperty(PropertyName = "x-schema", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] - public JsonSchema4 CustomSchema { get; set; } + public JsonSchema CustomSchema { get; set; } /// Gets or sets the name. [JsonProperty(PropertyName = "x-position", DefaultValueHandling = DefaultValueHandling.IgnoreAndPopulate)] @@ -156,7 +156,7 @@ public int? Position /// Gets the actual schema, either the parameter schema itself (or its reference) or the property when == body. /// The schema reference path is not resolved. [JsonIgnore] - public override JsonSchema4 ActualSchema + public override JsonSchema ActualSchema { get { diff --git a/src/NSwag.Core/SwaggerResponse.cs b/src/NSwag.Core/SwaggerResponse.cs index 32a3d16c29..85cd039209 100644 --- a/src/NSwag.Core/SwaggerResponse.cs +++ b/src/NSwag.Core/SwaggerResponse.cs @@ -56,7 +56,7 @@ public class SwaggerResponse : JsonReferenceBase, IJsonReferenc /// Gets or sets the response schema (Swagger only). [JsonProperty(PropertyName = "schema", Order = 2, DefaultValueHandling = DefaultValueHandling.Ignore)] - public JsonSchema4 Schema + public JsonSchema Schema { get => Content.FirstOrDefault(c => c.Value.Schema != null).Value?.Schema; set => UpdateContent(value, Examples); @@ -70,7 +70,7 @@ public object Examples set => UpdateContent(Schema, value); } - private void UpdateContent(JsonSchema4 schema, object example) + private void UpdateContent(JsonSchema schema, object example) { Content.Clear(); diff --git a/src/NSwag.Core/SwaggerSchemaResolver.cs b/src/NSwag.Core/SwaggerSchemaResolver.cs index 14c247a7cf..9704b88b52 100644 --- a/src/NSwag.Core/SwaggerSchemaResolver.cs +++ b/src/NSwag.Core/SwaggerSchemaResolver.cs @@ -35,7 +35,7 @@ public SwaggerSchemaResolver(SwaggerDocument document, JsonSchemaGeneratorSettin /// Appends the schema to the root object. /// The schema to append. /// The type name hint. - public override void AppendSchema(JsonSchema4 schema, string typeNameHint) + public override void AppendSchema(JsonSchema schema, string typeNameHint) { if (!Document.Definitions.Values.Contains(schema)) { diff --git a/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Responses/NullableResponseTests.cs b/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Responses/NullableResponseTests.cs index a3222197f9..d7f778dd7d 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Responses/NullableResponseTests.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Responses/NullableResponseTests.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Threading.Tasks; using NJsonSchema; +using NJsonSchema.Generation; using NSwag.SwaggerGeneration.AspNetCore.Tests.Web.Controllers; using Xunit; diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs b/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs index b42ea36c57..87acd5662e 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/AspNetCoreToSwaggerGenerator.cs @@ -266,7 +266,7 @@ private async Task CreateDocumentAsync() await SwaggerDocument.FromJsonAsync(Settings.DocumentTemplate).ConfigureAwait(false) : new SwaggerDocument(); - document.Generator = $"NSwag v{SwaggerDocument.ToolchainVersion} (NJsonSchema v{JsonSchema4.ToolchainVersion})"; + document.Generator = $"NSwag v{SwaggerDocument.ToolchainVersion} (NJsonSchema v{JsonSchema.ToolchainVersion})"; document.SchemaType = Settings.SchemaType; if (document.Info == null) diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index 5e1b0081fa..f56cfc833c 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -306,7 +306,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon { Name = extendedApiParameter.ApiParameter.Name, Kind = SwaggerParameterKind.Body, - Schema = new JsonSchema4 + Schema = new JsonSchema { Type = JsonObjectType.String, IsNullableRaw = isNullable @@ -323,7 +323,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon { Name = extendedApiParameter.ApiParameter.Name, Kind = SwaggerParameterKind.Body, - Schema = new JsonSchema4 + Schema = new JsonSchema { Type = JsonObjectType.String, Format = JsonFormatStrings.Byte, @@ -343,7 +343,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon IsRequired = extendedApiParameter.IsRequired(_settings.RequireParametersWithoutDefault), IsNullableRaw = isNullable, Description = await extendedApiParameter.GetDocumentationAsync().ConfigureAwait(false), - Schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( + Schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( contextualParameterType, isNullable, schemaResolver: context.SchemaResolver).ConfigureAwait(false) }; } diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs index 9973b440ea..186c6d47f7 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs @@ -78,7 +78,7 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso response.IsNullableRaw = typeDescription.IsNullable; response.Schema = await context.SchemaGenerator - .GenerateWithReferenceAndNullabilityAsync(contextualReturnType, typeDescription.IsNullable, context.SchemaResolver) + .GenerateWithReferenceAndNullabilityAsync(contextualReturnType, typeDescription.IsNullable, context.SchemaResolver) .ConfigureAwait(false); } @@ -91,7 +91,7 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso context.OperationDescription.Operation.Responses[GetVoidResponseStatusCode()] = new SwaggerResponse { IsNullableRaw = true, - Schema = new JsonSchema4 + Schema = new JsonSchema { Type = _settings.SchemaType == SchemaType.Swagger2 ? JsonObjectType.File : JsonObjectType.String, Format = _settings.SchemaType == SchemaType.Swagger2 ? null : JsonFormatStrings.Binary, diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index 5c471f852e..0beef86f74 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -298,7 +298,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon { Name = name, Kind = SwaggerParameterKind.Body, - Schema = new JsonSchema4 + Schema = new JsonSchema { Type = JsonObjectType.String, IsNullableRaw = isNullable @@ -316,7 +316,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon { Name = name, Kind = SwaggerParameterKind.Body, - Schema = new JsonSchema4 + Schema = new JsonSchema { Type = JsonObjectType.String, Format = JsonFormatStrings.Byte, @@ -337,7 +337,7 @@ private async Task AddBodyParameterAsync(OperationProcessorCon IsRequired = true, // FromBody parameters are always required IsNullableRaw = isNullable, Description = await contextualParameter.GetDescriptionAsync().ConfigureAwait(false), - Schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( + Schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( contextualParameter, isNullable, schemaResolver: context.SchemaResolver).ConfigureAwait(false) }; operation.Parameters.Add(operationParameter); diff --git a/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs b/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs index f3d8dddc7b..2c11d06cb6 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/WebApiToSwaggerGenerator.cs @@ -116,7 +116,7 @@ private async Task CreateDocumentAsync() await SwaggerDocument.FromJsonAsync(Settings.DocumentTemplate).ConfigureAwait(false) : new SwaggerDocument(); - document.Generator = "NSwag v" + SwaggerDocument.ToolchainVersion + " (NJsonSchema v" + JsonSchema4.ToolchainVersion + ")"; + document.Generator = "NSwag v" + SwaggerDocument.ToolchainVersion + " (NJsonSchema v" + JsonSchema.ToolchainVersion + ")"; document.SchemaType = Settings.SchemaType; document.Consumes = new List { "application/json" }; diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index f7113fc899..31dd4b5464 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -158,7 +158,7 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable(contextualReturnType, isNullable, context.SchemaResolver) + .GenerateWithReferenceAndNullabilityAsync(contextualReturnType, isNullable, context.SchemaResolver) .ConfigureAwait(false); } @@ -200,7 +200,7 @@ private async Task> GenerateExpectedSchemasAsync var contextualResponseType = response.ResponseType.ToContextualType(); var isNullable = _settings.ReflectionService.GetDescription(contextualResponseType, _settings).IsNullable; - var schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( + var schema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( contextualResponseType, isNullable, context.SchemaResolver) .ConfigureAwait(false); @@ -237,7 +237,7 @@ private async Task LoadDefaultSuccessResponseAsync(ParameterInfo returnParameter var contextualReturnParameter = returnType.ToContextualType(returnParameter.GetCustomAttributes(false).OfType()); var typeDescription = _settings.ReflectionService.GetDescription(contextualReturnParameter, _settings); - var responseSchema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( + var responseSchema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( contextualReturnParameter, typeDescription.IsNullable, context.SchemaResolver).ConfigureAwait(false); operation.Responses["200"] = new SwaggerResponse diff --git a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs index d8cf154c01..8330f7b3d9 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs @@ -97,7 +97,7 @@ public async Task CreatePrimitiveParameterAsync( if (_settings.SchemaType == SchemaType.Swagger2) { operationParameter.Type = typeDescription.Type; - operationParameter.CustomSchema = new JsonSchema4 { Reference = schema.ActualSchema }; + operationParameter.CustomSchema = new JsonSchema { Reference = schema.ActualSchema }; // Copy enumeration for compatibility with other tools which do not understand x-schema. // The enumeration will be ignored by NSwag and only the x-schema is processed @@ -112,12 +112,12 @@ public async Task CreatePrimitiveParameterAsync( { if (typeDescription.IsNullable) { - operationParameter.Schema = new JsonSchema4 { IsNullableRaw = true }; - operationParameter.Schema.OneOf.Add(new JsonSchema4 { Reference = schema.ActualSchema }); + operationParameter.Schema = new JsonSchema { IsNullableRaw = true }; + operationParameter.Schema.OneOf.Add(new JsonSchema { Reference = schema.ActualSchema }); } else { - operationParameter.Schema = new JsonSchema4 { Reference = schema.ActualSchema }; + operationParameter.Schema = new JsonSchema { Reference = schema.ActualSchema }; } } } @@ -134,7 +134,7 @@ public async Task CreatePrimitiveParameterAsync( operationParameter = new SwaggerParameter { Schema = await _schemaGenerator - .GenerateWithReferenceAndNullabilityAsync( + .GenerateWithReferenceAndNullabilityAsync( contextualParameter, typeDescription.IsNullable, _schemaResolver) .ConfigureAwait(false) }; diff --git a/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs b/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs index a7eae42a47..9a822125b9 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerJsonSchemaGenerator.cs @@ -34,7 +34,7 @@ public SwaggerJsonSchemaGenerator(JsonSchemaGeneratorSettings settings) : base(s /// The properties /// The schema resolver. /// - protected override async Task GenerateObjectAsync(Type type, JsonTypeDescription typeDescription, JsonSchema4 schema, JsonSchemaResolver schemaResolver) + protected override async Task GenerateObjectAsync(Type type, JsonTypeDescription typeDescription, JsonSchema schema, JsonSchemaResolver schemaResolver) { if (_isRootType) { @@ -64,7 +64,7 @@ protected override async Task GenerateObjectAsync(Type type, JsonTypeDescription /// The requested schema object. public override async Task GenerateWithReferenceAndNullabilityAsync( ContextualType contextualType, bool isNullable, - JsonSchemaResolver schemaResolver, Func transformation = null) + JsonSchemaResolver schemaResolver, Func transformation = null) { if (contextualType.TypeName == "Task`1") { From 82fe57c0a0f595d34fda678061543b19768e9254 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 18:00:41 +0200 Subject: [PATCH 05/20] Fix tests --- src/NSwag.Commands/Commands/IsolatedCommandBase.cs | 3 +++ .../Attributes/ComplexParametersTests.cs | 1 + src/NSwag.SwaggerGeneration.WebApi.Tests/EnumTests.cs | 2 +- .../Integration/SwashbuckleAnnotationsTests.cs | 3 ++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/NSwag.Commands/Commands/IsolatedCommandBase.cs b/src/NSwag.Commands/Commands/IsolatedCommandBase.cs index 06bc48e48a..ca011a5348 100644 --- a/src/NSwag.Commands/Commands/IsolatedCommandBase.cs +++ b/src/NSwag.Commands/Commands/IsolatedCommandBase.cs @@ -13,6 +13,7 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; +using Namotion.Reflection; using NConsole; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -110,6 +111,7 @@ public IEnumerable GetAssemblies(string assemblyDirectory) public IEnumerable GetAssemblies(string assemblyDirectory) { yield return typeof(JToken).GetTypeInfo().Assembly; + yield return typeof(ContextualType).GetTypeInfo().Assembly; yield return typeof(JsonSchema).GetTypeInfo().Assembly; yield return typeof(SwaggerDocument).GetTypeInfo().Assembly; yield return typeof(InputOutputCommandBase).GetTypeInfo().Assembly; @@ -124,6 +126,7 @@ public IEnumerable GetBindingRedirects() { #if NET461 yield return new BindingRedirect("Newtonsoft.Json", typeof(JToken), "30ad4fe6b2a6aeed"); + yield return new BindingRedirect("Namotion.Reflection", typeof(JsonSchema), "c2f9c3bdfae56102"); yield return new BindingRedirect("NJsonSchema", typeof(JsonSchema), "c2f9c3bdfae56102"); yield return new BindingRedirect("NSwag.Core", typeof(SwaggerDocument), "c2d88086e098d109"); yield return new BindingRedirect("NSwag.SwaggerGeneration", typeof(SwaggerJsonSchemaGenerator), "c2d88086e098d109"); diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/Attributes/ComplexParametersTests.cs b/src/NSwag.SwaggerGeneration.WebApi.Tests/Attributes/ComplexParametersTests.cs index 54ca26c451..9420bf4efd 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/Attributes/ComplexParametersTests.cs +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/Attributes/ComplexParametersTests.cs @@ -11,6 +11,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using NJsonSchema; +using NJsonSchema.Generation; using NJsonSchema.Generation.TypeMappers; using NSwag.Annotations; diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/EnumTests.cs b/src/NSwag.SwaggerGeneration.WebApi.Tests/EnumTests.cs index 3a4452c030..464bcf7b4b 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/EnumTests.cs +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/EnumTests.cs @@ -77,7 +77,7 @@ public async Task When_response_is_enum_then_it_is_referenced() var json = document.ToJson(); // Assert - Assert.IsTrue(document.Operations.First().Operation.ActualResponses.First().Value.Schema.HasSchemaReference); + Assert.IsTrue(document.Operations.First().Operation.ActualResponses.First().Value.Schema.HasReference); } } } \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/Integration/SwashbuckleAnnotationsTests.cs b/src/NSwag.SwaggerGeneration.WebApi.Tests/Integration/SwashbuckleAnnotationsTests.cs index 1174304236..206dccc940 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/Integration/SwashbuckleAnnotationsTests.cs +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/Integration/SwashbuckleAnnotationsTests.cs @@ -4,6 +4,7 @@ using System.Web.Http; using Microsoft.VisualStudio.TestTools.UnitTesting; using NJsonSchema; +using NJsonSchema.Generation; using NJsonSchema.Generation.TypeMappers; namespace NSwag.SwaggerGeneration.WebApi.Tests.Integration @@ -53,7 +54,7 @@ public async Task When_redundant_attributes_are_available_then_output_is_correct { TypeMappers = { - new ObjectTypeMapper(typeof(JsonDate), new JsonSchema4 + new ObjectTypeMapper(typeof(JsonDate), new JsonSchema { Type = JsonObjectType.String, Format = "date" From 49ac337872ca31279dbfd8df5b3eb9faa1039fa1 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 19:05:45 +0200 Subject: [PATCH 06/20] Fix stuff, remove obsolete methods --- src/NSwag.AspNetCore.Launcher/Program.cs | 1 + .../NSwagApplicationBuilderExtensions.cs | 54 ++- .../Middlewares/SwaggerUiIndexMiddleware.cs | 12 +- .../Middlewares/WebApiToSwaggerMiddleware.cs | 112 ------ src/NSwag.AspNetCore/NSwag.AspNetCore.csproj | 3 +- src/NSwag.AspNetCore/SwaggerExtensions.cs | 339 ------------------ src/NSwag.AspNetCore/SwaggerReDocSettings.cs | 4 + src/NSwag.AspNetCore/SwaggerSettings.cs | 28 +- src/NSwag.AspNetCore/SwaggerUi3Settings.cs | 11 +- src/NSwag.AspNetCore/SwaggerUiSettings.cs | 4 + src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs | 4 + src/NSwag.Sample.NetCoreAngular/Startup.cs | 4 +- src/NSwag.Sample.NetCoreAurelia/Startup.cs | 3 +- .../Processors/OperationParameterProcessor.cs | 2 +- .../Processors/OperationResponseProcessor.cs | 2 +- .../OperationResponseProcessorBase.cs | 4 +- .../AspNetCoreToSwaggerGeneratorViewModel.cs | 1 + ...AssemblyTypeToSwaggerGeneratorViewModel.cs | 1 + .../WebApiToSwaggerGeneratorViewModel.cs | 1 + 19 files changed, 90 insertions(+), 500 deletions(-) delete mode 100644 src/NSwag.AspNetCore/Middlewares/WebApiToSwaggerMiddleware.cs delete mode 100644 src/NSwag.AspNetCore/SwaggerExtensions.cs diff --git a/src/NSwag.AspNetCore.Launcher/Program.cs b/src/NSwag.AspNetCore.Launcher/Program.cs index 27e6bf8d2c..476b2a7b23 100644 --- a/src/NSwag.AspNetCore.Launcher/Program.cs +++ b/src/NSwag.AspNetCore.Launcher/Program.cs @@ -48,6 +48,7 @@ internal class Program ["Newtonsoft.Json"] = new AssemblyLoadInfo(new Version(9, 0, 0)), ["NConsole"] = new AssemblyLoadInfo(new Version(3, 9, 0, 0)), ["NJsonSchema"] = new AssemblyLoadInfo(new Version(9, 7, 7)), + ["Namotion.Reflection"] = new AssemblyLoadInfo(new Version(1, 0, 0)), ["NSwag.AssemblyLoader"] = new AssemblyLoadInfo(NSwagVersion), ["NSwag.Commands"] = new AssemblyLoadInfo(NSwagVersion), ["NSwag.Core"] = new AssemblyLoadInfo(NSwagVersion), diff --git a/src/NSwag.AspNetCore/Extensions/NSwagApplicationBuilderExtensions.cs b/src/NSwag.AspNetCore/Extensions/NSwagApplicationBuilderExtensions.cs index 37a9d6baf0..08acac5666 100644 --- a/src/NSwag.AspNetCore/Extensions/NSwagApplicationBuilderExtensions.cs +++ b/src/NSwag.AspNetCore/Extensions/NSwagApplicationBuilderExtensions.cs @@ -1,9 +1,9 @@ using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Options; using NSwag.AspNetCore; using NSwag.AspNetCore.Middlewares; -using NSwag.SwaggerGeneration.WebApi; using System; using System.Collections.Generic; using System.Linq; @@ -31,6 +31,7 @@ public static IApplicationBuilder UseOpenApi(this IApplicationBuilder app, Actio /// The methods and are the same, but will be deprecated eventually. /// The app. /// Configure additional settings. + [Obsolete("Use UseOpenApi() instead.")] public static IApplicationBuilder UseSwagger(this IApplicationBuilder app, Action configure = null) { return UseSwaggerWithApiExplorerCore(app, configure); @@ -38,10 +39,7 @@ public static IApplicationBuilder UseSwagger(this IApplicationBuilder app, Actio private static IApplicationBuilder UseSwaggerWithApiExplorerCore(IApplicationBuilder app, Action configure) { - // TODO(v12): Add IOptions support when SwaggerUi3Settings<> T has been removed - //var settings = configure == null && app.ApplicationServices.GetService>()?.Value ?? new SwaggerMiddlewareSettings(); - - var settings = new SwaggerDocumentMiddlewareSettings(); + var settings = configure == null ? app.ApplicationServices.GetService>()?.Value : null ?? new SwaggerDocumentMiddlewareSettings(); configure?.Invoke(settings); if (settings.Path.Contains("{documentName}")) @@ -67,23 +65,19 @@ private static IApplicationBuilder UseSwaggerWithApiExplorerCore(IApplicationBui /// The app builder. public static IApplicationBuilder UseSwaggerUi3( this IApplicationBuilder app, - Action> configure = null) + Action configure = null) { - // TODO(v12): Add IOptions support when SwaggerUi3Settings<> T has been removed - //var settings = configure == null && app.ApplicationServices.GetService>>()?.Value ?? - // new SwaggerUi3Settings(); - - var settings = new SwaggerUi3Settings(); + var settings = configure == null ? app.ApplicationServices.GetService>()?.Value : null ?? new SwaggerUi3Settings(); configure?.Invoke(settings); UseSwaggerUiWithDocumentNamePlaceholderExpanding(app, settings, (swaggerRoute, swaggerUiRoute) => { app.UseMiddleware(swaggerUiRoute, swaggerRoute, settings.TransformToExternalPath); - app.UseMiddleware>(swaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi3.index.html"); + app.UseMiddleware(swaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi3.index.html"); app.UseFileServer(new FileServerOptions { RequestPath = new PathString(swaggerUiRoute), - FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi3") + FileProvider = new EmbeddedFileProvider(typeof(NSwagApplicationBuilderExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi3") }); }, (documents) => @@ -110,27 +104,51 @@ public static IApplicationBuilder UseSwaggerUi3( /// The app builder. public static IApplicationBuilder UseReDoc( this IApplicationBuilder app, - Action> configure = null) + Action configure = null) { - var settings = new SwaggerReDocSettings(); + var settings = configure == null ? app.ApplicationServices.GetService>()?.Value : null ?? new SwaggerReDocSettings(); configure?.Invoke(settings); UseSwaggerUiWithDocumentNamePlaceholderExpanding(app, settings, (swaggerRoute, swaggerUiRoute) => { app.UseMiddleware(swaggerUiRoute, swaggerRoute, settings.TransformToExternalPath); - app.UseMiddleware>(swaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.ReDoc.index.html"); + app.UseMiddleware(swaggerUiRoute + "/index.html", settings, "NSwag.AspNetCore.ReDoc.index.html"); app.UseFileServer(new FileServerOptions { RequestPath = new PathString(swaggerUiRoute), - FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.ReDoc") + FileProvider = new EmbeddedFileProvider(typeof(NSwagApplicationBuilderExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.ReDoc") }); }, (documents) => false); return app; } + /// Adds the Swagger UI (only) to the pipeline. + /// The app. + /// Configure the Swagger UI settings. + /// The app builder. + [Obsolete("Use " + nameof(UseSwaggerUi3) + " instead.")] + public static IApplicationBuilder UseSwaggerUi( + this IApplicationBuilder app, + Action configure = null) + { + var settings = new SwaggerUiSettings(); + settings.DocumentPath = "/swagger/v1/swagger.json"; + configure?.Invoke(settings); + + app.UseMiddleware(settings.ActualSwaggerUiPath, settings.ActualSwaggerDocumentPath, settings.TransformToExternalPath); + app.UseMiddleware(settings.ActualSwaggerUiPath + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi.index.html"); + app.UseFileServer(new FileServerOptions + { + RequestPath = new PathString(settings.ActualSwaggerUiPath), + FileProvider = new EmbeddedFileProvider(typeof(NSwagApplicationBuilderExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi") + }); + + return app; + } + private static void UseSwaggerUiWithDocumentNamePlaceholderExpanding(IApplicationBuilder app, - SwaggerUiSettingsBase settings, + SwaggerUiSettingsBase settings, Action register, Func, bool> registerMultiple) { diff --git a/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs b/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs index 4da5460cfc..6a2fc82d6f 100644 --- a/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs +++ b/src/NSwag.AspNetCore/Middlewares/SwaggerUiIndexMiddleware.cs @@ -3,19 +3,17 @@ using System.Reflection; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; -using NSwag.SwaggerGeneration; namespace NSwag.AspNetCore.Middlewares { - internal class SwaggerUiIndexMiddleware - where T : SwaggerGeneratorSettings, new() + internal class SwaggerUiIndexMiddleware { private readonly RequestDelegate _nextDelegate; private readonly string _indexPath; - private readonly SwaggerUiSettingsBase _settings; + private readonly SwaggerUiSettingsBase _settings; private readonly string _resourcePath; - public SwaggerUiIndexMiddleware(RequestDelegate nextDelegate, string indexPath, SwaggerUiSettingsBase settings, string resourcePath) + public SwaggerUiIndexMiddleware(RequestDelegate nextDelegate, string indexPath, SwaggerUiSettingsBase settings, string resourcePath) { _nextDelegate = nextDelegate; _indexPath = indexPath; @@ -27,7 +25,7 @@ public async Task Invoke(HttpContext context) { if (context.Request.Path.HasValue && string.Equals(context.Request.Path.Value.Trim('/'), _indexPath.Trim('/'), StringComparison.OrdinalIgnoreCase)) { - var stream = typeof(SwaggerUiIndexMiddleware).GetTypeInfo().Assembly.GetManifestResourceStream(_resourcePath); + var stream = typeof(SwaggerUiIndexMiddleware).GetTypeInfo().Assembly.GetManifestResourceStream(_resourcePath); using (var reader = new StreamReader(stream)) { context.Response.Headers["Content-Type"] = "text/html; charset=utf-8"; @@ -36,7 +34,9 @@ public async Task Invoke(HttpContext context) } } else + { await _nextDelegate(context); + } } } } \ No newline at end of file diff --git a/src/NSwag.AspNetCore/Middlewares/WebApiToSwaggerMiddleware.cs b/src/NSwag.AspNetCore/Middlewares/WebApiToSwaggerMiddleware.cs deleted file mode 100644 index cdfb8a3bf1..0000000000 --- a/src/NSwag.AspNetCore/Middlewares/WebApiToSwaggerMiddleware.cs +++ /dev/null @@ -1,112 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (c) Rico Suter. All rights reserved. -// -// https://github.com/NSwag/NSwag/blob/master/LICENSE.md -// Rico Suter, mail@rsuter.com -//----------------------------------------------------------------------- - -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; -using NSwag.SwaggerGeneration; -using NSwag.SwaggerGeneration.WebApi; - -namespace NSwag.AspNetCore.Middlewares -{ - /// Generates a Swagger specification on a given path. - public class WebApiToSwaggerMiddleware - { - private readonly RequestDelegate _nextDelegate; - private readonly IOptions _mvcOptions; - private readonly IOptions _mvcJsonOptions; - - private readonly string _path; - private readonly IEnumerable _controllerTypes; - private readonly SwaggerSettings _settings; - private readonly SwaggerJsonSchemaGenerator _schemaGenerator; - - private string _schemaJson; - private Exception _schemaException; - private DateTimeOffset _schemaTimestamp; - - /// Initializes a new instance of the class. - /// The next delegate. - /// The options. - /// The json options. - /// The path. - /// The controller types. - /// The settings. - /// The schema generator. - public WebApiToSwaggerMiddleware(RequestDelegate nextDelegate, IOptions mvcOptions, IOptions mvcJsonOptions, string path, IEnumerable controllerTypes, SwaggerSettings settings, SwaggerJsonSchemaGenerator schemaGenerator) - { - _nextDelegate = nextDelegate; - _mvcOptions = mvcOptions; - _mvcJsonOptions = mvcJsonOptions; - _path = path; - _controllerTypes = controllerTypes; - _settings = settings; - _schemaGenerator = schemaGenerator; - } - - /// Invokes the specified context. - /// The context. - /// The task. - public async Task Invoke(HttpContext context) - { - if (context.Request.Path.HasValue && string.Equals(context.Request.Path.Value.Trim('/'), _path.Trim('/'), StringComparison.OrdinalIgnoreCase)) - { - var schemaJson = await GenerateSwaggerAsync(context); - context.Response.StatusCode = 200; - context.Response.Headers["Content-Type"] = "application/json; charset=utf-8"; - await context.Response.WriteAsync(schemaJson); - } - else - await _nextDelegate(context); - } - - /// Generates the Swagger specification. - /// The context. - /// The Swagger specification. - protected virtual async Task GenerateSwaggerAsync(HttpContext context) - { - if (_schemaException != null && _schemaTimestamp + _settings.ExceptionCacheTime > DateTimeOffset.UtcNow) - throw _schemaException; - - if (_schemaJson == null) - { - if (_schemaJson == null) - { - try - { - var serializerSettings = _mvcJsonOptions.Value.SerializerSettings; - var settings = _settings.CreateGeneratorSettings(serializerSettings, _mvcOptions.Value); - var generator = new WebApiToSwaggerGenerator(settings, _schemaGenerator); - var document = await generator.GenerateForControllersAsync(_controllerTypes); - - document.Host = context.Request.Host.Value ?? ""; - document.Schemes.Add(context.Request.Scheme == "http" ? SwaggerSchema.Http : SwaggerSchema.Https); - document.BasePath = context.Request.PathBase.Value?.Substring(0, context.Request.PathBase.Value.Length - (_settings.MiddlewareBasePath?.Length ?? 0)) ?? ""; - - _settings.PostProcess?.Invoke(document); - _schemaJson = document.ToJson(); - _schemaException = null; - _schemaTimestamp = DateTimeOffset.UtcNow; - } - catch (Exception exception) - { - _schemaJson = null; - _schemaException = exception; - _schemaTimestamp = DateTimeOffset.UtcNow; - throw _schemaException; - } - } - } - - return _schemaJson; - } - } -} \ No newline at end of file diff --git a/src/NSwag.AspNetCore/NSwag.AspNetCore.csproj b/src/NSwag.AspNetCore/NSwag.AspNetCore.csproj index 951a070100..0538fd4063 100644 --- a/src/NSwag.AspNetCore/NSwag.AspNetCore.csproj +++ b/src/NSwag.AspNetCore/NSwag.AspNetCore.csproj @@ -3,7 +3,7 @@ net451;netstandard1.6;netstandard2.0 NSwag: The Swagger API toolchain for .NET and TypeScript 12.2.5 - Swagger Documentation WebApi AspNet TypeScript CodeGen + Swagger Documentation AspNetCore NetCore TypeScript CodeGen Copyright © Rico Suter, 2019 https://github.com/NSwag/NSwag/blob/master/LICENSE.md http://NSwag.org @@ -39,7 +39,6 @@ - \ No newline at end of file diff --git a/src/NSwag.AspNetCore/SwaggerExtensions.cs b/src/NSwag.AspNetCore/SwaggerExtensions.cs deleted file mode 100644 index c67d0f9fd9..0000000000 --- a/src/NSwag.AspNetCore/SwaggerExtensions.cs +++ /dev/null @@ -1,339 +0,0 @@ -//----------------------------------------------------------------------- -// -// Copyright (c) Rico Suter. All rights reserved. -// -// https://github.com/NSwag/NSwag/blob/master/LICENSE.md -// Rico Suter, mail@rsuter.com -//----------------------------------------------------------------------- - -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.FileProviders; -using NSwag.AspNetCore.Middlewares; -using NSwag.SwaggerGeneration; -using NSwag.SwaggerGeneration.AspNetCore; -using NSwag.SwaggerGeneration.WebApi; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; - -namespace NSwag.AspNetCore -{ - // Obsolete extension methods only, see /Extensions directory for supported extensions. - - /// Provides extensions to enable Swagger UI. - public static class SwaggerExtensions - { - #region Swagger - - /// Adds the Swagger generator that uses reflection (legacy) and Swagger UI to the pipeline. - /// The app. - /// The Web API assembly to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "() and " + nameof(UseSwagger) + "() instead.")] - public static IApplicationBuilder UseSwagger( - this IApplicationBuilder app, - Assembly webApiAssembly, - Action> configure = null) - { - return app.UseSwagger(new[] { webApiAssembly }, configure); - } - - /// Adds the Swagger generator that uses reflection (legacy) and Swagger UI to the pipeline. - /// The app. - /// The Web API assemblies to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "() and " + nameof(UseSwagger) + "() instead.")] - public static IApplicationBuilder UseSwagger( - this IApplicationBuilder app, - IEnumerable webApiAssemblies, - Action> configure = null) - { - var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses); - return app.UseSwagger(controllerTypes, configure); - } - - /// Adds the Swagger generator that uses reflection (legacy) to the pipeline. - /// The app. - /// The Web API controller types. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "() and " + nameof(UseSwagger) + "() instead.")] - public static IApplicationBuilder UseSwagger( - this IApplicationBuilder app, - IEnumerable controllerTypes, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - var settings = new SwaggerSettings(); - configure?.Invoke(settings); - app.UseMiddleware(settings.ActualSwaggerDocumentPath, controllerTypes, settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings)); - return app; - } - - /// Adds the Swagger generator that uses Api Description to perform Swagger generation. - /// The app. - /// Configure additional settings. - [Obsolete("Use " + nameof(UseSwagger) + " instead.")] - public static IApplicationBuilder UseSwaggerWithApiExplorer(this IApplicationBuilder app, Action configure = null) - { - return NSwagApplicationBuilderExtensions.UseSwagger(app, configure); - } - - #endregion - - #region SwaggerUi - - /// Adds the Swagger generator and Swagger UI to the pipeline. - /// The app. - /// The Web API assembly to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi( - this IApplicationBuilder app, - Assembly webApiAssembly, - Action> configure = null) - { - return app.UseSwaggerUi(new[] { webApiAssembly }, configure); - } - - /// Adds the Swagger generator and Swagger UI to the pipeline. - /// The app. - /// The Web API assemblies to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi( - this IApplicationBuilder app, - IEnumerable webApiAssemblies, - Action> configure = null) - { - var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses); - return app.UseSwaggerUi(controllerTypes, configure); - } - - /// Adds the Swagger UI (only) to the pipeline. - /// The app. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(UseSwaggerUi3) + " instead.")] - public static IApplicationBuilder UseSwaggerUi( - this IApplicationBuilder app, - Action> configure = null) - { - return app.UseSwaggerUi(null, configure, null); - } - - /// Adds the Swagger generator and Swagger UI to the pipeline. - /// The app. - /// The Web API controller types. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi( - this IApplicationBuilder app, - IEnumerable controllerTypes, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - var settings = new SwaggerUiSettings(); - settings.DocumentPath = "/swagger/v1/swagger.json"; - configure?.Invoke(settings); - - if (controllerTypes != null) - app.UseMiddleware(settings.ActualSwaggerDocumentPath, controllerTypes, settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings)); - - app.UseMiddleware(settings.ActualSwaggerUiPath, settings.ActualSwaggerDocumentPath, settings.TransformToExternalPath); - app.UseMiddleware>(settings.ActualSwaggerUiPath + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi.index.html"); - app.UseFileServer(new FileServerOptions - { - RequestPath = new PathString(settings.ActualSwaggerUiPath), - FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi") - }); - - return app; - } - - /// Adds the Swagger generator and Swagger UI to the pipeline. - /// The app. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUiWithApiExplorer( - this IApplicationBuilder app, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - throw new NotSupportedException("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + - "() and " + nameof(UseSwaggerUi3) + "() instead."); - } - - #endregion - - #region SwaggerUi3 - - /// Adds the Swagger generator that uses reflection (legacy) and Swagger UI to the pipeline. - /// The app. - /// The Web API assembly to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi3( - this IApplicationBuilder app, - Assembly webApiAssembly, - Action> configure = null) - { - return app.UseSwaggerUi3(new[] { webApiAssembly }, configure); - } - - /// Adds the Swagger generator that uses reflection (legacy) and Swagger UI to the pipeline. - /// The app. - /// The Web API assemblies to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi3( - this IApplicationBuilder app, - IEnumerable webApiAssemblies, - Action> configure = null) - { - var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses); - return app.UseSwaggerUi3(controllerTypes, configure); - } - - /// Adds the Swagger generator that uses reflection (legacy) and Swagger UI to the pipeline. - /// The app. - /// The Web API controller types. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi3( - this IApplicationBuilder app, - IEnumerable controllerTypes, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - var settings = new SwaggerUi3Settings(); - settings.DocumentPath = "/swagger/v1/swagger.json"; - configure?.Invoke(settings); - - if (controllerTypes != null) - app.UseMiddleware(settings.ActualSwaggerDocumentPath, controllerTypes, settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings)); - - app.UseMiddleware(settings.ActualSwaggerUiPath, settings.ActualSwaggerDocumentPath, settings.TransformToExternalPath); - app.UseMiddleware>(settings.ActualSwaggerUiPath + "/index.html", settings, "NSwag.AspNetCore.SwaggerUi3.index.html"); - app.UseFileServer(new FileServerOptions - { - RequestPath = new PathString(settings.ActualSwaggerUiPath), - FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.SwaggerUi3") - }); - - return app; - } - - /// Adds the Swagger generator and Swagger UI to the pipeline. - /// The app. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerUi3) + "() instead.")] - public static IApplicationBuilder UseSwaggerUi3WithApiExplorer( - this IApplicationBuilder app, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - throw new NotSupportedException("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + - "() and " + nameof(UseSwaggerUi3) + "() instead."); - } - - #endregion - - #region ReDoc - - /// Adds the Swagger generator that uses reflection (legacy) and ReDoc UI to the pipeline. - /// The app. - /// The Web API assembly to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and UseReDoc() instead.")] - public static IApplicationBuilder UseSwaggerReDoc( - this IApplicationBuilder app, - Assembly webApiAssembly, - Action> configure = null) - { - return app.UseSwaggerReDoc(new[] { webApiAssembly }, configure); - } - - /// Adds the Swagger generator that uses reflection (legacy) and ReDoc UI to the pipeline. - /// The app. - /// The Web API assemblies to search for controller types. - /// Configure the Swagger settings. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and UseReDoc() instead.")] - public static IApplicationBuilder UseSwaggerReDoc( - this IApplicationBuilder app, - IEnumerable webApiAssemblies, - Action> configure = null) - { - var controllerTypes = webApiAssemblies.SelectMany(WebApiToSwaggerGenerator.GetControllerClasses); - return app.UseSwaggerReDoc(controllerTypes, configure); - } - - /// Adds the Swagger generator that uses reflection (legacy) and ReDoc UI to the pipeline. - /// The app. - /// The Web API controller types. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and UseReDoc() instead.")] - public static IApplicationBuilder UseSwaggerReDoc( - this IApplicationBuilder app, - IEnumerable controllerTypes, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - var settings = new SwaggerReDocSettings(); - settings.DocumentPath = "/swagger/v1/swagger.json"; - configure?.Invoke(settings); - - if (controllerTypes != null) - app.UseMiddleware(settings.ActualSwaggerDocumentPath, controllerTypes, settings, schemaGenerator ?? new SwaggerJsonSchemaGenerator(settings.GeneratorSettings)); - - app.UseMiddleware(settings.ActualSwaggerUiPath, settings.ActualSwaggerDocumentPath, settings.TransformToExternalPath); - app.UseMiddleware>(settings.ActualSwaggerUiPath + "/index.html", settings, "NSwag.AspNetCore.ReDoc.index.html"); - app.UseFileServer(new FileServerOptions - { - RequestPath = new PathString(settings.ActualSwaggerUiPath), - FileProvider = new EmbeddedFileProvider(typeof(SwaggerExtensions).GetTypeInfo().Assembly, "NSwag.AspNetCore.ReDoc") - }); - - return app; - } - - /// Adds the Swagger generator and Swagger UI to the pipeline. - /// The app. - /// Configure the Swagger settings. - /// The schema generator. - /// The app builder. - [Obsolete("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + "() and " + nameof(UseSwaggerReDoc) + "() instead.")] - public static IApplicationBuilder UseSwaggerReDocWithApiExplorer( - this IApplicationBuilder app, - Action> configure = null, - SwaggerJsonSchemaGenerator schemaGenerator = null) - { - throw new NotSupportedException("Use " + nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + "(), " + nameof(UseSwagger) + - "() and " + nameof(UseSwaggerReDoc) + "() instead."); - } - - #endregion - } -} diff --git a/src/NSwag.AspNetCore/SwaggerReDocSettings.cs b/src/NSwag.AspNetCore/SwaggerReDocSettings.cs index 178909e9a8..db359b1788 100644 --- a/src/NSwag.AspNetCore/SwaggerReDocSettings.cs +++ b/src/NSwag.AspNetCore/SwaggerReDocSettings.cs @@ -19,8 +19,12 @@ namespace NSwag.AspNetCore #endif { /// The settings for UseReDoc. +#if AspNetOwin public class SwaggerReDocSettings : SwaggerUiSettingsBase where T : SwaggerGeneratorSettings, new() +#else + public class SwaggerReDocSettings : SwaggerUiSettingsBase +#endif { /// Gets the additional ReDoc settings. public IDictionary AdditionalSettings { get; } = new Dictionary(); diff --git a/src/NSwag.AspNetCore/SwaggerSettings.cs b/src/NSwag.AspNetCore/SwaggerSettings.cs index 688c784676..3763bf50f4 100644 --- a/src/NSwag.AspNetCore/SwaggerSettings.cs +++ b/src/NSwag.AspNetCore/SwaggerSettings.cs @@ -9,9 +9,9 @@ using System; using Newtonsoft.Json; using NSwag.SwaggerGeneration; -using NSwag.SwaggerGeneration.WebApi; #if AspNetOwin +using NSwag.SwaggerGeneration.WebApi; using Microsoft.Owin; namespace NSwag.AspNet.Owin @@ -22,25 +22,25 @@ namespace NSwag.AspNetCore // TODO: Remove this class in v13, only used for legacy Web API middlewares /// The settings for UseSwagger. +#if AspNetOwin public class SwaggerSettings where T : SwaggerGeneratorSettings, new() +#else + public class SwaggerSettings +#endif { - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. public SwaggerSettings() { +#if AspNetOwin GeneratorSettings = new T(); - -#if !AspNetOwin - if (GeneratorSettings is WebApiToSwaggerGeneratorSettings) - ((WebApiToSwaggerGeneratorSettings)(object)GeneratorSettings).IsAspNetCore = true; #endif } +#if AspNetOwin /// Gets the generator settings. -#if !AspNetOwin - [Obsolete("This property is ignored when used without OpenAPI/Swagger generator and will be removed eventually, change config in UseSwagger().")] -#endif public T GeneratorSettings { get; } +#endif /// Gets or sets the OWIN base path (when mapped via app.MapOwinPath()) (must start with '/'). #if !AspNetOwin @@ -57,24 +57,22 @@ public SwaggerSettings() public string DocumentPath { get; set; } = "/swagger/v1/swagger.json"; #endif +#if AspNetOwin /// Gets or sets the Swagger post process action. -#if !AspNetOwin - [Obsolete("This property is ignored when using AspNetCoreToSwaggerGenerator and will be removed eventually.")] -#endif public Action PostProcess { get; set; } /// Gets or sets for how long a caught during schema generation is cached. -#if !AspNetOwin - [Obsolete("This property is ignored when using AspNetCoreToSwaggerGenerator and will be removed eventually.")] -#endif public TimeSpan ExceptionCacheTime { get; set; } = TimeSpan.FromSeconds(10); +#endif internal virtual string ActualSwaggerDocumentPath => DocumentPath.Substring(MiddlewareBasePath?.Length ?? 0); +#if AspNetOwin internal T CreateGeneratorSettings(JsonSerializerSettings serializerSettings, object mvcOptions) { GeneratorSettings.ApplySettings(serializerSettings, mvcOptions); return GeneratorSettings; } +#endif } } \ No newline at end of file diff --git a/src/NSwag.AspNetCore/SwaggerUi3Settings.cs b/src/NSwag.AspNetCore/SwaggerUi3Settings.cs index 831e1562ef..49ff19c63c 100644 --- a/src/NSwag.AspNetCore/SwaggerUi3Settings.cs +++ b/src/NSwag.AspNetCore/SwaggerUi3Settings.cs @@ -26,10 +26,14 @@ namespace NSwag.AspNetCore #endif { /// The settings for UseSwaggerUi3. +#if AspNetOwin public class SwaggerUi3Settings : SwaggerUiSettingsBase where T : SwaggerGeneratorSettings, new() +#else + public class SwaggerUi3Settings : SwaggerUiSettingsBase +#endif { - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. public SwaggerUi3Settings() { DocExpansion = "none"; @@ -137,6 +141,7 @@ internal override string TransformHtml(string html, HttpRequest request) /// Specifies a route in the Swagger dropdown. public class SwaggerUi3Route { + /// Initializes a new instance of the class. public SwaggerUi3Route(string name, string url) { if (string.IsNullOrWhiteSpace(name)) @@ -147,10 +152,12 @@ public SwaggerUi3Route(string name, string url) Name = name; Url = url; } - + + /// Gets the route URL. [JsonProperty("url")] public string Url { get; internal set; } + /// Gets the route name. [JsonProperty("name")] public string Name { get; internal set; } } diff --git a/src/NSwag.AspNetCore/SwaggerUiSettings.cs b/src/NSwag.AspNetCore/SwaggerUiSettings.cs index 1f0eef2969..3e7aa9ae34 100644 --- a/src/NSwag.AspNetCore/SwaggerUiSettings.cs +++ b/src/NSwag.AspNetCore/SwaggerUiSettings.cs @@ -22,8 +22,12 @@ namespace NSwag.AspNetCore #endif { /// The settings for UseSwaggerUi. +#if AspNetOwin public class SwaggerUiSettings : SwaggerUiSettingsBase where T : SwaggerGeneratorSettings, new() +#else + public class SwaggerUiSettings : SwaggerUiSettingsBase +#endif { /// Gets or sets a value indicating whether the Swagger specification should be validated. public bool ValidateSpecification { get; set; } = true; diff --git a/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs b/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs index b7e4bfe9dd..5bade86cb5 100644 --- a/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs +++ b/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs @@ -23,8 +23,12 @@ namespace NSwag.AspNetCore #endif { /// The base settings for all Swagger UIs. +#if AspNetOwin public abstract class SwaggerUiSettingsBase : SwaggerSettings where T : SwaggerGeneratorSettings, new() +#else + public abstract class SwaggerUiSettingsBase : SwaggerSettings +#endif { /// Initializes a new instance of the class. public SwaggerUiSettingsBase() diff --git a/src/NSwag.Sample.NetCoreAngular/Startup.cs b/src/NSwag.Sample.NetCoreAngular/Startup.cs index fe533c63cc..b6e0b9760a 100644 --- a/src/NSwag.Sample.NetCoreAngular/Startup.cs +++ b/src/NSwag.Sample.NetCoreAngular/Startup.cs @@ -35,6 +35,8 @@ public void ConfigureServices(IServiceCollection services) o.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; o.SerializerSettings.Converters = new List { new StringEnumConverter() }; }); + + services.AddSwaggerDocument(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -49,7 +51,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); - app.UseSwaggerUi(typeof(Startup).GetTypeInfo().Assembly); + app.UseSwaggerUi3(); if (env.IsDevelopment()) { diff --git a/src/NSwag.Sample.NetCoreAurelia/Startup.cs b/src/NSwag.Sample.NetCoreAurelia/Startup.cs index a858befc55..f8615caf25 100644 --- a/src/NSwag.Sample.NetCoreAurelia/Startup.cs +++ b/src/NSwag.Sample.NetCoreAurelia/Startup.cs @@ -28,6 +28,7 @@ public void ConfigureServices(IServiceCollection services) { // Add framework services. services.AddMvc(); + services.AddSwaggerDocument(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -42,7 +43,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); - app.UseSwaggerUi(typeof(Startup).GetTypeInfo().Assembly); + app.UseSwaggerUi3(); if (env.IsDevelopment()) { diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index f56cfc833c..d7c7387dee 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -390,7 +390,7 @@ private class ExtendedApiParameterDescription public Type ParameterType { get; set; } - public IEnumerable Attributes { get; set; } + public IEnumerable Attributes { get; set; } = Enumerable.Empty(); public bool IsRequired(bool requireParametersWithoutDefault) { diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs index 186c6d47f7..8efa9d8354 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs @@ -71,7 +71,7 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso if (IsVoidResponse(returnType) == false) { - var contextualReturnType = returnType.ToContextualType(context.MethodInfo.ReturnParameter.GetCustomAttributes(false).OfType()); + var contextualReturnType = returnType.ToContextualType(context.MethodInfo.ReturnParameter?.GetCustomAttributes(false).OfType() ?? Enumerable.Empty()); var typeDescription = _settings.ReflectionService.GetDescription( contextualReturnType, _settings.DefaultResponseReferenceTypeNullHandling, _settings); diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index 31dd4b5464..ed18ec17d9 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -139,7 +139,7 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable r.ResponseType).GetCommonBaseType(); - var contextualReturnType = returnType.ToContextualType(returnParameter.GetCustomAttributes(false).OfType()); + var contextualReturnType = returnType.ToContextualType(returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty()); var description = string.Join("\nor\n", statusCodeGroup.Select(r => r.Description)); @@ -234,7 +234,7 @@ private async Task LoadDefaultSuccessResponseAsync(ParameterInfo returnParameter } else { - var contextualReturnParameter = returnType.ToContextualType(returnParameter.GetCustomAttributes(false).OfType()); + var contextualReturnParameter = returnType.ToContextualType(returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty()); var typeDescription = _settings.ReflectionService.GetDescription(contextualReturnParameter, _settings); var responseSchema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( diff --git a/src/NSwagStudio/ViewModels/SwaggerGenerators/AspNetCoreToSwaggerGeneratorViewModel.cs b/src/NSwagStudio/ViewModels/SwaggerGenerators/AspNetCoreToSwaggerGeneratorViewModel.cs index 9dac432c62..74f3b964b8 100644 --- a/src/NSwagStudio/ViewModels/SwaggerGenerators/AspNetCoreToSwaggerGeneratorViewModel.cs +++ b/src/NSwagStudio/ViewModels/SwaggerGenerators/AspNetCoreToSwaggerGeneratorViewModel.cs @@ -12,6 +12,7 @@ using Microsoft.Win32; using MyToolkit.Command; using NJsonSchema; +using NJsonSchema.Generation; using NSwag; using NSwag.Commands; using NSwag.Commands.SwaggerGeneration.AspNetCore; diff --git a/src/NSwagStudio/ViewModels/SwaggerGenerators/AssemblyTypeToSwaggerGeneratorViewModel.cs b/src/NSwagStudio/ViewModels/SwaggerGenerators/AssemblyTypeToSwaggerGeneratorViewModel.cs index 35bdb044f2..28fc8ab550 100644 --- a/src/NSwagStudio/ViewModels/SwaggerGenerators/AssemblyTypeToSwaggerGeneratorViewModel.cs +++ b/src/NSwagStudio/ViewModels/SwaggerGenerators/AssemblyTypeToSwaggerGeneratorViewModel.cs @@ -14,6 +14,7 @@ using Microsoft.Win32; using MyToolkit.Command; using NJsonSchema; +using NJsonSchema.Generation; using NSwag; using NSwag.Commands; using NSwag.Commands.SwaggerGeneration; diff --git a/src/NSwagStudio/ViewModels/SwaggerGenerators/WebApiToSwaggerGeneratorViewModel.cs b/src/NSwagStudio/ViewModels/SwaggerGenerators/WebApiToSwaggerGeneratorViewModel.cs index 94b2924765..bbbcf358f3 100644 --- a/src/NSwagStudio/ViewModels/SwaggerGenerators/WebApiToSwaggerGeneratorViewModel.cs +++ b/src/NSwagStudio/ViewModels/SwaggerGenerators/WebApiToSwaggerGeneratorViewModel.cs @@ -13,6 +13,7 @@ using Microsoft.Win32; using MyToolkit.Command; using NJsonSchema; +using NJsonSchema.Generation; using NSwag; using NSwag.Commands; using NSwag.Commands.SwaggerGeneration.WebApi; From 2920f38fcacde7c170240d96cd02f6104e3b315b Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 19:13:16 +0200 Subject: [PATCH 07/20] Fix window --- src/NSwagStudio/ViewModels/MainWindowModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NSwagStudio/ViewModels/MainWindowModel.cs b/src/NSwagStudio/ViewModels/MainWindowModel.cs index 68c188e70e..5a710507ac 100644 --- a/src/NSwagStudio/ViewModels/MainWindowModel.cs +++ b/src/NSwagStudio/ViewModels/MainWindowModel.cs @@ -72,7 +72,7 @@ public DocumentModel SelectedDocument public string NSwagVersion => SwaggerDocument.ToolchainVersion; - public string NJsonSchemaVersion => JsonSchema4.ToolchainVersion; + public string NJsonSchemaVersion => JsonSchema.ToolchainVersion; protected override async void OnLoaded() { From b8482cf1c4411d5aa65404a5ff7b58ac9daf5c81 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 19:33:35 +0200 Subject: [PATCH 08/20] Fix IsolatedCommandBase --- src/NSwag.Commands/Commands/IsolatedCommandBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NSwag.Commands/Commands/IsolatedCommandBase.cs b/src/NSwag.Commands/Commands/IsolatedCommandBase.cs index ca011a5348..201cc3c1e5 100644 --- a/src/NSwag.Commands/Commands/IsolatedCommandBase.cs +++ b/src/NSwag.Commands/Commands/IsolatedCommandBase.cs @@ -126,7 +126,7 @@ public IEnumerable GetBindingRedirects() { #if NET461 yield return new BindingRedirect("Newtonsoft.Json", typeof(JToken), "30ad4fe6b2a6aeed"); - yield return new BindingRedirect("Namotion.Reflection", typeof(JsonSchema), "c2f9c3bdfae56102"); + yield return new BindingRedirect("Namotion.Reflection", typeof(ContextualType), "c2f9c3bdfae56102"); yield return new BindingRedirect("NJsonSchema", typeof(JsonSchema), "c2f9c3bdfae56102"); yield return new BindingRedirect("NSwag.Core", typeof(SwaggerDocument), "c2d88086e098d109"); yield return new BindingRedirect("NSwag.SwaggerGeneration", typeof(SwaggerJsonSchemaGenerator), "c2d88086e098d109"); From 3aa4c0c92369245646f6266cfdbb9fdf31bd50e2 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 19:35:15 +0200 Subject: [PATCH 09/20] Revert to packages --- .../NSwag.AspNet.Owin.csproj | 2 +- .../NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.AssemblyLoader.csproj | 4 +- .../NSwag.CodeGeneration.CSharp.csproj | 4 +- .../NSwag.CodeGeneration.TypeScript.csproj | 4 +- .../NSwag.CodeGeneration.csproj | 4 +- src/NSwag.Commands/NSwag.Commands.csproj | 10 +- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core/NSwag.Core.csproj | 4 +- src/NSwag.Min.sln | 100 ------------- .../NSwag.SwaggerGeneration.AspNetCore.csproj | 2 +- .../NSwag.SwaggerGeneration.WebApi.csproj | 2 +- .../NSwag.SwaggerGeneration.csproj | 2 +- src/switcher.json | 132 +----------------- 14 files changed, 22 insertions(+), 252 deletions(-) diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index d177ac014b..b070d6b9e3 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -46,10 +46,10 @@ + - diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index cd9412fb88..359fac1722 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -23,9 +23,9 @@ + - \ No newline at end of file diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index 24bd6dc3c0..487c9449dd 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -24,6 +24,7 @@ TRACE;RELEASE;FullNet;NET451 + @@ -35,7 +36,4 @@ 4.3.0 - - - \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index 6f921f9d1b..b1a2895a47 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -47,10 +47,12 @@ - + + + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index fe5c9394e3..ed70cf46ec 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -43,10 +43,12 @@ - + + + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 1c4773c963..3831c86a92 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -19,13 +19,13 @@ + + - - \ No newline at end of file diff --git a/src/NSwag.Commands/NSwag.Commands.csproj b/src/NSwag.Commands/NSwag.Commands.csproj index e7dee4d904..6d6ee61ac1 100644 --- a/src/NSwag.Commands/NSwag.Commands.csproj +++ b/src/NSwag.Commands/NSwag.Commands.csproj @@ -66,16 +66,16 @@ + + + + + - - - - - diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index c4993c90e6..9a4c0c29d4 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -16,10 +16,10 @@ NSwag + - \ No newline at end of file diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 4af0d9a9da..0616064a03 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -23,6 +23,7 @@ + @@ -32,7 +33,4 @@ - - - \ No newline at end of file diff --git a/src/NSwag.Min.sln b/src/NSwag.Min.sln index 79a2fe0c80..6d68256729 100644 --- a/src/NSwag.Min.sln +++ b/src/NSwag.Min.sln @@ -77,16 +77,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NSwag.Sample.NETCore22", "N EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NSwag.Sample.NETCore30", "NSwag.Sample.NETCore30\NSwag.Sample.NETCore30.csproj", "{BEE63487-C130-4337-BB01-E3661D830CA6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema", "..\..\NJsonSchema\src\NJsonSchema\NJsonSchema.csproj", "{CD3840EC-6930-458C-B119-ED8509629B4C}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.Yaml", "..\..\NJsonSchema\src\NJsonSchema.Yaml\NJsonSchema.Yaml.csproj", "{A3034424-FB36-4E0F-935D-CA0B00A699AD}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.CodeGeneration", "..\..\NJsonSchema\src\NJsonSchema.CodeGeneration\NJsonSchema.CodeGeneration.csproj", "{1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.CodeGeneration.CSharp", "..\..\NJsonSchema\src\NJsonSchema.CodeGeneration.CSharp\NJsonSchema.CodeGeneration.CSharp.csproj", "{72C7B587-9B92-4C78-83E4-9DB2AC091244}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NJsonSchema.CodeGeneration.TypeScript", "..\..\NJsonSchema\src\NJsonSchema.CodeGeneration.TypeScript\NJsonSchema.CodeGeneration.TypeScript.csproj", "{7FBFD522-1E27-45E0-844C-C6C8AECE04D0}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -638,96 +628,6 @@ Global {BEE63487-C130-4337-BB01-E3661D830CA6}.ReleaseTypeScriptStrict|x64.Build.0 = Release|Any CPU {BEE63487-C130-4337-BB01-E3661D830CA6}.ReleaseTypeScriptStrict|x86.ActiveCfg = Release|Any CPU {BEE63487-C130-4337-BB01-E3661D830CA6}.ReleaseTypeScriptStrict|x86.Build.0 = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x64.ActiveCfg = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x64.Build.0 = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x86.ActiveCfg = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Debug|x86.Build.0 = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|Any CPU.Build.0 = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x64.ActiveCfg = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x64.Build.0 = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x86.ActiveCfg = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.Release|x86.Build.0 = Release|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU - {CD3840EC-6930-458C-B119-ED8509629B4C}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x64.ActiveCfg = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x64.Build.0 = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x86.ActiveCfg = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Debug|x86.Build.0 = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|Any CPU.Build.0 = Release|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x64.ActiveCfg = Release|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x64.Build.0 = Release|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x86.ActiveCfg = Release|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.Release|x86.Build.0 = Release|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU - {A3034424-FB36-4E0F-935D-CA0B00A699AD}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x64.ActiveCfg = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x64.Build.0 = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x86.ActiveCfg = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Debug|x86.Build.0 = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|Any CPU.Build.0 = Release|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x64.ActiveCfg = Release|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x64.Build.0 = Release|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x86.ActiveCfg = Release|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.Release|x86.Build.0 = Release|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU - {1EA477F8-EC1A-4D1D-A8B4-B48AF7281B37}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|Any CPU.Build.0 = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x64.ActiveCfg = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x64.Build.0 = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x86.ActiveCfg = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Debug|x86.Build.0 = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|Any CPU.ActiveCfg = Release|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|Any CPU.Build.0 = Release|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x64.ActiveCfg = Release|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x64.Build.0 = Release|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x86.ActiveCfg = Release|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.Release|x86.Build.0 = Release|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU - {72C7B587-9B92-4C78-83E4-9DB2AC091244}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x64.ActiveCfg = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x64.Build.0 = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x86.ActiveCfg = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Debug|x86.Build.0 = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|Any CPU.Build.0 = Release|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x64.ActiveCfg = Release|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x64.Build.0 = Release|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x86.ActiveCfg = Release|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.Release|x86.Build.0 = Release|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|Any CPU.ActiveCfg = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|Any CPU.Build.0 = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x64.ActiveCfg = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x64.Build.0 = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x86.ActiveCfg = Debug|Any CPU - {7FBFD522-1E27-45E0-844C-C6C8AECE04D0}.ReleaseTypeScriptStrict|x86.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj index de95308d03..4095e7c0d2 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj +++ b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj @@ -25,12 +25,12 @@ + - \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj index f443b3af04..244f453f23 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj @@ -22,12 +22,12 @@ + - \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj index 3565ee2ae3..e3c3ac5d3f 100644 --- a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj +++ b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj @@ -22,12 +22,12 @@ + - \ No newline at end of file diff --git a/src/switcher.json b/src/switcher.json index 2af1c9550a..2a88f4ff03 100644 --- a/src/switcher.json +++ b/src/switcher.json @@ -6,135 +6,5 @@ "NJsonSchema.CodeGeneration": "../../NJsonSchema/src/NJsonSchema.CodeGeneration/NJsonSchema.CodeGeneration.csproj", "NJsonSchema.CodeGeneration.CSharp": "../../NJsonSchema/src/NJsonSchema.CodeGeneration.CSharp/NJsonSchema.CodeGeneration.CSharp.csproj", "NJsonSchema.CodeGeneration.TypeScript": "../../NJsonSchema/src/NJsonSchema.CodeGeneration.TypeScript/NJsonSchema.CodeGeneration.TypeScript.csproj" - }, - "restore": [ - { - "name": "NSwag.CodeGeneration", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - }, - { - "packageName": "NJsonSchema.CodeGeneration", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.Core", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.AspNet.Owin", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.AspNet.WebApi", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.SwaggerGeneration", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.CodeGeneration.CSharp", - "packages": [ - { - "packageName": "NJsonSchema.CodeGeneration.CSharp", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.CodeGeneration.TypeScript", - "packages": [ - { - "packageName": "NJsonSchema.CodeGeneration.TypeScript", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.SwaggerGeneration.WebApi", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.Core.Yaml", - "packages": [ - { - "packageName": "NJsonSchema.Yaml", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.SwaggerGeneration.AspNetCore", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.Commands", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - }, - { - "packageName": "NJsonSchema.Yaml", - "version": "9.14.1" - }, - { - "packageName": "NJsonSchema.CodeGeneration", - "version": "9.14.1" - }, - { - "packageName": "NJsonSchema.CodeGeneration.CSharp", - "version": "9.14.1" - }, - { - "packageName": "NJsonSchema.CodeGeneration.TypeScript", - "version": "9.14.1" - } - ] - }, - { - "name": "NSwag.AssemblyLoader", - "packages": [ - { - "packageName": "NJsonSchema", - "version": "9.14.1" - } - ] - } - ] + } } \ No newline at end of file From be1837a371170bd88d32949869bc8dfc017a3f03 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 20:20:15 +0200 Subject: [PATCH 10/20] Update NJS --- .../NSwag.AspNet.Owin.csproj | 2 +- .../NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.AssemblyLoader.csproj | 2 +- .../NSwag.CodeGeneration.CSharp.csproj | 2 +- .../NSwag.CodeGeneration.TypeScript.csproj | 2 +- .../NSwag.CodeGeneration.csproj | 4 ++-- src/NSwag.Commands/NSwag.Commands.csproj | 10 +++++----- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core/NSwag.Core.csproj | 2 +- src/NSwag.Demo.Web/NSwag.Demo.Web.csproj | 7 +++++-- src/NSwag.Demo.Web/packages.config | 3 ++- .../NSwag.Integration.WebAPI.csproj | 7 +++++-- src/NSwag.Integration.WebAPI/packages.config | 3 ++- .../NSwag.Sample.NetGlobalAsax.csproj | 7 +++++-- .../packages.config | 3 ++- .../NSwag.SwaggerGeneration.AspNetCore.csproj | 2 +- ...Swag.SwaggerGeneration.WebApi.Tests.csproj | 15 +++++++++------ .../packages.config | 7 ++++--- .../NSwag.SwaggerGeneration.WebApi.csproj | 2 +- .../NSwag.SwaggerGeneration.csproj | 2 +- src/NSwag.Tests/NSwag.Tests.csproj | 7 +++++-- src/NSwag.Tests/packages.config | 3 ++- src/NSwagStudio/NSwagStudio.csproj | 19 +++++++++++-------- src/NSwagStudio/packages.config | 9 +++++---- 24 files changed, 74 insertions(+), 50 deletions(-) diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index b070d6b9e3..bd1a2487de 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -46,7 +46,7 @@ - + diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index 359fac1722..e5ab960217 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index 487c9449dd..3bae394475 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -24,7 +24,7 @@ TRACE;RELEASE;FullNet;NET451 - + diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index b1a2895a47..2b97ba10ca 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -53,6 +53,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index ed70cf46ec..1e55b96870 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -49,6 +49,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 3831c86a92..a4e53ae7bb 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/src/NSwag.Commands/NSwag.Commands.csproj b/src/NSwag.Commands/NSwag.Commands.csproj index 6d6ee61ac1..383295a474 100644 --- a/src/NSwag.Commands/NSwag.Commands.csproj +++ b/src/NSwag.Commands/NSwag.Commands.csproj @@ -66,11 +66,11 @@ - - - - - + + + + + diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index 9a4c0c29d4..0e879aedab 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -16,7 +16,7 @@ NSwag - + diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 0616064a03..b3ec8884cf 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj index 495a6d9200..ecb3723c8e 100644 --- a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj +++ b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj @@ -63,12 +63,15 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True + + ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.9.14.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Demo.Web/packages.config b/src/NSwag.Demo.Web/packages.config index 08abaf26b4..88ad3f3fe1 100644 --- a/src/NSwag.Demo.Web/packages.config +++ b/src/NSwag.Demo.Web/packages.config @@ -14,7 +14,8 @@ + - + \ No newline at end of file diff --git a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj index 42da50b12e..d77028924e 100644 --- a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj +++ b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj @@ -58,12 +58,15 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + + ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.9.14.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Integration.WebAPI/packages.config b/src/NSwag.Integration.WebAPI/packages.config index bbd1a488a5..d269a0c94e 100644 --- a/src/NSwag.Integration.WebAPI/packages.config +++ b/src/NSwag.Integration.WebAPI/packages.config @@ -9,7 +9,8 @@ + - + \ No newline at end of file diff --git a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj index 564a449202..a217b5bb4e 100644 --- a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj +++ b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj @@ -56,11 +56,14 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll + + ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.9.14.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Sample.NetGlobalAsax/packages.config b/src/NSwag.Sample.NetGlobalAsax/packages.config index 3b28cda107..081cc61321 100644 --- a/src/NSwag.Sample.NetGlobalAsax/packages.config +++ b/src/NSwag.Sample.NetGlobalAsax/packages.config @@ -26,8 +26,9 @@ + - + diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj index 4095e7c0d2..427c202d90 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj +++ b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj index dc055e792e..24356e791d 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj @@ -46,18 +46,21 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True + + ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.9.14.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.9.14.1\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.0\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.9.14.1\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.0\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll ..\packages\Swashbuckle.Core.5.5.3\lib\net40\Swashbuckle.Core.dll diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config index 19dcaf32ef..27e05e87d5 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config @@ -11,10 +11,11 @@ + - - - + + + diff --git a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj index 244f453f23..6aab02f836 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj index e3c3ac5d3f..01b4040367 100644 --- a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj +++ b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.Tests/NSwag.Tests.csproj b/src/NSwag.Tests/NSwag.Tests.csproj index 1ecf0379f6..8c4e4e1b8b 100644 --- a/src/NSwag.Tests/NSwag.Tests.csproj +++ b/src/NSwag.Tests/NSwag.Tests.csproj @@ -59,12 +59,15 @@ + + ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.9.14.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll diff --git a/src/NSwag.Tests/packages.config b/src/NSwag.Tests/packages.config index 6b572971be..4d8e00badc 100644 --- a/src/NSwag.Tests/packages.config +++ b/src/NSwag.Tests/packages.config @@ -3,6 +3,7 @@ + - + \ No newline at end of file diff --git a/src/NSwagStudio/NSwagStudio.csproj b/src/NSwagStudio/NSwagStudio.csproj index 582e522e8b..f3a8eab6b9 100644 --- a/src/NSwagStudio/NSwagStudio.csproj +++ b/src/NSwagStudio/NSwagStudio.csproj @@ -87,23 +87,26 @@ ..\packages\MyToolkit.Extended.2.5.16\lib\net45\MyToolkit.Extended.dll + + ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\NConsole.3.9.6519.30868\lib\net45\NConsole.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.9.14.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.9.14.1\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.0\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.CSharp.9.14.1\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll + + ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.0\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.9.14.1\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.0\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll diff --git a/src/NSwagStudio/packages.config b/src/NSwagStudio/packages.config index 8198f0afb6..c888113e13 100644 --- a/src/NSwagStudio/packages.config +++ b/src/NSwagStudio/packages.config @@ -8,12 +8,13 @@ + - - - - + + + + From 6927940773c9e98f9433fe852ab28152c61c616d Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Mon, 20 May 2019 20:44:32 +0200 Subject: [PATCH 11/20] Refactoring --- .../Processors/OperationResponseProcessor.cs | 3 ++- .../Processors/OperationResponseProcessorBase.cs | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs index 8efa9d8354..5607bb62f1 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs @@ -71,7 +71,8 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso if (IsVoidResponse(returnType) == false) { - var contextualReturnType = returnType.ToContextualType(context.MethodInfo.ReturnParameter?.GetCustomAttributes(false).OfType() ?? Enumerable.Empty()); + var returnTypeAttributes = context.MethodInfo.ReturnParameter?.GetCustomAttributes(false).OfType() ?? Enumerable.Empty(); + var contextualReturnType = returnType.ToContextualType(returnTypeAttributes); var typeDescription = _settings.ReflectionService.GetDescription( contextualReturnType, _settings.DefaultResponseReferenceTypeNullHandling, _settings); diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index ed18ec17d9..18053b9f89 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -139,7 +139,8 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable r.ResponseType).GetCommonBaseType(); - var contextualReturnType = returnType.ToContextualType(returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty()); + var returnParameterAttributes = returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty(); + var contextualReturnType = returnType.ToContextualType(returnParameterAttributes); var description = string.Join("\nor\n", statusCodeGroup.Select(r => r.Description)); @@ -219,11 +220,17 @@ private async Task> GenerateExpectedSchemasAsync private async Task LoadDefaultSuccessResponseAsync(ParameterInfo returnParameter, string successXmlDescription, OperationProcessorContext context) { var operation = context.OperationDescription.Operation; + var returnType = returnParameter.ParameterType; if (returnType == typeof(Task)) + { returnType = typeof(void); + } + while (returnType.Name == "Task`1" || returnType.Name == "ActionResult`1") + { returnType = returnType.GenericTypeArguments[0]; + } if (IsVoidResponse(returnType)) { @@ -234,7 +241,8 @@ private async Task LoadDefaultSuccessResponseAsync(ParameterInfo returnParameter } else { - var contextualReturnParameter = returnType.ToContextualType(returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty()); + var returnParameterAttributes = returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty(); + var contextualReturnParameter = returnType.ToContextualType(returnParameterAttributes); var typeDescription = _settings.ReflectionService.GetDescription(contextualReturnParameter, _settings); var responseSchema = await context.SchemaGenerator.GenerateWithReferenceAndNullabilityAsync( From 47729510bc36f8c06891e3e509db715ec9492998 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Tue, 21 May 2019 10:50:21 +0200 Subject: [PATCH 12/20] Update NJS --- .../NSwag.AspNet.Owin.csproj | 2 +- .../NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.AssemblyLoader.csproj | 2 +- .../NSwag.CodeGeneration.CSharp.csproj | 2 +- .../NSwag.CodeGeneration.TypeScript.csproj | 2 +- .../NSwag.CodeGeneration.csproj | 4 ++-- src/NSwag.Commands/NSwag.Commands.csproj | 10 +++++----- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core/NSwag.Core.csproj | 2 +- src/NSwag.Demo.Web/NSwag.Demo.Web.csproj | 8 ++++---- src/NSwag.Demo.Web/packages.config | 4 ++-- .../NSwag.Integration.WebAPI.csproj | 7 ++++--- src/NSwag.Integration.WebAPI/packages.config | 4 ++-- .../NSwag.Sample.NetGlobalAsax.csproj | 8 ++++---- .../packages.config | 4 ++-- .../NSwag.SwaggerGeneration.AspNetCore.csproj | 2 +- .../Processors/OperationResponseProcessor.cs | 2 +- ...Swag.SwaggerGeneration.WebApi.Tests.csproj | 16 +++++++-------- .../packages.config | 8 ++++---- .../NSwag.SwaggerGeneration.WebApi.csproj | 2 +- .../NSwag.SwaggerGeneration.csproj | 2 +- .../OperationResponseProcessorBase.cs | 10 ++++------ src/NSwag.Tests/NSwag.Tests.csproj | 8 ++++---- src/NSwag.Tests/packages.config | 4 ++-- src/NSwagStudio/NSwagStudio.csproj | 20 +++++++++---------- src/NSwagStudio/packages.config | 10 +++++----- 26 files changed, 73 insertions(+), 74 deletions(-) diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index 60ec9f019b..ba74679821 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -46,7 +46,7 @@ - + diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index 118c482a95..bb6d3482c4 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index a2c0830d12..f7c180666a 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -24,7 +24,7 @@ TRACE;RELEASE;FullNet;NET451 - + diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index 1f34766e74..1e24fb548d 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -53,6 +53,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index 506a929479..cdf7c474e8 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -49,6 +49,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 703811b3f5..2577f5423a 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/src/NSwag.Commands/NSwag.Commands.csproj b/src/NSwag.Commands/NSwag.Commands.csproj index 9e84acf9d4..2377bb5bf8 100644 --- a/src/NSwag.Commands/NSwag.Commands.csproj +++ b/src/NSwag.Commands/NSwag.Commands.csproj @@ -66,11 +66,11 @@ - - - - - + + + + + diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index 4f16648654..5120f52a76 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -16,7 +16,7 @@ NSwag - + diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 96a826fd31..37a7588985 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj index ecb3723c8e..0e50c000bb 100644 --- a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj +++ b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj @@ -63,15 +63,15 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True - - ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Demo.Web/packages.config b/src/NSwag.Demo.Web/packages.config index 88ad3f3fe1..5a2e7307ae 100644 --- a/src/NSwag.Demo.Web/packages.config +++ b/src/NSwag.Demo.Web/packages.config @@ -14,8 +14,8 @@ - + - + \ No newline at end of file diff --git a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj index d77028924e..7b6e1ebcd0 100644 --- a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj +++ b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj @@ -59,14 +59,15 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + True ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Integration.WebAPI/packages.config b/src/NSwag.Integration.WebAPI/packages.config index d269a0c94e..2ed1860909 100644 --- a/src/NSwag.Integration.WebAPI/packages.config +++ b/src/NSwag.Integration.WebAPI/packages.config @@ -9,8 +9,8 @@ - + - + \ No newline at end of file diff --git a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj index a217b5bb4e..20279f0928 100644 --- a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj +++ b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj @@ -56,14 +56,14 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - - ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Sample.NetGlobalAsax/packages.config b/src/NSwag.Sample.NetGlobalAsax/packages.config index 081cc61321..b8c0408e0e 100644 --- a/src/NSwag.Sample.NetGlobalAsax/packages.config +++ b/src/NSwag.Sample.NetGlobalAsax/packages.config @@ -26,9 +26,9 @@ - + - + diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj index e6a3592170..3378f472cb 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj +++ b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs index 5607bb62f1..156c1f3d69 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationResponseProcessor.cs @@ -71,7 +71,7 @@ public async Task ProcessAsync(OperationProcessorContext operationProcesso if (IsVoidResponse(returnType) == false) { - var returnTypeAttributes = context.MethodInfo.ReturnParameter?.GetCustomAttributes(false).OfType() ?? Enumerable.Empty(); + var returnTypeAttributes = context.MethodInfo.ReturnParameter?.GetCustomAttributes(false).OfType(); var contextualReturnType = returnType.ToContextualType(returnTypeAttributes); var typeDescription = _settings.ReflectionService.GetDescription( diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj index 24356e791d..e7db48b064 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj @@ -46,21 +46,21 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True - - ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.10.0.0\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.1\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.0\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.1\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll ..\packages\Swashbuckle.Core.5.5.3\lib\net40\Swashbuckle.Core.dll diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config index 27e05e87d5..a7f52bfdf5 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config @@ -11,11 +11,11 @@ - + - - - + + + diff --git a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj index 5c2ec20233..75714b2651 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj index 00b3f68fb7..c1ae3bf290 100644 --- a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj +++ b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index 41578e592b..0472802261 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -57,13 +57,11 @@ public async Task ProcessResponseTypeAttributes(OperationProcessorContext operat /// The task. protected async Task UpdateResponseDescriptionAsync(OperationProcessorContext operationProcessorContext) { - var returnParameter = operationProcessorContext.MethodInfo.ReturnParameter; + var returnParameter = operationProcessorContext.MethodInfo.ReturnParameter.ToContextualParameter(); + var operationXmlDocs = await operationProcessorContext.MethodInfo.GetXmlDocumentationAsync(); var operationXmlDocsNodes = operationXmlDocs?.Nodes()?.OfType(); - var returnParameterXmlDocs = await returnParameter - .ToContextualParameter(returnParameter?.GetCustomAttributes(false).Cast()) - .GetDescriptionAsync() - .ConfigureAwait(false) ?? string.Empty; + var returnParameterXmlDocs = await returnParameter.GetDescriptionAsync().ConfigureAwait(false) ?? string.Empty; if (!string.IsNullOrEmpty(returnParameterXmlDocs) || operationXmlDocsNodes?.Any() == true) { @@ -139,7 +137,7 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable r.ResponseType).GetCommonBaseType(); - var returnParameterAttributes = returnParameter?.GetCustomAttributes(false)?.OfType() ?? Enumerable.Empty(); + var returnParameterAttributes = returnParameter?.GetCustomAttributes(false).OfType(); var contextualReturnType = returnType.ToContextualType(returnParameterAttributes); var description = string.Join("\nor\n", statusCodeGroup.Select(r => r.Description)); diff --git a/src/NSwag.Tests/NSwag.Tests.csproj b/src/NSwag.Tests/NSwag.Tests.csproj index 8c4e4e1b8b..030a0457f6 100644 --- a/src/NSwag.Tests/NSwag.Tests.csproj +++ b/src/NSwag.Tests/NSwag.Tests.csproj @@ -59,15 +59,15 @@ - - ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll diff --git a/src/NSwag.Tests/packages.config b/src/NSwag.Tests/packages.config index 4d8e00badc..b403e9cebe 100644 --- a/src/NSwag.Tests/packages.config +++ b/src/NSwag.Tests/packages.config @@ -3,7 +3,7 @@ - + - + \ No newline at end of file diff --git a/src/NSwagStudio/NSwagStudio.csproj b/src/NSwagStudio/NSwagStudio.csproj index f3a8eab6b9..20a01858dc 100644 --- a/src/NSwagStudio/NSwagStudio.csproj +++ b/src/NSwagStudio/NSwagStudio.csproj @@ -87,8 +87,8 @@ ..\packages\MyToolkit.Extended.2.5.16\lib\net45\MyToolkit.Extended.dll - - ..\packages\Namotion.Reflection.1.0.0\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll ..\packages\NConsole.3.9.6519.30868\lib\net45\NConsole.dll @@ -96,17 +96,17 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.10.0.0\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.10.0.0\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.1\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.0\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll + + ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.1\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.0\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.1\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll diff --git a/src/NSwagStudio/packages.config b/src/NSwagStudio/packages.config index c888113e13..2d890dd860 100644 --- a/src/NSwagStudio/packages.config +++ b/src/NSwagStudio/packages.config @@ -8,13 +8,13 @@ - + - - - - + + + + From 944173038304dcc6f59f3d802cc36658f7228666 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Tue, 21 May 2019 23:24:25 +0200 Subject: [PATCH 13/20] Fixes --- .../Models/TypeScriptFileTemplateModel.cs | 4 ++-- .../Processors/OperationParameterProcessor.cs | 2 ++ .../Processors/OperationResponseProcessorBase.cs | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptFileTemplateModel.cs b/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptFileTemplateModel.cs index 9cddd5ea8b..83ed16b1e4 100644 --- a/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptFileTemplateModel.cs +++ b/src/NSwag.CodeGeneration.TypeScript/Models/TypeScriptFileTemplateModel.cs @@ -43,10 +43,10 @@ public TypeScriptFileTemplateModel( _settings = settings; _resolver = resolver; - _clientCode = clientTypes.Concatenate(); + _clientCode = clientTypes.OrderByBaseDependency().Concatenate(); _clientTypes = clientTypes; - Types = dtoTypes.Concatenate(); + Types = dtoTypes.OrderByBaseDependency().Concatenate(); ExtensionCodeBottom = GenerateExtensionCodeAfter(); Framework = new TypeScriptFrameworkModel(settings); } diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index d7c7387dee..1c471afcd0 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -377,7 +377,9 @@ private void InitializeFileParameter(SwaggerParameter operationParameter, bool i operationParameter.Kind = SwaggerParameterKind.FormData; if (isFileArray) + { operationParameter.CollectionFormat = SwaggerParameterCollectionFormat.Multi; + } } private class ExtendedApiParameterDescription diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index 0472802261..305e7b2a73 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -137,7 +137,7 @@ private async Task ProcessOperationDescriptionsAsync(IEnumerable r.ResponseType).GetCommonBaseType(); - var returnParameterAttributes = returnParameter?.GetCustomAttributes(false).OfType(); + var returnParameterAttributes = returnParameter?.GetCustomAttributes(false)?.OfType(); var contextualReturnType = returnType.ToContextualType(returnParameterAttributes); var description = string.Join("\nor\n", statusCodeGroup.Select(r => r.Description)); From 1c7bb358d6816c3ebe393962bcd488f171ebc40c Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Wed, 22 May 2019 18:11:07 +0200 Subject: [PATCH 14/20] Change TransformToExternalPath default and update for NJS --- src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs | 9 +++++++-- .../Processors/OperationParameterProcessor.cs | 20 +++++++++---------- .../OperationResponseProcessorBase.cs | 2 +- ...OperationSummaryAndDescriptionProcessor.cs | 4 ++-- .../SwaggerGenerator.cs | 2 +- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs b/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs index 5bade86cb5..3d742417d9 100644 --- a/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs +++ b/src/NSwag.AspNetCore/SwaggerUiSettingsBase.cs @@ -33,7 +33,12 @@ public abstract class SwaggerUiSettingsBase : SwaggerSettings /// Initializes a new instance of the class. public SwaggerUiSettingsBase() { - TransformToExternalPath = (internalUiRoute, request) => internalUiRoute; + TransformToExternalPath = (internalUiRoute, request) => + { + return internalUiRoute.StartsWith("/") && internalUiRoute.StartsWith(request.PathBase.ToString()) == false + ? request.PathBase + internalUiRoute + : internalUiRoute; + }; } /// Gets or sets the internal swagger UI route (must start with '/'). @@ -82,7 +87,7 @@ protected string GetCustomScriptHtml() { return string.Empty; } - + var uriString = System.Net.WebUtility.HtmlEncode(CustomJavaScriptUri.OriginalString); return $""; diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index 0beef86f74..7deca9d3af 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -52,13 +52,13 @@ public async Task ProcessAsync(OperationProcessorContext context) { var parameterName = contextualParameter.Name; - dynamic fromRouteAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromRouteAttribute"); - dynamic fromHeaderAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); - dynamic fromFormAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("Microsoft.AspNetCore.Mvc.FromFormAttribute"); + dynamic fromRouteAttribute = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("Microsoft.AspNetCore.Mvc.FromRouteAttribute"); + dynamic fromHeaderAttribute = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("Microsoft.AspNetCore.Mvc.FromHeaderAttribute"); + dynamic fromFormAttribute = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("Microsoft.AspNetCore.Mvc.FromFormAttribute"); - var fromBodyAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("FromBodyAttribute", TypeNameStyle.Name); - var fromUriAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("FromUriAttribute", TypeNameStyle.Name) ?? - contextualParameter.ContextAttributes.TryGetAssignableToTypeName("FromQueryAttribute", TypeNameStyle.Name); + var fromBodyAttribute = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("FromBodyAttribute", TypeNameStyle.Name); + var fromUriAttribute = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("FromUriAttribute", TypeNameStyle.Name) ?? + contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("FromQueryAttribute", TypeNameStyle.Name); string bodyParameterName = fromBodyAttribute.TryGetPropertyValue("Name") ?? parameterName; string uriParameterName = fromUriAttribute.TryGetPropertyValue("Name") ?? parameterName; @@ -120,12 +120,12 @@ public async Task ProcessAsync(OperationProcessorContext context) if (parameterInfo.IsComplexType) { // Check for a custom ParameterBindingAttribute (OWIN/WebAPI only) - var parameterBindingAttribute = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("ParameterBindingAttribute", TypeNameStyle.Name); + var parameterBindingAttribute = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("ParameterBindingAttribute", TypeNameStyle.Name); if (parameterBindingAttribute != null && fromBodyAttribute == null && fromUriAttribute == null && !_settings.IsAspNetCore) { // Try to find a [WillReadBody] attribute on either the action parameter or the bindingAttribute's class var willReadBodyAttribute = contextualParameter.ContextAttributes.Concat(parameterBindingAttribute.GetType().GetTypeInfo().GetCustomAttributes()) - .TryGetAssignableToTypeName("WillReadBodyAttribute", TypeNameStyle.Name); + .FirstAssignableToTypeNameOrDefault("WillReadBodyAttribute", TypeNameStyle.Name); if (willReadBodyAttribute == null) operationParameter = await AddBodyParameterAsync(context, bodyParameterName, contextualParameter).ConfigureAwait(false); @@ -363,7 +363,7 @@ private async Task AddPrimitiveParametersFromUriAsync( } else { - foreach (var contextualProperty in contextualParameter.Type.GetContextualRuntimeProperties()) + foreach (var contextualProperty in contextualParameter.Type.GetContextualProperties()) { if (contextualProperty.ContextAttributes.All(a => a.GetType().Name != "SwaggerIgnoreAttribute" && a.GetType().Name != "JsonIgnoreAttribute")) { @@ -383,7 +383,7 @@ private async Task AddPrimitiveParametersFromUriAsync( propertyName = fromHeaderAttribute?.Name; } - var propertySummary = await contextualProperty.PropertyInfo.GetXmlSummaryAsync().ConfigureAwait(false); + var propertySummary = await contextualProperty.PropertyInfo.GetXmlDocsSummaryAsync().ConfigureAwait(false); var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(propertyName, propertySummary, contextualProperty).ConfigureAwait(false); // TODO: Check if required can be controlled with mechanisms other than RequiredAttribute diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs index 305e7b2a73..3d130e73b7 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationResponseProcessorBase.cs @@ -59,7 +59,7 @@ protected async Task UpdateResponseDescriptionAsync(OperationProcessorContext op { var returnParameter = operationProcessorContext.MethodInfo.ReturnParameter.ToContextualParameter(); - var operationXmlDocs = await operationProcessorContext.MethodInfo.GetXmlDocumentationAsync(); + var operationXmlDocs = await operationProcessorContext.MethodInfo.GetXmlDocsElementAsync(); var operationXmlDocsNodes = operationXmlDocs?.Nodes()?.OfType(); var returnParameterXmlDocs = await returnParameter.GetDescriptionAsync().ConfigureAwait(false) ?? string.Empty; diff --git a/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs b/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs index 5d44d0691f..8a3eb90980 100644 --- a/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs +++ b/src/NSwag.SwaggerGeneration/Processors/OperationSummaryAndDescriptionProcessor.cs @@ -33,12 +33,12 @@ public async Task ProcessAsync(OperationProcessorContext context) } else { - var summary = await context.MethodInfo.GetXmlSummaryAsync().ConfigureAwait(false); + var summary = await context.MethodInfo.GetXmlDocsSummaryAsync().ConfigureAwait(false); if (summary != string.Empty) context.OperationDescription.Operation.Summary = summary; } - var remarks = await context.MethodInfo.GetXmlRemarksAsync().ConfigureAwait(false); + var remarks = await context.MethodInfo.GetXmlDocsRemarksAsync().ConfigureAwait(false); if (remarks != string.Empty) { context.OperationDescription.Operation.Description = remarks; diff --git a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs index 8330f7b3d9..f9f722ba29 100644 --- a/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs +++ b/src/NSwag.SwaggerGeneration/SwaggerGenerator.cs @@ -142,7 +142,7 @@ public async Task CreatePrimitiveParameterAsync( } operationParameter.Name = name; - operationParameter.IsRequired = contextualParameter.ContextAttributes.TryGetAssignableToTypeName("RequiredAttribute", TypeNameStyle.Name) != null; + operationParameter.IsRequired = contextualParameter.ContextAttributes.FirstAssignableToTypeNameOrDefault("RequiredAttribute", TypeNameStyle.Name) != null; if (typeDescription.Type.HasFlag(JsonObjectType.Array)) { From d37bf1405584b1421088ae824dc1a2237c8d15de Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Thu, 23 May 2019 15:28:19 +0200 Subject: [PATCH 15/20] Fix web api OperationParameterProcessor --- .../Processors/OperationParameterProcessor.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index 7deca9d3af..2328d21ff9 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -41,7 +41,7 @@ public OperationParameterProcessor(WebApiToSwaggerGeneratorSettings settings) public async Task ProcessAsync(OperationProcessorContext context) { var httpPath = context.OperationDescription.Path; - var parameters = context.MethodInfo.GetParameters().ToList(); + var parameters = context.MethodInfo.GetParameters(); var position = 1; foreach (var contextualParameter in parameters.Select(p => p.ToContextualParameter()) @@ -215,7 +215,7 @@ private void EnsureSingleBodyParameter(SwaggerOperationDescription operationDesc private void UpdateConsumedTypes(SwaggerOperationDescription operationDescription) { - if (operationDescription.Operation.ActualParameters.Any(p => p.IsBinary)) + if (operationDescription.Operation.ActualParameters.Any(p => p.ActualSchema.IsBinary)) { operationDescription.Operation.TryAddConsumes("multipart/form-data"); } @@ -237,7 +237,7 @@ private async Task TryAddFileParameterAsync( { var isFileArray = IsFileArray(contextualParameter.Type, typeInfo); var hasSwaggerFileAttribute = contextualParameter.Attributes - .Any(a => a.GetType().IsAssignableToTypeName("SwaggerFileAttribute", TypeNameStyle.Name)); + .FirstAssignableToTypeNameOrDefault("SwaggerFileAttribute", TypeNameStyle.Name) != null; if (typeInfo.Type == JsonObjectType.File || typeInfo.Format == JsonFormatStrings.Binary || @@ -272,7 +272,7 @@ private bool IsFileArray(Type type, JsonTypeDescription typeInfo) if (typeInfo.Type == JsonObjectType.Array && type.GenericTypeArguments.Any()) { - var description = _settings.ReflectionService.GetDescription(type.ToContextualType(), _settings); + var description = _settings.ReflectionService.GetDescription(type.GenericTypeArguments[0].ToContextualType(), _settings); if (description.Type == JsonObjectType.File || description.Format == JsonFormatStrings.Binary) { From c80bf7d4f5aa68dec84746295ac9db7b8c5a35b6 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Thu, 23 May 2019 21:03:50 +0200 Subject: [PATCH 16/20] Correctly set parameter value, closes #2010 --- .../NSwag.AspNet.Owin.csproj | 2 +- .../NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.AssemblyLoader.csproj | 2 +- .../NSwag.CodeGeneration.CSharp.csproj | 2 +- .../NSwag.CodeGeneration.TypeScript.csproj | 2 +- .../NSwag.CodeGeneration.csproj | 4 +- src/NSwag.Commands/NSwag.Commands.csproj | 10 +- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core/NSwag.Core.csproj | 2 +- src/NSwag.Demo.Web/NSwag.Demo.Web.csproj | 8 +- src/NSwag.Demo.Web/packages.config | 4 +- .../NSwag.Integration.WebAPI.csproj | 6 +- src/NSwag.Integration.WebAPI/packages.config | 4 +- .../NSwag.Sample.NetGlobalAsax.csproj | 8 +- .../packages.config | 4 +- .../Parameters/DefaultParametersController.cs | 27 +++++ .../Parameters/DefaultParametersTests.cs | 100 ++++++++++++++++++ .../NSwag.SwaggerGeneration.AspNetCore.csproj | 2 +- .../Processors/OperationParameterProcessor.cs | 20 +++- ...Swag.SwaggerGeneration.WebApi.Tests.csproj | 16 +-- .../packages.config | 8 +- .../NSwag.SwaggerGeneration.WebApi.csproj | 2 +- .../Processors/OperationParameterProcessor.cs | 35 ++++-- .../NSwag.SwaggerGeneration.csproj | 2 +- src/NSwag.Tests/NSwag.Tests.csproj | 8 +- src/NSwag.Tests/packages.config | 4 +- src/NSwagStudio/NSwagStudio.csproj | 20 ++-- src/NSwagStudio/packages.config | 10 +- 28 files changed, 239 insertions(+), 77 deletions(-) create mode 100644 src/NSwag.SwaggerGeneration.AspNetCore.Tests.Web/Controllers/Parameters/DefaultParametersController.cs create mode 100644 src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index ba74679821..d9f68e906b 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -46,7 +46,7 @@ - + diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index bb6d3482c4..477fc24da0 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index f7c180666a..a42556e20a 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -24,7 +24,7 @@ TRACE;RELEASE;FullNet;NET451 - + diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index 1e24fb548d..cc1496f69e 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -53,6 +53,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index cdf7c474e8..09038a5897 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -49,6 +49,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index 2577f5423a..f0ef2191a8 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/src/NSwag.Commands/NSwag.Commands.csproj b/src/NSwag.Commands/NSwag.Commands.csproj index 2377bb5bf8..f4aea01c1d 100644 --- a/src/NSwag.Commands/NSwag.Commands.csproj +++ b/src/NSwag.Commands/NSwag.Commands.csproj @@ -66,11 +66,11 @@ - - - - - + + + + + diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index 5120f52a76..70b71e0233 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -16,7 +16,7 @@ NSwag - + diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 37a7588985..7131fa9f2c 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj index 0e50c000bb..387d05859e 100644 --- a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj +++ b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj @@ -63,15 +63,15 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True - - ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Demo.Web/packages.config b/src/NSwag.Demo.Web/packages.config index 5a2e7307ae..67446f06be 100644 --- a/src/NSwag.Demo.Web/packages.config +++ b/src/NSwag.Demo.Web/packages.config @@ -14,8 +14,8 @@ - + - + \ No newline at end of file diff --git a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj index 7b6e1ebcd0..d7164728e2 100644 --- a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj +++ b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj @@ -59,15 +59,15 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll True ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Integration.WebAPI/packages.config b/src/NSwag.Integration.WebAPI/packages.config index 2ed1860909..8ffefbc79c 100644 --- a/src/NSwag.Integration.WebAPI/packages.config +++ b/src/NSwag.Integration.WebAPI/packages.config @@ -9,8 +9,8 @@ - + - + \ No newline at end of file diff --git a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj index 20279f0928..ae02b7c38c 100644 --- a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj +++ b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj @@ -56,14 +56,14 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.1.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - - ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Sample.NetGlobalAsax/packages.config b/src/NSwag.Sample.NetGlobalAsax/packages.config index b8c0408e0e..f62d3b087f 100644 --- a/src/NSwag.Sample.NetGlobalAsax/packages.config +++ b/src/NSwag.Sample.NetGlobalAsax/packages.config @@ -26,9 +26,9 @@ - + - + diff --git a/src/NSwag.SwaggerGeneration.AspNetCore.Tests.Web/Controllers/Parameters/DefaultParametersController.cs b/src/NSwag.SwaggerGeneration.AspNetCore.Tests.Web/Controllers/Parameters/DefaultParametersController.cs new file mode 100644 index 0000000000..48c1a745a4 --- /dev/null +++ b/src/NSwag.SwaggerGeneration.AspNetCore.Tests.Web/Controllers/Parameters/DefaultParametersController.cs @@ -0,0 +1,27 @@ +using Microsoft.AspNetCore.Mvc; + +namespace NSwag.SwaggerGeneration.AspNetCore.Tests.Web.Controllers.Parameters +{ + [ApiController] + [Route("api/[controller]")] + public class DefaultParametersController : Controller + { + [HttpGet("WithDefault")] + public ActionResult WithDefault(int? parameter = 5) + { + return Ok(); + } + + [HttpGet("WithDefaultEnum")] + public ActionResult WithDefaultEnum(MyEnum parameter = MyEnum.Def) + { + return Ok(); + } + + public enum MyEnum + { + Abc, + Def + } + } +} \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs b/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs new file mode 100644 index 0000000000..4d0bb3bc3e --- /dev/null +++ b/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs @@ -0,0 +1,100 @@ +using System.Linq; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Serialization; +using NJsonSchema; +using NSwag.SwaggerGeneration.AspNetCore.Tests.Web.Controllers.Parameters; +using Xunit; + +namespace NSwag.SwaggerGeneration.AspNetCore.Tests.Parameters +{ + public class DefaultParametersTests : AspNetCoreTestsBase + { + [Fact] + public async Task When_parameter_has_default_and_schema_type_is_OpenApi3_then_schema_default_is_set() + { + // Arrange + var settings = new AspNetCoreToSwaggerGeneratorSettings + { + SchemaType = SchemaType.OpenApi3, + RequireParametersWithoutDefault = true + }; + + // Act + var document = await GenerateDocumentAsync(settings, typeof(DefaultParametersController)); + var json = document.ToJson(); + + // Assert + var operation = document.Operations.First(o => o.Path.Contains(nameof(DefaultParametersController.WithDefault))).Operation; + + Assert.Equal(5, operation.Parameters.First().Schema.Default); + } + + [Fact] + public async Task When_parameter_has_default_and_schema_type_is_OpenApi3_then_schema_default_is_set_on_oneOf_reference() + { + // Arrange + var settings = new AspNetCoreToSwaggerGeneratorSettings + { + SchemaType = SchemaType.OpenApi3, + RequireParametersWithoutDefault = true + }; + + // Act + var document = await GenerateDocumentAsync(settings, typeof(DefaultParametersController)); + var json = document.ToJson(); + + // Assert + var operation = document.Operations.First(o => o.Path.Contains(nameof(DefaultParametersController.WithDefaultEnum))).Operation; + + Assert.Equal(5, operation.Parameters.First().Schema.Default); + Assert.True(operation.Parameters.First().Schema.OneOf.Any()); + } + + [Fact] + public async Task When_parameter_has_default_and_schema_type_is_OpenApi3_then_schema_default_is_set_and_is_string() + { + // Arrange + var settings = new AspNetCoreToSwaggerGeneratorSettings + { + SchemaType = SchemaType.OpenApi3, + RequireParametersWithoutDefault = true, + SerializerSettings = new JsonSerializerSettings + { + Converters = { new StringEnumConverter() } + } + }; + + // Act + var document = await GenerateDocumentAsync(settings, typeof(DefaultParametersController)); + var json = document.ToJson(); + + // Assert + var operation = document.Operations.First(o => o.Path.Contains(nameof(DefaultParametersController.WithDefaultEnum))).Operation; + + Assert.Equal("Def", operation.Parameters.First().Schema.Default); + } + + [Fact] + public async Task When_parameter_has_default_and_schema_type_is_Swagger2_then_parameter_default_is_set() + { + // Arrange + var settings = new AspNetCoreToSwaggerGeneratorSettings + { + SchemaType = SchemaType.Swagger2, + RequireParametersWithoutDefault = true + }; + + // Act + var document = await GenerateDocumentAsync(settings, typeof(DefaultParametersController)); + var json = document.ToJson(); + + // Assert + var operation = document.Operations.First(o => o.Path.Contains(nameof(DefaultParametersController.WithDefault))).Operation; + + Assert.Null(operation.Parameters.First().Schema); + Assert.Equal(5, operation.Parameters.First().Default); + } + } +} \ No newline at end of file diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj index 3378f472cb..28e8cb30fa 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj +++ b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index 1c471afcd0..c4e1c22bb3 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -364,7 +364,25 @@ private async Task CreatePrimitiveParameterAsync( if (extendedApiParameter.ParameterInfo?.HasDefaultValue == true) { - operationParameter.Default = extendedApiParameter.ParameterInfo.DefaultValue; + var defaultValue = context.SchemaGenerator + .ConvertDefaultValue(contextualParameter, extendedApiParameter.ParameterInfo.DefaultValue); + + if (_settings.SchemaType == SchemaType.Swagger2) + { + operationParameter.Default = defaultValue; + } + else if (operationParameter.Schema.HasReference) + { + operationParameter.Schema = new JsonSchema + { + Default = defaultValue, + OneOf = { operationParameter.Schema } + }; + } + else + { + operationParameter.Schema.Default = defaultValue; + } } operationParameter.IsRequired = extendedApiParameter.IsRequired(_settings.RequireParametersWithoutDefault); diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj index e7db48b064..9b5c4952da 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj @@ -46,21 +46,21 @@ ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll True - - ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.10.0.1\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.4\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.1\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.4\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll ..\packages\Swashbuckle.Core.5.5.3\lib\net40\Swashbuckle.Core.dll diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config index a7f52bfdf5..3ff06f7f79 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config @@ -11,11 +11,11 @@ - + - - - + + + diff --git a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj index 75714b2651..61fbb3c63f 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index 2328d21ff9..20ff6f6996 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -141,7 +141,7 @@ public async Task ProcessAsync(OperationProcessorContext context) // If we are not reading from the body, then treat this as a primitive. // This may seem odd, but it allows for primitive -> custom complex-type bindings which are very common // In this case, the API author should use a TypeMapper to define the parameter - operationParameter = await AddPrimitiveParameterAsync(uriParameterName, context.OperationDescription.Operation, contextualParameter, context.SwaggerGenerator).ConfigureAwait(false); + operationParameter = await AddPrimitiveParameterAsync(uriParameterName, context, contextualParameter).ConfigureAwait(false); } } } @@ -163,8 +163,7 @@ public async Task ProcessAsync(OperationProcessorContext context) } else { - operationParameter = await AddPrimitiveParameterAsync( - uriParameterName, context.OperationDescription.Operation, contextualParameter, context.SwaggerGenerator).ConfigureAwait(false); + operationParameter = await AddPrimitiveParameterAsync(uriParameterName, context, contextualParameter).ConfigureAwait(false); } } } @@ -421,18 +420,36 @@ private async Task AddPrimitiveParametersFromUriAsync( } private async Task AddPrimitiveParameterAsync( - string name, SwaggerOperation operation, ContextualParameterInfo parameter, SwaggerGenerator swaggerGenerator) + string name, OperationProcessorContext context, ContextualParameterInfo contextualParameter) { - var operationParameter = await swaggerGenerator.CreatePrimitiveParameterAsync(name, parameter).ConfigureAwait(false); + var operationParameter = await context.SwaggerGenerator.CreatePrimitiveParameterAsync(name, contextualParameter).ConfigureAwait(false); operationParameter.Kind = SwaggerParameterKind.Query; - operationParameter.IsRequired = operationParameter.IsRequired || parameter.ParameterInfo.HasDefaultValue == false; + operationParameter.IsRequired = operationParameter.IsRequired || contextualParameter.ParameterInfo.HasDefaultValue == false; - if (parameter.ParameterInfo.HasDefaultValue) + if (contextualParameter.ParameterInfo.HasDefaultValue) { - operationParameter.Default = parameter.ParameterInfo.DefaultValue; + var defaultValue = context.SchemaGenerator.ConvertDefaultValue( + contextualParameter, contextualParameter.ParameterInfo.DefaultValue); + + if (_settings.SchemaType == SchemaType.Swagger2) + { + operationParameter.Default = defaultValue; + } + else if (operationParameter.Schema.HasReference) + { + operationParameter.Schema = new JsonSchema + { + Default = defaultValue, + OneOf = { operationParameter.Schema } + }; + } + else + { + operationParameter.Schema.Default = defaultValue; + } } - operation.Parameters.Add(operationParameter); + context.OperationDescription.Operation.Parameters.Add(operationParameter); return operationParameter; } diff --git a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj index c1ae3bf290..594d4c42fc 100644 --- a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj +++ b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.Tests/NSwag.Tests.csproj b/src/NSwag.Tests/NSwag.Tests.csproj index 030a0457f6..ec6ad67e4f 100644 --- a/src/NSwag.Tests/NSwag.Tests.csproj +++ b/src/NSwag.Tests/NSwag.Tests.csproj @@ -59,15 +59,15 @@ - - ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll diff --git a/src/NSwag.Tests/packages.config b/src/NSwag.Tests/packages.config index b403e9cebe..cbca06c2e5 100644 --- a/src/NSwag.Tests/packages.config +++ b/src/NSwag.Tests/packages.config @@ -3,7 +3,7 @@ - + - + \ No newline at end of file diff --git a/src/NSwagStudio/NSwagStudio.csproj b/src/NSwagStudio/NSwagStudio.csproj index 20a01858dc..548d596346 100644 --- a/src/NSwagStudio/NSwagStudio.csproj +++ b/src/NSwagStudio/NSwagStudio.csproj @@ -87,8 +87,8 @@ ..\packages\MyToolkit.Extended.2.5.16\lib\net45\MyToolkit.Extended.dll - - ..\packages\Namotion.Reflection.1.0.1\lib\net45\Namotion.Reflection.dll + + ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll ..\packages\NConsole.3.9.6519.30868\lib\net45\NConsole.dll @@ -96,17 +96,17 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.10.0.1\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.10.0.1\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.4\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.1\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll + + ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.4\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.1\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.4\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll diff --git a/src/NSwagStudio/packages.config b/src/NSwagStudio/packages.config index 2d890dd860..2802726062 100644 --- a/src/NSwagStudio/packages.config +++ b/src/NSwagStudio/packages.config @@ -8,13 +8,13 @@ - + - - - - + + + + From 5c0d92a3f2f94e6c182f88104feee365108961b4 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Fri, 24 May 2019 10:52:55 +0200 Subject: [PATCH 17/20] Fix test --- .../Parameters/DefaultParametersTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs b/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs index 4d0bb3bc3e..6735574ed5 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore.Tests/Parameters/DefaultParametersTests.cs @@ -6,6 +6,7 @@ using NJsonSchema; using NSwag.SwaggerGeneration.AspNetCore.Tests.Web.Controllers.Parameters; using Xunit; +using static NSwag.SwaggerGeneration.AspNetCore.Tests.Web.Controllers.Parameters.DefaultParametersController; namespace NSwag.SwaggerGeneration.AspNetCore.Tests.Parameters { @@ -48,7 +49,7 @@ public async Task When_parameter_has_default_and_schema_type_is_OpenApi3_then_sc // Assert var operation = document.Operations.First(o => o.Path.Contains(nameof(DefaultParametersController.WithDefaultEnum))).Operation; - Assert.Equal(5, operation.Parameters.First().Schema.Default); + Assert.Equal((int)MyEnum.Def, operation.Parameters.First().Schema.Default); Assert.True(operation.Parameters.First().Schema.OneOf.Any()); } From 5c8d0dfb41a2bde26f1f98fd3967b855dbf9d14c Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Fri, 24 May 2019 15:04:42 +0200 Subject: [PATCH 18/20] Update njs --- src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj | 2 +- .../NSwag.AspNet.WebApi.csproj | 2 +- .../NSwag.AssemblyLoader.csproj | 2 +- .../NSwag.CodeGeneration.CSharp.csproj | 2 +- .../NSwag.CodeGeneration.TypeScript.csproj | 2 +- .../NSwag.CodeGeneration.csproj | 4 ++-- src/NSwag.Commands/NSwag.Commands.csproj | 10 +++++----- src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj | 2 +- src/NSwag.Core/NSwag.Core.csproj | 2 +- src/NSwag.Demo.Web/NSwag.Demo.Web.csproj | 4 ++-- src/NSwag.Demo.Web/packages.config | 2 +- .../NSwag.Integration.WebAPI.csproj | 3 ++- src/NSwag.Integration.WebAPI/packages.config | 2 +- .../NSwag.Sample.NetGlobalAsax.csproj | 4 ++-- src/NSwag.Sample.NetGlobalAsax/packages.config | 2 +- .../NSwag.SwaggerGeneration.AspNetCore.csproj | 2 +- .../NSwag.SwaggerGeneration.WebApi.Tests.csproj | 12 ++++++------ .../packages.config | 6 +++--- .../NSwag.SwaggerGeneration.WebApi.csproj | 2 +- .../NSwag.SwaggerGeneration.csproj | 2 +- src/NSwag.Tests/NSwag.Tests.csproj | 4 ++-- src/NSwag.Tests/packages.config | 2 +- src/NSwagStudio/NSwagStudio.csproj | 16 ++++++++-------- src/NSwagStudio/packages.config | 8 ++++---- 24 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj index d9f68e906b..d1d302baab 100644 --- a/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj +++ b/src/NSwag.AspNet.Owin/NSwag.AspNet.Owin.csproj @@ -46,7 +46,7 @@ - + diff --git a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj index 477fc24da0..80f242901d 100644 --- a/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj +++ b/src/NSwag.AspNet.WebApi/NSwag.AspNet.WebApi.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj index a42556e20a..71ea040234 100644 --- a/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj +++ b/src/NSwag.AssemblyLoader/NSwag.AssemblyLoader.csproj @@ -24,7 +24,7 @@ TRACE;RELEASE;FullNet;NET451 - + diff --git a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj index cc1496f69e..2b6efd970d 100644 --- a/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj +++ b/src/NSwag.CodeGeneration.CSharp/NSwag.CodeGeneration.CSharp.csproj @@ -53,6 +53,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj index 09038a5897..f79ab8c4b3 100644 --- a/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj +++ b/src/NSwag.CodeGeneration.TypeScript/NSwag.CodeGeneration.TypeScript.csproj @@ -49,6 +49,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj index f0ef2191a8..3cbfc9e89f 100644 --- a/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj +++ b/src/NSwag.CodeGeneration/NSwag.CodeGeneration.csproj @@ -19,8 +19,8 @@ - - + + diff --git a/src/NSwag.Commands/NSwag.Commands.csproj b/src/NSwag.Commands/NSwag.Commands.csproj index f4aea01c1d..2796a2d5de 100644 --- a/src/NSwag.Commands/NSwag.Commands.csproj +++ b/src/NSwag.Commands/NSwag.Commands.csproj @@ -66,11 +66,11 @@ - - - - - + + + + + diff --git a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj index 70b71e0233..67a0edff97 100644 --- a/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj +++ b/src/NSwag.Core.Yaml/NSwag.Core.Yaml.csproj @@ -16,7 +16,7 @@ NSwag - + diff --git a/src/NSwag.Core/NSwag.Core.csproj b/src/NSwag.Core/NSwag.Core.csproj index 7131fa9f2c..d8085d9ea3 100644 --- a/src/NSwag.Core/NSwag.Core.csproj +++ b/src/NSwag.Core/NSwag.Core.csproj @@ -23,7 +23,7 @@ - + diff --git a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj index 387d05859e..1dcbb07fe0 100644 --- a/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj +++ b/src/NSwag.Demo.Web/NSwag.Demo.Web.csproj @@ -70,8 +70,8 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Demo.Web/packages.config b/src/NSwag.Demo.Web/packages.config index 67446f06be..42f233184c 100644 --- a/src/NSwag.Demo.Web/packages.config +++ b/src/NSwag.Demo.Web/packages.config @@ -16,6 +16,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj index d7164728e2..d8f31f8e33 100644 --- a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj +++ b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj @@ -67,7 +67,8 @@ True - ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll + True ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Integration.WebAPI/packages.config b/src/NSwag.Integration.WebAPI/packages.config index 8ffefbc79c..2ed92a2f99 100644 --- a/src/NSwag.Integration.WebAPI/packages.config +++ b/src/NSwag.Integration.WebAPI/packages.config @@ -11,6 +11,6 @@ - + \ No newline at end of file diff --git a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj index ae02b7c38c..72fb321b81 100644 --- a/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj +++ b/src/NSwag.Sample.NetGlobalAsax/NSwag.Sample.NetGlobalAsax.csproj @@ -62,8 +62,8 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll ..\packages\Owin.1.0\lib\net40\Owin.dll diff --git a/src/NSwag.Sample.NetGlobalAsax/packages.config b/src/NSwag.Sample.NetGlobalAsax/packages.config index f62d3b087f..32a576d511 100644 --- a/src/NSwag.Sample.NetGlobalAsax/packages.config +++ b/src/NSwag.Sample.NetGlobalAsax/packages.config @@ -28,7 +28,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj index 28e8cb30fa..0ef468f1b0 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj +++ b/src/NSwag.SwaggerGeneration.AspNetCore/NSwag.SwaggerGeneration.AspNetCore.csproj @@ -25,7 +25,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj index 9b5c4952da..fd884e1f49 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/NSwag.SwaggerGeneration.WebApi.Tests.csproj @@ -53,14 +53,14 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.10.0.4\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.5\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.4\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.5\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll ..\packages\Swashbuckle.Core.5.5.3\lib\net40\Swashbuckle.Core.dll diff --git a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config index 3ff06f7f79..8c273386cf 100644 --- a/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config +++ b/src/NSwag.SwaggerGeneration.WebApi.Tests/packages.config @@ -13,9 +13,9 @@ - - - + + + diff --git a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj index 61fbb3c63f..4c34a606ca 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj +++ b/src/NSwag.SwaggerGeneration.WebApi/NSwag.SwaggerGeneration.WebApi.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj index 594d4c42fc..8947d518fd 100644 --- a/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj +++ b/src/NSwag.SwaggerGeneration/NSwag.SwaggerGeneration.csproj @@ -22,7 +22,7 @@ - + diff --git a/src/NSwag.Tests/NSwag.Tests.csproj b/src/NSwag.Tests/NSwag.Tests.csproj index ec6ad67e4f..e313bb60cb 100644 --- a/src/NSwag.Tests/NSwag.Tests.csproj +++ b/src/NSwag.Tests/NSwag.Tests.csproj @@ -66,8 +66,8 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - - ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll diff --git a/src/NSwag.Tests/packages.config b/src/NSwag.Tests/packages.config index cbca06c2e5..ef01fbf7ed 100644 --- a/src/NSwag.Tests/packages.config +++ b/src/NSwag.Tests/packages.config @@ -5,5 +5,5 @@ - + \ No newline at end of file diff --git a/src/NSwagStudio/NSwagStudio.csproj b/src/NSwagStudio/NSwagStudio.csproj index 548d596346..9a33389212 100644 --- a/src/NSwagStudio/NSwagStudio.csproj +++ b/src/NSwagStudio/NSwagStudio.csproj @@ -96,17 +96,17 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\NJsonSchema.10.0.4\lib\net45\NJsonSchema.dll + + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll - - ..\packages\NJsonSchema.CodeGeneration.10.0.4\lib\net451\NJsonSchema.CodeGeneration.dll + + ..\packages\NJsonSchema.CodeGeneration.10.0.5\lib\net451\NJsonSchema.CodeGeneration.dll - - ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.4\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll + + ..\packages\NJsonSchema.CodeGeneration.CSharp.10.0.5\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll - - ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.4\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll + + ..\packages\NJsonSchema.CodeGeneration.TypeScript.10.0.5\lib\net451\NJsonSchema.CodeGeneration.TypeScript.dll diff --git a/src/NSwagStudio/packages.config b/src/NSwagStudio/packages.config index 2802726062..ea9d2f8139 100644 --- a/src/NSwagStudio/packages.config +++ b/src/NSwagStudio/packages.config @@ -11,10 +11,10 @@ - - - - + + + + From d18f2be652a59ad7f8cc7bf60f6ef481f0a275ef Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Fri, 24 May 2019 15:48:20 +0200 Subject: [PATCH 19/20] Fix project --- .../NSwag.Integration.WebAPI.csproj | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj index d8f31f8e33..7db5d09289 100644 --- a/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj +++ b/src/NSwag.Integration.WebAPI/NSwag.Integration.WebAPI.csproj @@ -58,17 +58,12 @@ ..\packages\Microsoft.Owin.Host.SystemWeb.3.0.1\lib\net45\Microsoft.Owin.Host.SystemWeb.dll - - ..\packages\Namotion.Reflection.1.0.2\lib\net45\Namotion.Reflection.dll - True - ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True - + ..\packages\NJsonSchema.10.0.5\lib\net45\NJsonSchema.dll - True ..\packages\Owin.1.0\lib\net40\Owin.dll From fc0167d99b9d22cda7226c9c46b75ccfc9d4f0e6 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Fri, 24 May 2019 19:28:59 +0200 Subject: [PATCH 20/20] Fix tests --- src/NSwag.Core/SwaggerParameter.cs | 4 ++++ .../Processors/OperationParameterProcessor.cs | 2 +- .../Processors/OperationParameterProcessor.cs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/NSwag.Core/SwaggerParameter.cs b/src/NSwag.Core/SwaggerParameter.cs index 90af8ca8a9..80eea36a99 100644 --- a/src/NSwag.Core/SwaggerParameter.cs +++ b/src/NSwag.Core/SwaggerParameter.cs @@ -161,9 +161,13 @@ public override JsonSchema ActualSchema get { if (Reference is SwaggerParameter parameter) + { return parameter.ActualSchema; + } else + { return Schema?.ActualSchema ?? CustomSchema?.ActualSchema ?? base.ActualSchema; + } } } diff --git a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs index c4e1c22bb3..be71e38da1 100644 --- a/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.AspNetCore/Processors/OperationParameterProcessor.cs @@ -208,7 +208,7 @@ private void EnsureSingleBodyParameter(SwaggerOperationDescription operationDesc private void UpdateConsumedTypes(SwaggerOperationDescription operationDescription) { - if (operationDescription.Operation.ActualParameters.Any(p => p.IsBinary)) + if (operationDescription.Operation.ActualParameters.Any(p => p.IsBinary || p.ActualSchema.IsBinary)) { operationDescription.Operation.TryAddConsumes("multipart/form-data"); } diff --git a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs index 20ff6f6996..e470748584 100644 --- a/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs +++ b/src/NSwag.SwaggerGeneration.WebApi/Processors/OperationParameterProcessor.cs @@ -214,7 +214,7 @@ private void EnsureSingleBodyParameter(SwaggerOperationDescription operationDesc private void UpdateConsumedTypes(SwaggerOperationDescription operationDescription) { - if (operationDescription.Operation.ActualParameters.Any(p => p.ActualSchema.IsBinary)) + if (operationDescription.Operation.ActualParameters.Any(p => p.IsBinary || p.ActualSchema.IsBinary)) { operationDescription.Operation.TryAddConsumes("multipart/form-data"); }