Changing implementation for url to align with spec
[ric-plt/a1.git] / pkg / restapi / operations / a1_api.go
index c8a14b1..3d626cd 100644 (file)
@@ -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
@@ -342,11 +357,11 @@ func (o *A1API) initHandlerCache() {
        if o.handlers["PUT"] == nil {
                o.handlers["PUT"] = make(map[string]http.Handler)
        }
-       o.handlers["PUT"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerCreateOrReplacePolicyInstance(o.context, o.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler)
+       o.handlers["PUT"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerCreateOrReplacePolicyInstance(o.context, o.A1MediatorA1ControllerCreateOrReplacePolicyInstanceHandler)
        if o.handlers["PUT"] == nil {
                o.handlers["PUT"] = make(map[string]http.Handler)
        }
-       o.handlers["PUT"]["/a1-p/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerCreatePolicyType(o.context, o.A1MediatorA1ControllerCreatePolicyTypeHandler)
+       o.handlers["PUT"]["/A1-P/v2/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerCreatePolicyType(o.context, o.A1MediatorA1ControllerCreatePolicyTypeHandler)
        if o.handlers["POST"] == nil {
                o.handlers["POST"] = make(map[string]http.Handler)
        }
@@ -354,35 +369,35 @@ func (o *A1API) initHandlerCache() {
        if o.handlers["DELETE"] == nil {
                o.handlers["DELETE"] = make(map[string]http.Handler)
        }
-       o.handlers["DELETE"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerDeletePolicyInstance(o.context, o.A1MediatorA1ControllerDeletePolicyInstanceHandler)
+       o.handlers["DELETE"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerDeletePolicyInstance(o.context, o.A1MediatorA1ControllerDeletePolicyInstanceHandler)
        if o.handlers["DELETE"] == nil {
                o.handlers["DELETE"] = make(map[string]http.Handler)
        }
-       o.handlers["DELETE"]["/a1-p/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerDeletePolicyType(o.context, o.A1MediatorA1ControllerDeletePolicyTypeHandler)
+       o.handlers["DELETE"]["/A1-P/v2/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerDeletePolicyType(o.context, o.A1MediatorA1ControllerDeletePolicyTypeHandler)
        if o.handlers["GET"] == nil {
                o.handlers["GET"] = make(map[string]http.Handler)
        }
-       o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}/policies"] = a1_mediator.NewA1ControllerGetAllInstancesForType(o.context, o.A1MediatorA1ControllerGetAllInstancesForTypeHandler)
+       o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}/policies"] = a1_mediator.NewA1ControllerGetAllInstancesForType(o.context, o.A1MediatorA1ControllerGetAllInstancesForTypeHandler)
        if o.handlers["GET"] == nil {
                o.handlers["GET"] = make(map[string]http.Handler)
        }
-       o.handlers["GET"]["/a1-p/policytypes"] = a1_mediator.NewA1ControllerGetAllPolicyTypes(o.context, o.A1MediatorA1ControllerGetAllPolicyTypesHandler)
+       o.handlers["GET"]["/A1-P/v2/policytypes"] = a1_mediator.NewA1ControllerGetAllPolicyTypes(o.context, o.A1MediatorA1ControllerGetAllPolicyTypesHandler)
        if o.handlers["GET"] == nil {
                o.handlers["GET"] = make(map[string]http.Handler)
        }
-       o.handlers["GET"]["/a1-p/healthcheck"] = a1_mediator.NewA1ControllerGetHealthcheck(o.context, o.A1MediatorA1ControllerGetHealthcheckHandler)
+       o.handlers["GET"]["/A1-P/v2/healthcheck"] = a1_mediator.NewA1ControllerGetHealthcheck(o.context, o.A1MediatorA1ControllerGetHealthcheckHandler)
        if o.handlers["GET"] == nil {
                o.handlers["GET"] = make(map[string]http.Handler)
        }
-       o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerGetPolicyInstance(o.context, o.A1MediatorA1ControllerGetPolicyInstanceHandler)
+       o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}"] = a1_mediator.NewA1ControllerGetPolicyInstance(o.context, o.A1MediatorA1ControllerGetPolicyInstanceHandler)
        if o.handlers["GET"] == nil {
                o.handlers["GET"] = make(map[string]http.Handler)
        }
-       o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}/policies/{policy_instance_id}/status"] = a1_mediator.NewA1ControllerGetPolicyInstanceStatus(o.context, o.A1MediatorA1ControllerGetPolicyInstanceStatusHandler)
+       o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}/policies/{policy_instance_id}/status"] = a1_mediator.NewA1ControllerGetPolicyInstanceStatus(o.context, o.A1MediatorA1ControllerGetPolicyInstanceStatusHandler)
        if o.handlers["GET"] == nil {
                o.handlers["GET"] = make(map[string]http.Handler)
        }
-       o.handlers["GET"]["/a1-p/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerGetPolicyType(o.context, o.A1MediatorA1ControllerGetPolicyTypeHandler)
+       o.handlers["GET"]["/A1-P/v2/policytypes/{policy_type_id}"] = a1_mediator.NewA1ControllerGetPolicyType(o.context, o.A1MediatorA1ControllerGetPolicyTypeHandler)
 }
 
 // Serve creates a http handler to serve the API over HTTP
@@ -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)
 }