-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix tests around ConfigureSwaggerDocOptions & ConfigureSwaggerO…
…ptions
- Loading branch information
1 parent
fa6809a
commit 1100b4f
Showing
36 changed files
with
1,152 additions
and
250 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...Scenarios/DemoSample/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/GlobalUsings.verified.cs
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
88 changes: 88 additions & 0 deletions
88
...e/VerifyServerAll/Mvc_WOPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs
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,88 @@ | ||
namespace DemoSample.Api.Options; | ||
|
||
public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||
{ | ||
private readonly IApiVersionDescriptionProvider provider; | ||
private readonly IWebHostEnvironment environment; | ||
|
||
/// <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> | ||
/// <param name="environment">The environment.</param> | ||
public ConfigureSwaggerOptions( | ||
IApiVersionDescriptionProvider provider, | ||
IWebHostEnvironment environment) | ||
{ | ||
this.provider = provider; | ||
this.environment = environment; | ||
} | ||
|
||
/// <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)); | ||
} | ||
} | ||
|
||
private OpenApiInfo CreateInfoForApiVersion( | ||
ApiVersionDescription description) | ||
{ | ||
var text = new StringBuilder("Demo Sample Api - SingleFileVersion"); | ||
var info = new OpenApiInfo | ||
{ | ||
Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", | ||
Version = description.ApiVersion.ToString(), | ||
Contact = new OpenApiContact | ||
{ | ||
Name = "atc-net A/S", | ||
}, | ||
}; | ||
|
||
if (description.IsDeprecated) | ||
{ | ||
text.Append(" This API version has been deprecated."); | ||
} | ||
|
||
if (description.SunsetPolicy is { } policy) | ||
{ | ||
if (policy.Date is { } when) | ||
{ | ||
text.Append(" The API will be sunset on ") | ||
.Append(when.Date.ToShortDateString()) | ||
.Append('.'); | ||
} | ||
|
||
if (policy.HasLinks) | ||
{ | ||
text.AppendLine(); | ||
|
||
foreach (var link in policy.Links) | ||
{ | ||
if (link.Type != "text/html") | ||
{ | ||
continue; | ||
} | ||
|
||
text.AppendLine(); | ||
|
||
if (link.Title.HasValue) | ||
{ | ||
text.Append(link.Title.Value).Append(": "); | ||
} | ||
|
||
text.Append(link.LinkTarget.OriginalString); | ||
} | ||
} | ||
} | ||
|
||
info.Description = text.ToString(); | ||
|
||
return info; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../Scenarios/DemoSample/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/GlobalUsings.verified.cs
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
88 changes: 88 additions & 0 deletions
88
...le/VerifyServerAll/Mvc_WPD/src/DemoSample.Api/Options/ConfigureSwaggerOptions.verified.cs
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,88 @@ | ||
namespace DemoSample.Api.Options; | ||
|
||
public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions> | ||
{ | ||
private readonly IApiVersionDescriptionProvider provider; | ||
private readonly IWebHostEnvironment environment; | ||
|
||
/// <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> | ||
/// <param name="environment">The environment.</param> | ||
public ConfigureSwaggerOptions( | ||
IApiVersionDescriptionProvider provider, | ||
IWebHostEnvironment environment) | ||
{ | ||
this.provider = provider; | ||
this.environment = environment; | ||
} | ||
|
||
/// <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)); | ||
} | ||
} | ||
|
||
private OpenApiInfo CreateInfoForApiVersion( | ||
ApiVersionDescription description) | ||
{ | ||
var text = new StringBuilder("Demo Sample Api - SingleFileVersion"); | ||
var info = new OpenApiInfo | ||
{ | ||
Title = $"{environment.ApplicationName} {description.GroupName.ToUpperInvariant()}", | ||
Version = description.ApiVersion.ToString(), | ||
Contact = new OpenApiContact | ||
{ | ||
Name = "atc-net A/S", | ||
}, | ||
}; | ||
|
||
if (description.IsDeprecated) | ||
{ | ||
text.Append(" This API version has been deprecated."); | ||
} | ||
|
||
if (description.SunsetPolicy is { } policy) | ||
{ | ||
if (policy.Date is { } when) | ||
{ | ||
text.Append(" The API will be sunset on ") | ||
.Append(when.Date.ToShortDateString()) | ||
.Append('.'); | ||
} | ||
|
||
if (policy.HasLinks) | ||
{ | ||
text.AppendLine(); | ||
|
||
foreach (var link in policy.Links) | ||
{ | ||
if (link.Type != "text/html") | ||
{ | ||
continue; | ||
} | ||
|
||
text.AppendLine(); | ||
|
||
if (link.Title.HasValue) | ||
{ | ||
text.Append(link.Title.Value).Append(": "); | ||
} | ||
|
||
text.Append(link.LinkTarget.OriginalString); | ||
} | ||
} | ||
} | ||
|
||
info.Description = text.ToString(); | ||
|
||
return info; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...esponseTypes/VerifyServerAll/Mvc_WOPD/src/ExAllResponseTypes.Api/GlobalUsings.verified.cs
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
Oops, something went wrong.