fcatae / Arda

Arda is an open source tool designed to manage team workloads.
42 stars 18 forks source link

Create API versioning with Swagger support #83

Closed fcatae closed 7 years ago

fcatae commented 7 years ago

Need Swagger versioning to support Kanban v2

Sample: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/test/WebSites/MultipleVersions/Startup.cs

fcatae commented 7 years ago

See this discussion: https://github.com/Microsoft/aspnet-api-versioning/issues/60

fcatae commented 7 years ago

Solution:

  1. Define the available versions

    c.SwaggerDoc("v1", new Info { Title = "Arda.Kanban", Version = "v1" });
    c.SwaggerDoc("v2", new Info { Title = "Arda.Kanban v2 (Workspaces)", Version = "v2" });
  2. Define a function to classify the API in version

    c.DocInclusionPredicate((docName, apiDesc) =>
    {
    switch (docName)
    {
        case "v1":
            return apiDesc.RelativePath.StartsWith("api/");
        case "v2":
            return apiDesc.RelativePath.StartsWith("v2/");
    }
    
    // unknown version?
    return true;
    });
  3. Update the Swagger UI

    app.UseSwaggerUi(c =>
    {
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "Arda.Kanban v1");
    c.SwaggerEndpoint("/swagger/v2/swagger.json", "Arda.Kanban v2 (Workspaces)");
    });
fcatae commented 7 years ago

Done