Skip to content

Commit 569cdcc

Browse files
Chris Martinezcommonsensesoftware
Chris Martinez
authored andcommitted
Update examples
1 parent 3285ad2 commit 569cdcc

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

samples/aspnetcore/BasicSample/BasicSample.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<RootNamespace>Microsoft.Examples</RootNamespace>
66
</PropertyGroup>
77

samples/aspnetcore/ByNamespaceSample/ByNamespaceSample.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<RootNamespace>Microsoft.Examples</RootNamespace>
66
</PropertyGroup>
77

samples/aspnetcore/ConventionsSample/ConventionsSample.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<RootNamespace>Microsoft.Examples</RootNamespace>
66
</PropertyGroup>
77

samples/aspnetcore/SwaggerODataSample/SwaggerDefaultValues.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.OpenApi.Models;
55
using Swashbuckle.AspNetCore.SwaggerGen;
66
using System.Linq;
7+
using System.Text.Json;
78

89
/// <summary>
910
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
@@ -23,15 +24,13 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
2324

2425
operation.Deprecated |= apiDescription.IsDeprecated();
2526

26-
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
27+
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
2728
foreach ( var responseType in context.ApiDescription.SupportedResponseTypes )
2829
{
29-
// based on internals of SwaggerGenerator
30-
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
30+
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
3131
var responseKey = responseType.IsDefaultResponse ? "default" : responseType.StatusCode.ToString();
3232
var response = operation.Responses[responseKey];
3333

34-
// remove media types not supported by the API
3534
foreach ( var contentType in response.Content.Keys )
3635
{
3736
if ( !responseType.ApiResponseFormats.Any( x => x.MediaType == contentType ) )
@@ -59,8 +58,9 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
5958

6059
if ( parameter.Schema.Default == null && description.DefaultValue != null )
6160
{
62-
// https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
63-
parameter.Schema.Default = OpenApiAnyFactory.CreateFor( parameter.Schema, description.DefaultValue );
61+
// REF: https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
62+
var json = JsonSerializer.Serialize( description.DefaultValue, description.ModelMetadata.ModelType );
63+
parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson( json );
6464
}
6565

6666
parameter.Required |= description.IsRequired;

samples/aspnetcore/SwaggerODataSample/SwaggerODataSample.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
11-
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3-*" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.2-*" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/aspnetcore/SwaggerSample/SwaggerDefaultValues.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Microsoft.OpenApi.Models;
55
using Swashbuckle.AspNetCore.SwaggerGen;
66
using System.Linq;
7+
using System.Text.Json;
78

89
/// <summary>
910
/// Represents the Swagger/Swashbuckle operation filter used to document the implicit API version parameter.
@@ -23,15 +24,13 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
2324

2425
operation.Deprecated |= apiDescription.IsDeprecated();
2526

26-
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
27+
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077
2728
foreach ( var responseType in context.ApiDescription.SupportedResponseTypes )
2829
{
29-
// based on internals of SwaggerGenerator
30-
// https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
30+
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387
3131
var responseKey = responseType.IsDefaultResponse ? "default" : responseType.StatusCode.ToString();
3232
var response = operation.Responses[responseKey];
3333

34-
// remove media types not supported by the API
3534
foreach ( var contentType in response.Content.Keys )
3635
{
3736
if ( !responseType.ApiResponseFormats.Any( x => x.MediaType == contentType ) )
@@ -59,8 +58,9 @@ public void Apply( OpenApiOperation operation, OperationFilterContext context )
5958

6059
if ( parameter.Schema.Default == null && description.DefaultValue != null )
6160
{
62-
// https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
63-
parameter.Schema.Default = OpenApiAnyFactory.CreateFor( parameter.Schema, description.DefaultValue );
61+
// REF: https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330
62+
var json = JsonSerializer.Serialize( description.DefaultValue, description.ModelMetadata.ModelType );
63+
parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson( json );
6464
}
6565

6666
parameter.Required |= description.IsRequired;

samples/aspnetcore/SwaggerSample/SwaggerSample.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net5.0</TargetFramework>
55
<RootNamespace>Microsoft.Examples</RootNamespace>
66
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
11-
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3-*" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.2-*" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)