- BasicAuthenticationAttribute: AllowAnonymous-Handling ergänzt, Fehlerbehandlung für ungültige Header verbessert, WWW-Authenticate-Header korrigiert, Credential-Handling robuster gestaltet. - WiseController: Webhook akzeptiert jetzt JSON und Text, asynchrone Verarbeitung, robustere Deserialisierung, <AllowAnonymous> auf Klassenebene. - WiseWebhookExampleProcessor: OpenAPI/Swagger-Doku erweitert (application/json & text/plain, Beispiele, flexiblere Schemas). - SwaggerConfig: Unsichtbares Zeichen entfernt. - .gitignore: Codacy-spezifische Anweisungen ausgeschlossen. - codacy.instructions.md: Neue Datei mit KI-Verhaltensregeln für Codacy-Analysen hinzugefügt.
112 lines
8.0 KiB
VB.net
112 lines
8.0 KiB
VB.net
Imports System.Web.Http
|
||
Imports System.Web.Http.Description
|
||
Imports System.Web.Routing
|
||
Imports Microsoft.Extensions.Options
|
||
Imports Swashbuckle.Application
|
||
Imports NSwag.AspNet.Owin
|
||
Imports System.IO
|
||
Imports System.Reflection
|
||
|
||
|
||
|
||
'<Assembly: PreApplicationStartMethod(GetType(SwaggerConfig), "Register")>
|
||
|
||
|
||
Public Class SwaggerConfig
|
||
|
||
Private Shared descr As String = "VERAG API"
|
||
|
||
|
||
Public Shared Sub Register2(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) As SwaggerDocsConfig
|
||
|
||
|
||
c.PrettyPrint()
|
||
c.MultipleApiVersions(Function(apiDesc, targetApiVersion) ResolveVersionSupportByRouteConstraint(apiDesc, targetApiVersion), Function(vc) As VersionInfoBuilder
|
||
|
||
vc.Version("1", descr & " V1").Description("A sample API for testing ").TermsOfService("Some Terms").Contact(Function(cont) As ContactBuilder
|
||
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("2", descr & " V2")
|
||
vc.Version("3", descr & " V3")
|
||
Return vc
|
||
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)()
|
||
|
||
|
||
Return c
|
||
End Function).EnableSwaggerUi(Function(c) As SwaggerUiConfig
|
||
c.DocumentTitle(descr)
|
||
|
||
c.EnableDiscoveryUrlSelector()
|
||
c.DocExpansion(DocExpansion.List)
|
||
|
||
c.CustomAsset("index", thisAssembly, "VERAG_REST_SERVER.my_index.html")
|
||
|
||
Return c
|
||
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
|
||
|
||
Public Shared Sub Register(ByVal config As HttpConfiguration)
|
||
|
||
RouteTable.Routes.MapOwinPath("swagger", Sub(app)
|
||
|
||
|
||
|
||
app.UseSwaggerUi(GetType(WebApiApplication).Assembly, Function(settings) As SwaggerUiSettings(Of NSwag.Generation.WebApi.WebApiOpenApiDocumentGeneratorSettings)
|
||
settings.MiddlewareBasePath = "/swagger"
|
||
settings.GeneratorSettings.OperationProcessors.Add(New WiseWebhookExampleProcessor())
|
||
settings.GeneratorSettings.DefaultUrlTemplate = "api/{controller}/{id}"
|
||
settings.DocumentTitle = descr
|
||
settings.DocExpansion = "list"
|
||
settings.DefaultModelsExpandDepth = -1
|
||
Return settings
|
||
End Function)
|
||
|
||
|
||
|
||
End Sub)
|
||
|
||
|
||
End Sub
|
||
|
||
|
||
End Class
|