Commit
This commit is contained in:
52
VERAG_REST_SERVER/App_Start/SwaggerConfig.vb
Normal file
52
VERAG_REST_SERVER/App_Start/SwaggerConfig.vb
Normal file
@@ -0,0 +1,52 @@
|
||||
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
|
||||
|
||||
|
||||
GlobalConfiguration.Configuration.EnableSwagger(Function(c)
|
||||
'c.SingleApiVersion("v1", descr)
|
||||
c.PrettyPrint()
|
||||
c.MultipleApiVersions(Function(apiDesc, targetApiVersion) ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), Function(vc)
|
||||
|
||||
vc.Version("1", descr & " V1")
|
||||
vc.Version("2", descr & " V2")
|
||||
End Function)
|
||||
|
||||
'c.OAuth2("oauth2").Description("OAuth2 Implicit Grant").Flow("implicit").AuthorizationUrl("http://petstore.swagger.wordnik.com/api/oauth/dialog").Scopes(Function(scopes)
|
||||
' scopes.Add("read", "Read access to protected resources")
|
||||
' scopes.Add("write", "Write access to protected resources")
|
||||
' End Function)
|
||||
|
||||
End Function).EnableSwaggerUi(Function(c)
|
||||
c.DocumentTitle(descr)
|
||||
c.EnableDiscoveryUrlSelector()
|
||||
c.DocExpansion(DocExpansion.List)
|
||||
'c.EnableOAuth2Support(clientId:="test-client-id", clientSecret:=Nothing, realm:="test-realm", appName:="Swagger UI", additionalQueryStringParams:=New Dictionary(Of String, String)() From {
|
||||
' {"foo", "bar"}
|
||||
'})
|
||||
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
|
||||
Reference in New Issue
Block a user