Add optional subscription ID
[ric-plt/xapp-frame.git] / pkg / restapi / operations / xapp_framework_api.go
1 // Code generated by go-swagger; DO NOT EDIT.
2
3 package operations
4
5 // This file was generated by the swagger tool.
6 // Editing this file might prove futile when you re-run the swagger generate command
7
8 import (
9         "fmt"
10         "net/http"
11         "strings"
12
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"
21
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"
24 )
25
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() {},
37                 spec:                spec,
38                 ServeError:          errors.ServeError,
39                 BasicAuthenticator:  security.BasicAuth,
40                 APIKeyAuthenticator: security.APIKeyAuth,
41                 BearerAuthenticator: security.BearerAuth,
42
43                 JSONConsumer: runtime.JSONConsumer(),
44
45                 JSONProducer: runtime.JSONProducer(),
46                 XMLProducer:  runtime.XMLProducer(),
47
48                 CommonSubscribeHandler: common.SubscribeHandlerFunc(func(params common.SubscribeParams) middleware.Responder {
49                         return middleware.NotImplemented("operation common.Subscribe has not yet been implemented")
50                 }),
51                 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
52                         return middleware.NotImplemented("operation common.Unsubscribe has not yet been implemented")
53                 }),
54                 CommonGetAllSubscriptionsHandler: common.GetAllSubscriptionsHandlerFunc(func(params common.GetAllSubscriptionsParams) middleware.Responder {
55                         return middleware.NotImplemented("operation common.GetAllSubscriptions has not yet been implemented")
56                 }),
57                 XappGetXappConfigListHandler: xapp.GetXappConfigListHandlerFunc(func(params xapp.GetXappConfigListParams) middleware.Responder {
58                         return middleware.NotImplemented("operation xapp.GetXappConfigList has not yet been implemented")
59                 }),
60         }
61 }
62
63 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
64 type XappFrameworkAPI struct {
65         spec            *loads.Document
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
74
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
84
85         // JSONConsumer registers a consumer for the following mime types:
86         //   - application/json
87         JSONConsumer runtime.Consumer
88
89         // JSONProducer registers a producer for the following mime types:
90         //   - application/json
91         JSONProducer runtime.Producer
92         // XMLProducer registers a producer for the following mime types:
93         //   - application/xml
94         XMLProducer runtime.Producer
95
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)
107
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()
111
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()
115
116         // Custom command line argument groups with their descriptions
117         CommandLineOptionsGroups []swag.CommandLineOptionsGroup
118
119         // User defined logger function.
120         Logger func(string, ...interface{})
121 }
122
123 // SetDefaultProduces sets the default produces media type
124 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
125         o.defaultProduces = mediaType
126 }
127
128 // SetDefaultConsumes returns the default consumes media type
129 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
130         o.defaultConsumes = mediaType
131 }
132
133 // SetSpec sets a spec that will be served for the clients.
134 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
135         o.spec = spec
136 }
137
138 // DefaultProduces returns the default produces media type
139 func (o *XappFrameworkAPI) DefaultProduces() string {
140         return o.defaultProduces
141 }
142
143 // DefaultConsumes returns the default consumes media type
144 func (o *XappFrameworkAPI) DefaultConsumes() string {
145         return o.defaultConsumes
146 }
147
148 // Formats returns the registered string formats
149 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
150         return o.formats
151 }
152
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)
156 }
157
158 // Validate validates the registrations in the XappFrameworkAPI
159 func (o *XappFrameworkAPI) Validate() error {
160         var unregistered []string
161
162         if o.JSONConsumer == nil {
163                 unregistered = append(unregistered, "JSONConsumer")
164         }
165
166         if o.JSONProducer == nil {
167                 unregistered = append(unregistered, "JSONProducer")
168         }
169         if o.XMLProducer == nil {
170                 unregistered = append(unregistered, "XMLProducer")
171         }
172
173         if o.CommonSubscribeHandler == nil {
174                 unregistered = append(unregistered, "common.SubscribeHandler")
175         }
176         if o.CommonUnsubscribeHandler == nil {
177                 unregistered = append(unregistered, "common.UnsubscribeHandler")
178         }
179         if o.CommonGetAllSubscriptionsHandler == nil {
180                 unregistered = append(unregistered, "common.GetAllSubscriptionsHandler")
181         }
182         if o.XappGetXappConfigListHandler == nil {
183                 unregistered = append(unregistered, "xapp.GetXappConfigListHandler")
184         }
185
186         if len(unregistered) > 0 {
187                 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
188         }
189
190         return nil
191 }
192
193 // ServeErrorFor gets a error handler for a given operation id
194 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
195         return o.ServeError
196 }
197
198 // AuthenticatorsFor gets the authenticators for the specified security schemes
199 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
200         return nil
201 }
202
203 // Authorizer returns the registered authorizer
204 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
205         return nil
206 }
207
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 {
213                 switch mt {
214                 case "application/json":
215                         result["application/json"] = o.JSONConsumer
216                 }
217
218                 if c, ok := o.customConsumers[mt]; ok {
219                         result[mt] = c
220                 }
221         }
222         return result
223 }
224
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 {
230                 switch mt {
231                 case "application/json":
232                         result["application/json"] = o.JSONProducer
233                 case "application/xml":
234                         result["application/xml"] = o.XMLProducer
235                 }
236
237                 if p, ok := o.customProducers[mt]; ok {
238                         result[mt] = p
239                 }
240         }
241         return result
242 }
243
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 {
247                 return nil, false
248         }
249         um := strings.ToUpper(method)
250         if _, ok := o.handlers[um]; !ok {
251                 return nil, false
252         }
253         if path == "/" {
254                 path = ""
255         }
256         h, ok := o.handlers[um][path]
257         return h, ok
258 }
259
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)
264         }
265
266         return o.context
267 }
268
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)
273         }
274
275         if o.handlers["POST"] == nil {
276                 o.handlers["POST"] = make(map[string]http.Handler)
277         }
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)
281         }
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)
285         }
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)
289         }
290         o.handlers["GET"]["/config"] = xapp.NewGetXappConfigList(o.context, o.XappGetXappConfigListHandler)
291 }
292
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 {
296         o.Init()
297
298         if o.Middleware != nil {
299                 return o.Middleware(builder)
300         }
301         return o.context.APIHandler(builder)
302 }
303
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 {
307                 o.initHandlerCache()
308         }
309 }
310
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
314 }
315
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
319 }
320
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)
324         if path == "/" {
325                 path = ""
326         }
327         o.Init()
328         if h, ok := o.handlers[um][path]; ok {
329                 o.handlers[method][path] = builder(h)
330         }
331 }