Files
REST_SERVER/VERAG_REST_SERVER/App_Start/SwaggerConfig.vb
m.ilhan 5c8daaabc0 Verbesserung Auth, Webhook-Handling & Codacy-Integration
- 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.
2025-12-10 15:12:02 +01:00

112 lines
8.0 KiB
VB.net
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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