Skip to content

Commit 089dd2e

Browse files
committed
Create SwaggerInfo.cs
moved to new static class file to construct Swagger Info
1 parent 1a52c16 commit 089dd2e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

Supermarket/Swagger/SwaggerInfo.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Mvc.ApiExplorer;
2+
using Swashbuckle.AspNetCore.Swagger;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Reflection;
7+
using System.Threading.Tasks;
8+
9+
namespace Supermarket.Swagger
10+
{
11+
public static class SwaggerInfo
12+
{
13+
public static Info CreateInfoForApiVersion(ApiVersionDescription description, Type type)
14+
{
15+
var info = new Info()
16+
{
17+
Title = $"{type.Assembly.GetCustomAttribute<AssemblyProductAttribute>().Product} {description.ApiVersion}",
18+
Version = description.ApiVersion.ToString(),
19+
Description = "A simple example ASP.NET Core Web API",
20+
TermsOfService = "None",
21+
Contact = new Contact { Name = "Mathavan N", Email = "mathavan@gmail.com", Url = "https://github.com/Mathavana" },
22+
License = new License { Name = "Use under LICX", Url = "https://example.com/license" }
23+
};
24+
25+
if (description.IsDeprecated)
26+
{
27+
info.Description += " This API version has been deprecated.";
28+
}
29+
30+
return info;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)