88 lines
6.0 KiB
VB.net
88 lines
6.0 KiB
VB.net
Imports System.IO
|
|
Imports System.Net.Http
|
|
Imports System.Reflection
|
|
Imports System.Web.Http
|
|
Imports System.Web.Http.Description
|
|
Imports Microsoft.Extensions.Options
|
|
Imports Swashbuckle.Application
|
|
Imports Swashbuckle.Swagger
|
|
Imports Swashbuckle.SwaggerUi
|
|
|
|
|
|
|
|
'<Assembly: PreApplicationStartMethod(GetType(SwaggerConfig), "Register")>
|
|
|
|
|
|
Public Class SwaggerConfig
|
|
|
|
Private Shared descr As String = "VERAG API"
|
|
|
|
|
|
Public Shared Sub Register(ByVal config As HttpConfiguration)
|
|
Dim thisAssembly = GetType(SwaggerConfig).Assembly
|
|
|
|
Dim baseDirectory = AppDomain.CurrentDomain.BaseDirectory
|
|
baseDirectory &= "\bin\"
|
|
Dim commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".XML"
|
|
Dim commentsFile = Path.Combine(baseDirectory, commentsFileName)
|
|
|
|
GlobalConfiguration.Configuration.EnableSwagger(Function(c)
|
|
|
|
|
|
c.PrettyPrint()
|
|
c.MultipleApiVersions(Function(apiDesc, targetApiVersion) ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), Function(vc)
|
|
|
|
vc.Version("v1", descr & " V1").Description("A sample API for testing ").TermsOfService("Some Terms").Contact(Function(cont)
|
|
cont.Name("VERAG AG")
|
|
cont.Url("http://test.at")
|
|
cont.Email("Mail.test")
|
|
End Function).License(Function(lic)
|
|
lic.Name("Lizenz")
|
|
lic.Url("http://test.at")
|
|
End Function)
|
|
|
|
|
|
vc.Version("v2", descr & " V2")
|
|
vc.Version("v3", descr & " V3")
|
|
End Function)
|
|
|
|
|
|
c.BasicAuth("basic").Description("Basic HTTP Authentication")
|
|
|
|
c.IncludeXmlComments(commentsFile)
|
|
|
|
|
|
'c.RootUrl(Function(req) req.GetRouteData)
|
|
|
|
'c.OperationFilter(Of AddAuthorizationHeaderParameterOperationFilter)()
|
|
|
|
'c.OperationFilter(Of BasicAuthenticationAttribute)()
|
|
|
|
|
|
|
|
End Function).EnableSwaggerUi(Function(c)
|
|
c.DocumentTitle(descr)
|
|
|
|
c.EnableDiscoveryUrlSelector()
|
|
c.DocExpansion(DocExpansion.List)
|
|
|
|
c.CustomAsset("index", thisAssembly, "VERAG_REST_SERVER.my_index.html")
|
|
|
|
|
|
|
|
|
|
|
|
End Function)
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
Public Shared Function ResolveVersionSupportByRouteConstraint(ByVal apiDesc As ApiDescription, ByVal targetApiVersion As String) As Boolean
|
|
Return apiDesc.ID.Contains($"/{targetApiVersion}/")
|
|
'Return apiDesc.ActionDescriptor.ControllerDescriptor.ControllerType.FullName.Contains($"{targetApiVersion}")
|
|
|
|
End Function
|
|
|
|
End Class
|