Skip to content
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 9 commits into from
Feb 25, 2019
Merged

Conversation

ussamoo
Copy link
Contributor

@ussamoo ussamoo commented Feb 22, 2019

The RP add versioning support.

New Config :

In the previous implementation, you could not add multiple routes for a specific API. This change addresses that problem to allow adding multiples configuration for a swagger endpoint.

 "SwaggerEndPoints": [
    {
      "Key": "contacts",
      "Config": [
        {
          "Name": "Contacts API",
          "Version": "v1",
          "Url": "http://localhost:5100/swagger/v1/swagger.json"
        }
      ]
    },
    {
      "Key": "orders",
      "Config": [
        {
          "Name": "Orders API",
          "Version": "v0.9",
          "Url": "http://localhost:5200/swagger/v0.9/swagger.json"
        },
        {
          "Name": "Orders API",
          "Version": "v1",
          "Url": "http://localhost:5200/swagger/v1/swagger.json"
        },
        {
          "Name": "Orders API",
          "Version": "v2",
          "Url": "http://localhost:5200/swagger/v2/swagger.json"
        },
        {
          "Name": "Orders API",
          "Version": "v3",
          "Url": "http://localhost:5200/swagger/v3/swagger.json"
        }
      ]
    }
  ]

@ussamoo ussamoo closed this Feb 22, 2019
@ussamoo ussamoo reopened this Feb 22, 2019
@Burgyn Burgyn self-requested a review February 22, 2019 09:48
Copy link
Owner

@Burgyn Burgyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
Great thanks for your contribution.

I have a few minor comments. Coming from our coding style. Please check it (Review changes).

I worry about breaking change.

It would be nice to support the original configuration. But it's from category 'nice to have'.

Unit tests

Now is time write first tests for configuration. Since they have not been tested so far, I create new issue.

@@ -12,6 +12,6 @@ public class SwaggerForOcelotUIOptions: SwaggerUIOptions
/// The end point base path. The final path to swagger endpoint is
/// <see cref="EndPointBasePath"/> + <see cref="SwaggerEndPointOptions.Key"/>
/// </summary>
public string EndPointBasePath { get; set; } = "/swagger/v1";
public string EndPointBasePath { get; set; }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the default value (/swagger/docs) for property EndPointBasePath.
In my opinion, for most scenarios, it is unnecessary to configure property EndPointBasePath.

/// <returns>
/// <see cref="IApplicationBuilder"/>.
/// </returns>
public static IApplicationBuilder UseSwaggerForOcelotUI(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this overload?
In my opinion, for most scenarios, it is unnecessary to configure property EndPointBasePath.

@@ -43,11 +30,10 @@ public static class BuilderExtensions
setupAction?.Invoke(options);

UseSwaggerForOcelot(app, options);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we don't use whitespace.

@@ -0,0 +1,55 @@
namespace OrderService
{
using Microsoft.AspNetCore.Mvc.ApiExplorer;
Copy link
Owner

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.

@@ -0,0 +1,104 @@
namespace OrderService
{
using Microsoft.AspNetCore.Builder;
Copy link
Owner

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.

foreach (var config in endPoint.Config)
{
c.SwaggerEndpoint($"{basePath}/{config.Version}/{endPoint.KeyToPath}", $"{config.Name} - {config.Version}");
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please remove whitespaces after }.
Tip: we use extension Trailing Whitespace Visualizer.

var url = endPoint.Config.Where(x => x.Version == endPointInfo.Version).FirstOrDefault()?.Url;
return (url, endPoint);
}
/// <summary>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: by our coding style, we adding one empty line beatween methods.

private (string Version, string Key) GetEndPointInfo(string path)
{
var keys = path.Split('/');
return (keys[1], keys[2]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please remove whitespaces.
Tip: we use extension Trailing Whitespace Visualizer.

@ussamoo
Copy link
Contributor Author

ussamoo commented Feb 25, 2019

Hi,

Thanks for the quick reply, i will do the necessary!

@ussamoo
Copy link
Contributor Author

ussamoo commented Feb 25, 2019

I will add configuration unit tests later!

@Burgyn Burgyn self-requested a review February 25, 2019 13:46
@Burgyn
Copy link
Owner

Burgyn commented Feb 25, 2019

Hi,
I'll merge this PR.

Release come in a few minits, v1.1.0

Thank you again.

@Burgyn Burgyn merged commit 9099734 into Burgyn:master Feb 25, 2019
@ussamoo ussamoo deleted the feature/versioning-support branch February 25, 2019 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants