Skip to content

Commit

Permalink
Merge pull request #21 from vaclavnovotny/prerelease
Browse files Browse the repository at this point in the history
Merging prerelease into main
  • Loading branch information
vaclavnovotny authored Feb 19, 2024
2 parents f35e68f + e9f0cc3 commit 0bf29e7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and Publish

on:
push:
branches: [ main, prelease ]
branches: [ main, prerelease ]

defaults:
run:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
.idea/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

Expand Down
2 changes: 1 addition & 1 deletion samples/NSwagWithExamples/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {

app.UseAuthorization();
app.UseOpenApi();
app.UseSwaggerUi3();
app.UseSwaggerUi();

app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
Expand Down
10 changes: 7 additions & 3 deletions src/NSwag.Examples/ExamplesConverter.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using JsonSerializer = System.Text.Json.JsonSerializer;

namespace NSwag.Examples;

internal class ExamplesConverter
{
private readonly JsonSerializerSettings _jsonSerializerSettings;
private readonly JsonSerializerSettings? _jsonSerializerSettings;
private readonly JsonSerializerOptions? _systemTextJsonSettings;

internal ExamplesConverter(JsonSerializerSettings jsonSerializerSettings) {
internal ExamplesConverter(JsonSerializerSettings? jsonSerializerSettings, JsonSerializerOptions? systemTextJsonSettings) {
_jsonSerializerSettings = jsonSerializerSettings;
_systemTextJsonSettings = systemTextJsonSettings;
}

private object SerializeExampleJson(object value) {
var serializeObject = JsonConvert.SerializeObject(value, _jsonSerializerSettings);
var serializeObject = _jsonSerializerSettings is not null ? JsonConvert.SerializeObject(value, _jsonSerializerSettings) : JsonSerializer.Serialize(value, _systemTextJsonSettings);
return JToken.Parse(serializeObject);
}

Expand Down
6 changes: 3 additions & 3 deletions src/NSwag.Examples/NSwag.Examples.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net5.0;net6.0;net7.0</TargetFrameworks>
<Version>1.0.11</Version>
<TargetFrameworks>netstandard2.0;net5.0;net6.0;net7.0;net8.0</TargetFrameworks>
<Version>1.0.12-preview-01</Version>
<Authors>Vaclav Novotny</Authors>
<RepositoryUrl>https://github.com/vaclavnovotny/NSwag.Examples</RepositoryUrl>
<PackageProjectUrl>https://github.com/vaclavnovotny/NSwag.Examples</PackageProjectUrl>
Expand All @@ -16,6 +16,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NSwag.AspNetCore" Version="13.19.0" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.3" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion src/NSwag.Examples/RequestBodyExampleProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NSwag.Generation.AspNetCore;
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;

Expand All @@ -23,7 +24,7 @@ public RequestBodyExampleProcessor(IServiceProvider serviceProvider) {
}

public bool Process(OperationProcessorContext context) {
_examplesConverter = new ExamplesConverter(context.Settings.SerializerSettings);
_examplesConverter = new ExamplesConverter(AspNetCoreOpenApiDocumentGenerator.GetJsonSerializerSettings(_serviceProvider), AspNetCoreOpenApiDocumentGenerator.GetSystemTextJsonSettings(_serviceProvider));
var exampleProvider = _serviceProvider.GetRequiredService<SwaggerExampleProvider>();
SetRequestExamples(context, exampleProvider);
SetResponseExamples(context, exampleProvider);
Expand Down

0 comments on commit 0bf29e7

Please sign in to comment.