Skip to content

Commit 6a424ad

Browse files
author
Chris Martinez
committed
Update to Swagger 5.0.0
1 parent 6491692 commit 6a424ad

File tree

4 files changed

+14
-13
lines changed

4 files changed

+14
-13
lines changed

samples/aspnetcore/SwaggerODataSample/ConfigureSwaggerOptions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
using Microsoft.AspNetCore.Mvc.ApiExplorer;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Options;
6-
using Swashbuckle.AspNetCore.Swagger;
6+
using Microsoft.OpenApi.Models;
77
using Swashbuckle.AspNetCore.SwaggerGen;
8+
using System;
89

910
/// <summary>
1011
/// Configures the Swagger generation options.
@@ -32,16 +33,15 @@ public void Configure( SwaggerGenOptions options )
3233
}
3334
}
3435

35-
static Info CreateInfoForApiVersion( ApiVersionDescription description )
36+
static OpenApiInfo CreateInfoForApiVersion( ApiVersionDescription description )
3637
{
37-
var info = new Info()
38+
var info = new OpenApiInfo()
3839
{
3940
Title = "Sample API",
4041
Version = description.ApiVersion.ToString(),
4142
Description = "A sample application with Swagger, Swashbuckle, and API versioning.",
42-
Contact = new Contact() { Name = "Bill Mei", Email = "bill.mei@somewhere.com" },
43-
TermsOfService = "Shareware",
44-
License = new License() { Name = "MIT", Url = "https://opensource.org/licenses/MIT" }
43+
Contact = new OpenApiContact() { Name = "Bill Mei", Email = "bill.mei@somewhere.com" },
44+
License = new OpenApiLicense() { Name = "MIT", Url = new Uri( "https://opensource.org/licenses/MIT" ) }
4545
};
4646

4747
if ( description.IsDeprecated )

samples/aspnetcore/SwaggerODataSample/SwaggerDefaultValues.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
namespace Microsoft.Examples
22
{
33
using Microsoft.AspNetCore.Mvc.ApiExplorer;
4-
using Swashbuckle.AspNetCore.Swagger;
4+
using Microsoft.OpenApi.Any;
5+
using Microsoft.OpenApi.Models;
56
using Swashbuckle.AspNetCore.SwaggerGen;
67
using System.Linq;
78

@@ -17,7 +18,7 @@ public class SwaggerDefaultValues : IOperationFilter
1718
/// </summary>
1819
/// <param name="operation">The operation to apply the filter to.</param>
1920
/// <param name="context">The current operation filter context.</param>
20-
public void Apply( Operation operation, OperationFilterContext context )
21+
public void Apply( OpenApiOperation operation, OperationFilterContext context )
2122
{
2223
var apiDescription = context.ApiDescription;
2324

@@ -30,7 +31,7 @@ public void Apply( Operation operation, OperationFilterContext context )
3031

3132
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412
3233
// REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413
33-
foreach ( var parameter in operation.Parameters.OfType<NonBodyParameter>() )
34+
foreach ( var parameter in operation.Parameters )
3435
{
3536
var description = apiDescription.ParameterDescriptions.First( p => p.Name == parameter.Name );
3637

@@ -39,9 +40,9 @@ public void Apply( Operation operation, OperationFilterContext context )
3940
parameter.Description = description.ModelMetadata?.Description;
4041
}
4142

42-
if ( parameter.Default == null )
43+
if ( parameter.Schema.Default == null && description.DefaultValue != null )
4344
{
44-
parameter.Default = description.DefaultValue;
45+
parameter.Schema.Default = new OpenApiString( description.DefaultValue.ToString() );
4546
}
4647

4748
parameter.Required |= description.IsRequired;

samples/aspnetcore/SwaggerODataSample/SwaggerODataSample.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageReference Include="Microsoft.AspNetCore.App" />
1212
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
1313
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
14-
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
14+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-*" />
1515
</ItemGroup>
1616

1717
<ItemGroup>

samples/aspnetcore/SwaggerSample/SwaggerSample.csproj

Lines changed: 1 addition & 1 deletion
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.0.0-rc2" />
11+
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-*" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

0 commit comments

Comments
 (0)