Skip to content

Commit bcbb2ff

Browse files
author
Chebotov Nikolay
committed
Fix bug: use "System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping" encoder for responses examples
1 parent 6a403de commit bcbb2ff

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
These are the changes to each version that has been released on the [nuget](https://www.nuget.org/packages/Unchase.Swashbuckle.AspNetCore.Extensions/).
1010

11+
## v2.1.1 `(2020-02-19)`
12+
13+
- [x] Fix bug: use `System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping` encoder for responses examples
14+
1115
## v2.1.0 `(2020-02-19)`
1216

1317
- [x] Add `ChangeAllResponsesByHttpStatusCode<T>` extension method for `SwaggerGenOptions` allows to change all responses by specific http status codes in OpenApi document

src/Unchase.Swashbuckle.AspNetCore.Extensions/Filters/ChangeResponseByHttpStatusCodeDocumentFilter.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
9292
break;
9393
case ResponseExampleOptions.AddNew:
9494
if (this._responseExample != null)
95-
jsonContent.Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
95+
{
96+
jsonContent.Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample,
97+
new System.Text.Json.JsonSerializerOptions
98+
{
99+
WriteIndented = true,
100+
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
101+
}));
102+
}
96103
jsonContent.Schema = schema;
97104
break;
98105
case ResponseExampleOptions.None:
@@ -109,7 +116,12 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
109116
{
110117
response.Value.Content.Add("application/json", new OpenApiMediaType()
111118
{
112-
Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample, new System.Text.Json.JsonSerializerOptions { WriteIndented = true })),
119+
Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample,
120+
new System.Text.Json.JsonSerializerOptions
121+
{
122+
WriteIndented = true,
123+
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
124+
})),
113125
Schema = schema
114126
});
115127
}

0 commit comments

Comments
 (0)