-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added versioning support #16
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
50ab096
no message
ussamoo 160a97a
Updated SwaggerForOcelotMiddleware to support versioning
ussamoo 8b31738
Created demo application with versioning
ussamoo 326e6aa
Updated doc
ussamoo f4a7c79
Updated doc
ussamoo 6a07778
Clean up
ussamoo f4780ef
Clean up
ussamoo d80efd9
Added some comments
ussamoo 85499ee
code review fixes
ussamoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
namespace OrderService | ||
{ | ||
using Microsoft.AspNetCore.Mvc.ApiExplorer; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using Swashbuckle.AspNetCore.Swagger; | ||
using Swashbuckle.AspNetCore.SwaggerGen; | ||
|
||
/// <summary> | ||
/// Configures the Swagger generation options. | ||
/// </summary> | ||
/// <remarks>This allows API versioning to define a Swagger document per API version after the | ||
/// <see cref="IApiVersionDescriptionProvider"/> service has been resolved from the service container.</remarks> | ||
public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||
{ | ||
readonly IApiVersionDescriptionProvider provider; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConfigureSwaggerOptions"/> class. | ||
/// </summary> | ||
/// <param name="provider">The <see cref="IApiVersionDescriptionProvider">provider</see> used to generate Swagger documents.</param> | ||
public ConfigureSwaggerOptions( IApiVersionDescriptionProvider provider ) => this.provider = provider; | ||
|
||
/// <inheritdoc /> | ||
public void Configure( SwaggerGenOptions options ) | ||
{ | ||
// add a swagger document for each discovered API version | ||
// note: you might choose to skip or document deprecated API versions differently | ||
foreach ( var description in provider.ApiVersionDescriptions ) | ||
{ | ||
options.SwaggerDoc( description.GroupName, CreateInfoForApiVersion( description ) ); | ||
} | ||
} | ||
|
||
static Info CreateInfoForApiVersion( ApiVersionDescription description ) | ||
{ | ||
var info = new Info() | ||
{ | ||
Title = "Sample API", | ||
Version = description.ApiVersion.ToString(), | ||
Description = "A sample application with Swagger, Swashbuckle, and API versioning.", | ||
Contact = new Contact() { Name = "Bill Mei", Email = "[email protected]" }, | ||
TermsOfService = "Shareware", | ||
License = new License() { Name = "MIT", Url = "https://opensource.org/licenses/MIT" } | ||
}; | ||
|
||
if ( description.IsDeprecated ) | ||
{ | ||
info.Description += " This API version has been deprecated."; | ||
} | ||
|
||
return info; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel> | ||
<RootNamespace>OrderService</RootNamespace> | ||
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(MSBuildThisFileName).xml</DocumentationFile> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.App" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="3.2.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" /> | ||
<PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" /> | ||
</ItemGroup> | ||
|
||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace OrderService | ||
{ | ||
using Microsoft.AspNetCore; | ||
using Microsoft.AspNetCore.Hosting; | ||
|
||
/// <summary> | ||
/// Represents the current application. | ||
/// </summary> | ||
public static class Program | ||
{ | ||
/// <summary> | ||
/// The main entry point to the application. | ||
/// </summary> | ||
/// <param name="args">The arguments provided at start-up, if any.</param> | ||
public static void Main( string[] args ) => | ||
CreateWebHostBuilder( args ).Build().Run(); | ||
|
||
/// <summary> | ||
/// Builds a new web host for the application. | ||
/// </summary> | ||
/// <param name="args">The command-line arguments, if any.</param> | ||
/// <returns>A new <see cref="IWebHostBuilder">web host builder</see>.</returns> | ||
public static IWebHostBuilder CreateWebHostBuilder( string[] args ) => | ||
WebHost.CreateDefaultBuilder( args ) | ||
.UseStartup<Startup>(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: we usually have the
using
section at beginning of document.