finished implementing characters endpoints
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace server.SwaggerOptions
|
||||
{
|
||||
public class ConfigureSwaggerOptions : IConfigureOptions<SwaggerGenOptions>
|
||||
{
|
||||
private readonly IApiVersionDescriptionProvider _provider;
|
||||
|
||||
public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider)
|
||||
{
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
public void Configure(SwaggerGenOptions options)
|
||||
{
|
||||
foreach (var description in _provider.ApiVersionDescriptions)
|
||||
{
|
||||
var versionInfo = CreateVersionInfo(description);
|
||||
|
||||
options.SwaggerDoc(description.GroupName, versionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
private static OpenApiInfo CreateVersionInfo(ApiVersionDescription description)
|
||||
{
|
||||
var info = new OpenApiInfo
|
||||
{
|
||||
Title = "criminalmindsapi",
|
||||
Version = description.ApiVersion.ToString(),
|
||||
Description = "An api that provides information about the Criminal Minds series.",
|
||||
Contact = new OpenApiContact
|
||||
{
|
||||
Name = "Stevan Freeborn",
|
||||
Email = "stevan.freeborn@gmail.com",
|
||||
Url = new Uri("https://stevanfreeborn.com")
|
||||
}
|
||||
};
|
||||
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
|
||||
namespace server.SwaggerOptions.Filters
|
||||
{
|
||||
public class ApiVersionOperationFilter : IOperationFilter
|
||||
{
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
var headerParameter = operation.Parameters.Where(p => p.Name == "x-api-version").SingleOrDefault();
|
||||
|
||||
if (headerParameter != null)
|
||||
{
|
||||
headerParameter.Description = "Header value that identifies target version of api.";
|
||||
headerParameter.Schema.Default = new OpenApiString(context.DocumentName.ToLower().Replace("v", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user