From 2fd559e2e8b79b5b9796699263512b9049d61457 Mon Sep 17 00:00:00 2001 From: Chebotov Nikolay Date: Fri, 21 Feb 2020 14:34:54 +0300 Subject: [PATCH] Fix openApi response content schema in "ChangeResponseByHttpStatusCodeDocumentFilter". --- CHANGELOG.md | 4 ++++ ...eResponseByHttpStatusCodeDocumentFilter.cs | 20 ++++++++++++++++--- ...e.Swashbuckle.AspNetCore.Extensions.csproj | 6 +++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70659ba..c4f591b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ These are the changes to each version that has been released on the [nuget](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/). +## v2.1.5 `(2020-02-21)` + +- [x] Fix bug: fix openApi response content schema in `ChangeResponseByHttpStatusCodeDocumentFilter` + ## v2.1.4 `(2020-02-20)` - [x] Add xml-comments to nuget package diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/ChangeResponseByHttpStatusCodeDocumentFilter.cs b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/ChangeResponseByHttpStatusCodeDocumentFilter.cs index 13b39a9..4c61527 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/ChangeResponseByHttpStatusCodeDocumentFilter.cs +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/ChangeResponseByHttpStatusCodeDocumentFilter.cs @@ -102,7 +102,14 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) jsonContent.Example = jsonExample; } - jsonContent.Schema = schema; + jsonContent.Schema = new OpenApiSchema + { + Reference = new OpenApiReference + { + Id = typeof(T).Name, + Type = ReferenceType.Schema + } + }; break; case ResponseExampleOptions.None: default: @@ -122,10 +129,17 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) WriteIndented = true, Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping })); - response.Value.Content.Add("application/json", new OpenApiMediaType() + response.Value.Content.Add("application/json", new OpenApiMediaType { Example = jsonExample, - Schema = schema + Schema = new OpenApiSchema + { + Reference = new OpenApiReference + { + Id = typeof(T).Name, + Type = ReferenceType.Schema + } + } }); } break; diff --git a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj index 2c3d43e..0455202 100644 --- a/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj +++ b/src/Unchase.Swashbuckle.AspNetCore.Extensions/Unchase.Swashbuckle.AspNetCore.Extensions.csproj @@ -14,9 +14,9 @@ 7.3 https://github.com/unchase/Unchase.Swashbuckle.AspNetCore.Extensions/blob/master/assets/icon.png?raw=true - 2.1.4 - 2.1.4.0 - 2.1.4.0 + 2.1.5 + 2.1.5.0 + 2.1.5.0 false Unchase.Swashbuckle.AspNetCore.Extensions.xml