Skip to content

Commit

Permalink
Fix bug: use "System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelax…
Browse files Browse the repository at this point in the history
…edJsonEscaping" encoder for responses examples
  • Loading branch information
Chebotov Nikolay committed Feb 19, 2020
1 parent 6a403de commit bcbb2ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.1 `(2020-02-19)`

- [x] Fix bug: use `System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping` encoder for responses examples

## v2.1.0 `(2020-02-19)`

- [x] Add `ChangeAllResponsesByHttpStatusCode<T>` extension method for `SwaggerGenOptions` allows to change all responses by specific http status codes in OpenApi document
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,14 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
break;
case ResponseExampleOptions.AddNew:
if (this._responseExample != null)
jsonContent.Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample, new System.Text.Json.JsonSerializerOptions { WriteIndented = true }));
{
jsonContent.Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample,
new System.Text.Json.JsonSerializerOptions
{
WriteIndented = true,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
}));
}
jsonContent.Schema = schema;
break;
case ResponseExampleOptions.None:
Expand All @@ -109,7 +116,12 @@ public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
response.Value.Content.Add("application/json", new OpenApiMediaType()
{
Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample, new System.Text.Json.JsonSerializerOptions { WriteIndented = true })),
Example = new OpenApiString(System.Text.Json.JsonSerializer.Serialize(this._responseExample,
new System.Text.Json.JsonSerializerOptions
{
WriteIndented = true,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
})),
Schema = schema
});
}
Expand Down

0 comments on commit bcbb2ff

Please sign in to comment.