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 errors "github.com/go-openapi/errors"
14 loads "github.com/go-openapi/loads"
15 runtime "github.com/go-openapi/runtime"
16 middleware "github.com/go-openapi/runtime/middleware"
17 security "github.com/go-openapi/runtime/security"
18 spec "github.com/go-openapi/spec"
19 strfmt "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/control"
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/policy"
25 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/query"
26 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/report"
29 // NewXappFrameworkAPI creates a new XappFramework instance
30 func NewXappFrameworkAPI(spec *loads.Document) *XappFrameworkAPI {
31 return &XappFrameworkAPI{
32 handlers: make(map[string]map[string]http.Handler),
33 formats: strfmt.Default,
34 defaultConsumes: "application/json",
35 defaultProduces: "application/json",
36 customConsumers: make(map[string]runtime.Consumer),
37 customProducers: make(map[string]runtime.Producer),
38 ServerShutdown: func() {},
40 ServeError: errors.ServeError,
41 BasicAuthenticator: security.BasicAuth,
42 APIKeyAuthenticator: security.APIKeyAuth,
43 BearerAuthenticator: security.BearerAuth,
44 JSONConsumer: runtime.JSONConsumer(),
45 JSONProducer: runtime.JSONProducer(),
46 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
47 return middleware.NotImplemented("operation CommonUnsubscribe has not yet been implemented")
49 QueryGetAllSubscriptionsHandler: query.GetAllSubscriptionsHandlerFunc(func(params query.GetAllSubscriptionsParams) middleware.Responder {
50 return middleware.NotImplemented("operation QueryGetAllSubscriptions has not yet been implemented")
52 ControlSubscribeControlHandler: control.SubscribeControlHandlerFunc(func(params control.SubscribeControlParams) middleware.Responder {
53 return middleware.NotImplemented("operation ControlSubscribeControl has not yet been implemented")
55 PolicySubscribePolicyHandler: policy.SubscribePolicyHandlerFunc(func(params policy.SubscribePolicyParams) middleware.Responder {
56 return middleware.NotImplemented("operation PolicySubscribePolicy has not yet been implemented")
58 ReportSubscribeReportHandler: report.SubscribeReportHandlerFunc(func(params report.SubscribeReportParams) middleware.Responder {
59 return middleware.NotImplemented("operation ReportSubscribeReport has not yet been implemented")
64 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
65 type XappFrameworkAPI struct {
67 context *middleware.Context
68 handlers map[string]map[string]http.Handler
69 formats strfmt.Registry
70 customConsumers map[string]runtime.Consumer
71 customProducers map[string]runtime.Producer
72 defaultConsumes string
73 defaultProduces string
74 Middleware func(middleware.Builder) http.Handler
76 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
77 // It has a default implementation in the security package, however you can replace it for your particular usage.
78 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
79 // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
80 // It has a default implementation in the security package, however you can replace it for your particular usage.
81 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
82 // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
83 // It has a default implementation in the security package, however you can replace it for your particular usage.
84 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
86 // JSONConsumer registers a consumer for a "application/json" mime type
87 JSONConsumer runtime.Consumer
89 // JSONProducer registers a producer for a "application/json" mime type
90 JSONProducer runtime.Producer
92 // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation
93 CommonUnsubscribeHandler common.UnsubscribeHandler
94 // QueryGetAllSubscriptionsHandler sets the operation handler for the get all subscriptions operation
95 QueryGetAllSubscriptionsHandler query.GetAllSubscriptionsHandler
96 // ControlSubscribeControlHandler sets the operation handler for the subscribe control operation
97 ControlSubscribeControlHandler control.SubscribeControlHandler
98 // PolicySubscribePolicyHandler sets the operation handler for the subscribe policy operation
99 PolicySubscribePolicyHandler policy.SubscribePolicyHandler
100 // ReportSubscribeReportHandler sets the operation handler for the subscribe report operation
101 ReportSubscribeReportHandler report.SubscribeReportHandler
103 // ServeError is called when an error is received, there is a default handler
104 // but you can set your own with this
105 ServeError func(http.ResponseWriter, *http.Request, error)
107 // ServerShutdown is called when the HTTP(S) server is shut down and done
108 // handling all active connections and does not accept connections any more
109 ServerShutdown func()
111 // Custom command line argument groups with their descriptions
112 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
114 // User defined logger function.
115 Logger func(string, ...interface{})
118 // SetDefaultProduces sets the default produces media type
119 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
120 o.defaultProduces = mediaType
123 // SetDefaultConsumes returns the default consumes media type
124 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
125 o.defaultConsumes = mediaType
128 // SetSpec sets a spec that will be served for the clients.
129 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
133 // DefaultProduces returns the default produces media type
134 func (o *XappFrameworkAPI) DefaultProduces() string {
135 return o.defaultProduces
138 // DefaultConsumes returns the default consumes media type
139 func (o *XappFrameworkAPI) DefaultConsumes() string {
140 return o.defaultConsumes
143 // Formats returns the registered string formats
144 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
148 // RegisterFormat registers a custom format validator
149 func (o *XappFrameworkAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
150 o.formats.Add(name, format, validator)
153 // Validate validates the registrations in the XappFrameworkAPI
154 func (o *XappFrameworkAPI) Validate() error {
155 var unregistered []string
157 if o.JSONConsumer == nil {
158 unregistered = append(unregistered, "JSONConsumer")
161 if o.JSONProducer == nil {
162 unregistered = append(unregistered, "JSONProducer")
165 if o.CommonUnsubscribeHandler == nil {
166 unregistered = append(unregistered, "common.UnsubscribeHandler")
169 if o.QueryGetAllSubscriptionsHandler == nil {
170 unregistered = append(unregistered, "query.GetAllSubscriptionsHandler")
173 if o.ControlSubscribeControlHandler == nil {
174 unregistered = append(unregistered, "control.SubscribeControlHandler")
177 if o.PolicySubscribePolicyHandler == nil {
178 unregistered = append(unregistered, "policy.SubscribePolicyHandler")
181 if o.ReportSubscribeReportHandler == nil {
182 unregistered = append(unregistered, "report.SubscribeReportHandler")
185 if len(unregistered) > 0 {
186 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
192 // ServeErrorFor gets a error handler for a given operation id
193 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
197 // AuthenticatorsFor gets the authenticators for the specified security schemes
198 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
204 // Authorizer returns the registered authorizer
205 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
211 // ConsumersFor gets the consumers for the specified media types
212 func (o *XappFrameworkAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
214 result := make(map[string]runtime.Consumer)
215 for _, mt := range mediaTypes {
218 case "application/json":
219 result["application/json"] = o.JSONConsumer
223 if c, ok := o.customConsumers[mt]; ok {
231 // ProducersFor gets the producers for the specified media types
232 func (o *XappFrameworkAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
234 result := make(map[string]runtime.Producer)
235 for _, mt := range mediaTypes {
238 case "application/json":
239 result["application/json"] = o.JSONProducer
243 if p, ok := o.customProducers[mt]; ok {
251 // HandlerFor gets a http.Handler for the provided operation method and path
252 func (o *XappFrameworkAPI) HandlerFor(method, path string) (http.Handler, bool) {
253 if o.handlers == nil {
256 um := strings.ToUpper(method)
257 if _, ok := o.handlers[um]; !ok {
263 h, ok := o.handlers[um][path]
267 // Context returns the middleware context for the xapp framework API
268 func (o *XappFrameworkAPI) Context() *middleware.Context {
269 if o.context == nil {
270 o.context = middleware.NewRoutableContext(o.spec, o, nil)
276 func (o *XappFrameworkAPI) initHandlerCache() {
277 o.Context() // don't care about the result, just that the initialization happened
279 if o.handlers == nil {
280 o.handlers = make(map[string]map[string]http.Handler)
283 if o.handlers["DELETE"] == nil {
284 o.handlers["DELETE"] = make(map[string]http.Handler)
286 o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler)
288 if o.handlers["GET"] == nil {
289 o.handlers["GET"] = make(map[string]http.Handler)
291 o.handlers["GET"]["/subscriptions"] = query.NewGetAllSubscriptions(o.context, o.QueryGetAllSubscriptionsHandler)
293 if o.handlers["POST"] == nil {
294 o.handlers["POST"] = make(map[string]http.Handler)
296 o.handlers["POST"]["/subscriptions/control"] = control.NewSubscribeControl(o.context, o.ControlSubscribeControlHandler)
298 if o.handlers["POST"] == nil {
299 o.handlers["POST"] = make(map[string]http.Handler)
301 o.handlers["POST"]["/subscriptions/policy"] = policy.NewSubscribePolicy(o.context, o.PolicySubscribePolicyHandler)
303 if o.handlers["POST"] == nil {
304 o.handlers["POST"] = make(map[string]http.Handler)
306 o.handlers["POST"]["/subscriptions/report"] = report.NewSubscribeReport(o.context, o.ReportSubscribeReportHandler)
310 // Serve creates a http handler to serve the API over HTTP
311 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
312 func (o *XappFrameworkAPI) Serve(builder middleware.Builder) http.Handler {
315 if o.Middleware != nil {
316 return o.Middleware(builder)
318 return o.context.APIHandler(builder)
321 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
322 func (o *XappFrameworkAPI) Init() {
323 if len(o.handlers) == 0 {
328 // RegisterConsumer allows you to add (or override) a consumer for a media type.
329 func (o *XappFrameworkAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
330 o.customConsumers[mediaType] = consumer
333 // RegisterProducer allows you to add (or override) a producer for a media type.
334 func (o *XappFrameworkAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
335 o.customProducers[mediaType] = producer