1 // Code generated by go-swagger; DO NOT EDIT.
5 // This file was generated by the swagger tool.
6 // Editing this file might prove futile when you re-run the swagger generate command
13 "github.com/go-openapi/errors"
14 "github.com/go-openapi/loads"
15 "github.com/go-openapi/runtime"
16 "github.com/go-openapi/runtime/middleware"
17 "github.com/go-openapi/runtime/security"
18 "github.com/go-openapi/spec"
19 "github.com/go-openapi/strfmt"
20 "github.com/go-openapi/swag"
22 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/common"
23 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/xapp"
26 // NewXappFrameworkAPI creates a new XappFramework instance
27 func NewXappFrameworkAPI(spec *loads.Document) *XappFrameworkAPI {
28 return &XappFrameworkAPI{
29 handlers: make(map[string]map[string]http.Handler),
30 formats: strfmt.Default,
31 defaultConsumes: "application/json",
32 defaultProduces: "application/json",
33 customConsumers: make(map[string]runtime.Consumer),
34 customProducers: make(map[string]runtime.Producer),
35 PreServerShutdown: func() {},
36 ServerShutdown: func() {},
38 ServeError: errors.ServeError,
39 BasicAuthenticator: security.BasicAuth,
40 APIKeyAuthenticator: security.APIKeyAuth,
41 BearerAuthenticator: security.BearerAuth,
43 JSONConsumer: runtime.JSONConsumer(),
45 JSONProducer: runtime.JSONProducer(),
46 XMLProducer: runtime.XMLProducer(),
48 CommonSubscribeHandler: common.SubscribeHandlerFunc(func(params common.SubscribeParams) middleware.Responder {
49 return middleware.NotImplemented("operation common.Subscribe has not yet been implemented")
51 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
52 return middleware.NotImplemented("operation common.Unsubscribe has not yet been implemented")
54 CommonGetAllSubscriptionsHandler: common.GetAllSubscriptionsHandlerFunc(func(params common.GetAllSubscriptionsParams) middleware.Responder {
55 return middleware.NotImplemented("operation common.GetAllSubscriptions has not yet been implemented")
57 XappGetXappConfigListHandler: xapp.GetXappConfigListHandlerFunc(func(params xapp.GetXappConfigListParams) middleware.Responder {
58 return middleware.NotImplemented("operation xapp.GetXappConfigList has not yet been implemented")
63 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
64 type XappFrameworkAPI struct {
66 context *middleware.Context
67 handlers map[string]map[string]http.Handler
68 formats strfmt.Registry
69 customConsumers map[string]runtime.Consumer
70 customProducers map[string]runtime.Producer
71 defaultConsumes string
72 defaultProduces string
73 Middleware func(middleware.Builder) http.Handler
75 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
76 // It has a default implementation in the security package, however you can replace it for your particular usage.
77 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
78 // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
79 // It has a default implementation in the security package, however you can replace it for your particular usage.
80 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
81 // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
82 // It has a default implementation in the security package, however you can replace it for your particular usage.
83 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
85 // JSONConsumer registers a consumer for the following mime types:
87 JSONConsumer runtime.Consumer
89 // JSONProducer registers a producer for the following mime types:
91 JSONProducer runtime.Producer
92 // XMLProducer registers a producer for the following mime types:
94 XMLProducer runtime.Producer
96 // CommonSubscribeHandler sets the operation handler for the subscribe operation
97 CommonSubscribeHandler common.SubscribeHandler
98 // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation
99 CommonUnsubscribeHandler common.UnsubscribeHandler
100 // CommonGetAllSubscriptionsHandler sets the operation handler for the get all subscriptions operation
101 CommonGetAllSubscriptionsHandler common.GetAllSubscriptionsHandler
102 // XappGetXappConfigListHandler sets the operation handler for the get xapp config list operation
103 XappGetXappConfigListHandler xapp.GetXappConfigListHandler
104 // ServeError is called when an error is received, there is a default handler
105 // but you can set your own with this
106 ServeError func(http.ResponseWriter, *http.Request, error)
108 // PreServerShutdown is called before the HTTP(S) server is shutdown
109 // This allows for custom functions to get executed before the HTTP(S) server stops accepting traffic
110 PreServerShutdown func()
112 // ServerShutdown is called when the HTTP(S) server is shut down and done
113 // handling all active connections and does not accept connections any more
114 ServerShutdown func()
116 // Custom command line argument groups with their descriptions
117 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
119 // User defined logger function.
120 Logger func(string, ...interface{})
123 // SetDefaultProduces sets the default produces media type
124 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
125 o.defaultProduces = mediaType
128 // SetDefaultConsumes returns the default consumes media type
129 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
130 o.defaultConsumes = mediaType
133 // SetSpec sets a spec that will be served for the clients.
134 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
138 // DefaultProduces returns the default produces media type
139 func (o *XappFrameworkAPI) DefaultProduces() string {
140 return o.defaultProduces
143 // DefaultConsumes returns the default consumes media type
144 func (o *XappFrameworkAPI) DefaultConsumes() string {
145 return o.defaultConsumes
148 // Formats returns the registered string formats
149 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
153 // RegisterFormat registers a custom format validator
154 func (o *XappFrameworkAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
155 o.formats.Add(name, format, validator)
158 // Validate validates the registrations in the XappFrameworkAPI
159 func (o *XappFrameworkAPI) Validate() error {
160 var unregistered []string
162 if o.JSONConsumer == nil {
163 unregistered = append(unregistered, "JSONConsumer")
166 if o.JSONProducer == nil {
167 unregistered = append(unregistered, "JSONProducer")
169 if o.XMLProducer == nil {
170 unregistered = append(unregistered, "XMLProducer")
173 if o.CommonSubscribeHandler == nil {
174 unregistered = append(unregistered, "common.SubscribeHandler")
176 if o.CommonUnsubscribeHandler == nil {
177 unregistered = append(unregistered, "common.UnsubscribeHandler")
179 if o.CommonGetAllSubscriptionsHandler == nil {
180 unregistered = append(unregistered, "common.GetAllSubscriptionsHandler")
182 if o.XappGetXappConfigListHandler == nil {
183 unregistered = append(unregistered, "xapp.GetXappConfigListHandler")
186 if len(unregistered) > 0 {
187 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
193 // ServeErrorFor gets a error handler for a given operation id
194 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
198 // AuthenticatorsFor gets the authenticators for the specified security schemes
199 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
203 // Authorizer returns the registered authorizer
204 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
208 // ConsumersFor gets the consumers for the specified media types.
209 // MIME type parameters are ignored here.
210 func (o *XappFrameworkAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
211 result := make(map[string]runtime.Consumer, len(mediaTypes))
212 for _, mt := range mediaTypes {
214 case "application/json":
215 result["application/json"] = o.JSONConsumer
218 if c, ok := o.customConsumers[mt]; ok {
225 // ProducersFor gets the producers for the specified media types.
226 // MIME type parameters are ignored here.
227 func (o *XappFrameworkAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
228 result := make(map[string]runtime.Producer, len(mediaTypes))
229 for _, mt := range mediaTypes {
231 case "application/json":
232 result["application/json"] = o.JSONProducer
233 case "application/xml":
234 result["application/xml"] = o.XMLProducer
237 if p, ok := o.customProducers[mt]; ok {
244 // HandlerFor gets a http.Handler for the provided operation method and path
245 func (o *XappFrameworkAPI) HandlerFor(method, path string) (http.Handler, bool) {
246 if o.handlers == nil {
249 um := strings.ToUpper(method)
250 if _, ok := o.handlers[um]; !ok {
256 h, ok := o.handlers[um][path]
260 // Context returns the middleware context for the xapp framework API
261 func (o *XappFrameworkAPI) Context() *middleware.Context {
262 if o.context == nil {
263 o.context = middleware.NewRoutableContext(o.spec, o, nil)
269 func (o *XappFrameworkAPI) initHandlerCache() {
270 o.Context() // don't care about the result, just that the initialization happened
271 if o.handlers == nil {
272 o.handlers = make(map[string]map[string]http.Handler)
275 if o.handlers["POST"] == nil {
276 o.handlers["POST"] = make(map[string]http.Handler)
278 o.handlers["POST"]["/subscriptions"] = common.NewSubscribe(o.context, o.CommonSubscribeHandler)
279 if o.handlers["DELETE"] == nil {
280 o.handlers["DELETE"] = make(map[string]http.Handler)
282 o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler)
283 if o.handlers["GET"] == nil {
284 o.handlers["GET"] = make(map[string]http.Handler)
286 o.handlers["GET"]["/subscriptions"] = common.NewGetAllSubscriptions(o.context, o.CommonGetAllSubscriptionsHandler)
287 if o.handlers["GET"] == nil {
288 o.handlers["GET"] = make(map[string]http.Handler)
290 o.handlers["GET"]["/config"] = xapp.NewGetXappConfigList(o.context, o.XappGetXappConfigListHandler)
293 // Serve creates a http handler to serve the API over HTTP
294 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
295 func (o *XappFrameworkAPI) Serve(builder middleware.Builder) http.Handler {
298 if o.Middleware != nil {
299 return o.Middleware(builder)
301 return o.context.APIHandler(builder)
304 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
305 func (o *XappFrameworkAPI) Init() {
306 if len(o.handlers) == 0 {
311 // RegisterConsumer allows you to add (or override) a consumer for a media type.
312 func (o *XappFrameworkAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
313 o.customConsumers[mediaType] = consumer
316 // RegisterProducer allows you to add (or override) a producer for a media type.
317 func (o *XappFrameworkAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
318 o.customProducers[mediaType] = producer
321 // AddMiddlewareFor adds a http middleware to existing handler
322 func (o *XappFrameworkAPI) AddMiddlewareFor(method, path string, builder middleware.Builder) {
323 um := strings.ToUpper(method)
328 if h, ok := o.handlers[um][path]; ok {
329 o.handlers[method][path] = builder(h)