X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Frestapi%2Foperations%2Fa1_api.go;fp=pkg%2Frestapi%2Foperations%2Fa1_api.go;h=a526e997ab9c042092a9c2be17b312a7ab09ae3e;hb=5152bd39551f19139752d89a795327ca9dd189db;hp=c8a14b167ff643b465e957ec067aceeafd93a426;hpb=272fb5b36779f68a944ca317fa6a6159da0128e3;p=ric-plt%2Fa1.git diff --git a/pkg/restapi/operations/a1_api.go b/pkg/restapi/operations/a1_api.go index c8a14b1..a526e99 100644 --- a/pkg/restapi/operations/a1_api.go +++ b/pkg/restapi/operations/a1_api.go @@ -39,8 +39,8 @@ import ( "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" - "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_e_i_data_delivery" - "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_e_i_data_delivery" + "gerrit.o-ran-sc.org/r/ric-plt/a1/pkg/restapi/operations/a1_mediator" ) // NewA1API creates a new A1 instance @@ -55,6 +55,7 @@ func NewA1API(spec *loads.Document) *A1API { PreServerShutdown: func() {}, ServerShutdown: func() {}, spec: spec, + useSwaggerUI: false, ServeError: errors.ServeError, BasicAuthenticator: security.BasicAuth, APIKeyAuthenticator: security.APIKeyAuth, @@ -111,13 +112,16 @@ type A1API struct { defaultConsumes string defaultProduces string Middleware func(middleware.Builder) http.Handler + useSwaggerUI bool // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function. // It has a default implementation in the security package, however you can replace it for your particular usage. BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator + // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function. // It has a default implementation in the security package, however you can replace it for your particular usage. APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator + // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function. // It has a default implementation in the security package, however you can replace it for your particular usage. BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator @@ -152,6 +156,7 @@ type A1API struct { A1MediatorA1ControllerGetPolicyInstanceStatusHandler a1_mediator.A1ControllerGetPolicyInstanceStatusHandler // A1MediatorA1ControllerGetPolicyTypeHandler sets the operation handler for the a1 controller get policy type operation A1MediatorA1ControllerGetPolicyTypeHandler a1_mediator.A1ControllerGetPolicyTypeHandler + // ServeError is called when an error is received, there is a default handler // but you can set your own with this ServeError func(http.ResponseWriter, *http.Request, error) @@ -171,6 +176,16 @@ type A1API struct { Logger func(string, ...interface{}) } +// UseRedoc for documentation at /docs +func (o *A1API) UseRedoc() { + o.useSwaggerUI = false +} + +// UseSwaggerUI for documentation at /docs +func (o *A1API) UseSwaggerUI() { + o.useSwaggerUI = true +} + // SetDefaultProduces sets the default produces media type func (o *A1API) SetDefaultProduces(mediaType string) { o.defaultProduces = mediaType @@ -393,6 +408,9 @@ func (o *A1API) Serve(builder middleware.Builder) http.Handler { if o.Middleware != nil { return o.Middleware(builder) } + if o.useSwaggerUI { + return o.context.APIHandlerSwaggerUI(builder) + } return o.context.APIHandler(builder) }