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/policy"
24 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/query"
25 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/report"
26 "gerrit.o-ran-sc.org/r/ric-plt/xapp-frame/pkg/restapi/operations/xapp"
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 XMLProducer: runtime.XMLProducer(),
47 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
48 return middleware.NotImplemented("operation CommonUnsubscribe has not yet been implemented")
50 QueryGetAllSubscriptionsHandler: query.GetAllSubscriptionsHandlerFunc(func(params query.GetAllSubscriptionsParams) middleware.Responder {
51 return middleware.NotImplemented("operation QueryGetAllSubscriptions has not yet been implemented")
53 XappGetXappConfigListHandler: xapp.GetXappConfigListHandlerFunc(func(params xapp.GetXappConfigListParams) middleware.Responder {
54 return middleware.NotImplemented("operation XappGetXappConfigList has not yet been implemented")
56 PolicySubscribePolicyHandler: policy.SubscribePolicyHandlerFunc(func(params policy.SubscribePolicyParams) middleware.Responder {
57 return middleware.NotImplemented("operation PolicySubscribePolicy has not yet been implemented")
59 ReportSubscribeReportHandler: report.SubscribeReportHandlerFunc(func(params report.SubscribeReportParams) middleware.Responder {
60 return middleware.NotImplemented("operation ReportSubscribeReport has not yet been implemented")
65 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
66 type XappFrameworkAPI struct {
68 context *middleware.Context
69 handlers map[string]map[string]http.Handler
70 formats strfmt.Registry
71 customConsumers map[string]runtime.Consumer
72 customProducers map[string]runtime.Producer
73 defaultConsumes string
74 defaultProduces string
75 Middleware func(middleware.Builder) http.Handler
77 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
78 // It has a default implementation in the security package, however you can replace it for your particular usage.
79 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
80 // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
81 // It has a default implementation in the security package, however you can replace it for your particular usage.
82 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
83 // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
84 // It has a default implementation in the security package, however you can replace it for your particular usage.
85 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
87 // JSONConsumer registers a consumer for a "application/json" mime type
88 JSONConsumer runtime.Consumer
90 // JSONProducer registers a producer for a "application/json" mime type
91 JSONProducer runtime.Producer
92 // XMLProducer registers a producer for a "application/xml" mime type
93 XMLProducer runtime.Producer
95 // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation
96 CommonUnsubscribeHandler common.UnsubscribeHandler
97 // QueryGetAllSubscriptionsHandler sets the operation handler for the get all subscriptions operation
98 QueryGetAllSubscriptionsHandler query.GetAllSubscriptionsHandler
99 // XappGetXappConfigListHandler sets the operation handler for the get xapp config list operation
100 XappGetXappConfigListHandler xapp.GetXappConfigListHandler
101 // PolicySubscribePolicyHandler sets the operation handler for the subscribe policy operation
102 PolicySubscribePolicyHandler policy.SubscribePolicyHandler
103 // ReportSubscribeReportHandler sets the operation handler for the subscribe report operation
104 ReportSubscribeReportHandler report.SubscribeReportHandler
106 // ServeError is called when an error is received, there is a default handler
107 // but you can set your own with this
108 ServeError func(http.ResponseWriter, *http.Request, error)
110 // ServerShutdown is called when the HTTP(S) server is shut down and done
111 // handling all active connections and does not accept connections any more
112 ServerShutdown func()
114 // Custom command line argument groups with their descriptions
115 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
117 // User defined logger function.
118 Logger func(string, ...interface{})
121 // SetDefaultProduces sets the default produces media type
122 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
123 o.defaultProduces = mediaType
126 // SetDefaultConsumes returns the default consumes media type
127 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
128 o.defaultConsumes = mediaType
131 // SetSpec sets a spec that will be served for the clients.
132 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
136 // DefaultProduces returns the default produces media type
137 func (o *XappFrameworkAPI) DefaultProduces() string {
138 return o.defaultProduces
141 // DefaultConsumes returns the default consumes media type
142 func (o *XappFrameworkAPI) DefaultConsumes() string {
143 return o.defaultConsumes
146 // Formats returns the registered string formats
147 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
151 // RegisterFormat registers a custom format validator
152 func (o *XappFrameworkAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
153 o.formats.Add(name, format, validator)
156 // Validate validates the registrations in the XappFrameworkAPI
157 func (o *XappFrameworkAPI) Validate() error {
158 var unregistered []string
160 if o.JSONConsumer == nil {
161 unregistered = append(unregistered, "JSONConsumer")
164 if o.JSONProducer == nil {
165 unregistered = append(unregistered, "JSONProducer")
168 if o.XMLProducer == nil {
169 unregistered = append(unregistered, "XMLProducer")
172 if o.CommonUnsubscribeHandler == nil {
173 unregistered = append(unregistered, "common.UnsubscribeHandler")
176 if o.QueryGetAllSubscriptionsHandler == nil {
177 unregistered = append(unregistered, "query.GetAllSubscriptionsHandler")
180 if o.XappGetXappConfigListHandler == nil {
181 unregistered = append(unregistered, "xapp.GetXappConfigListHandler")
184 if o.PolicySubscribePolicyHandler == nil {
185 unregistered = append(unregistered, "policy.SubscribePolicyHandler")
188 if o.ReportSubscribeReportHandler == nil {
189 unregistered = append(unregistered, "report.SubscribeReportHandler")
192 if len(unregistered) > 0 {
193 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
199 // ServeErrorFor gets a error handler for a given operation id
200 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
204 // AuthenticatorsFor gets the authenticators for the specified security schemes
205 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
211 // Authorizer returns the registered authorizer
212 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
218 // ConsumersFor gets the consumers for the specified media types
219 func (o *XappFrameworkAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
221 result := make(map[string]runtime.Consumer)
222 for _, mt := range mediaTypes {
225 case "application/json":
226 result["application/json"] = o.JSONConsumer
230 if c, ok := o.customConsumers[mt]; ok {
238 // ProducersFor gets the producers for the specified media types
239 func (o *XappFrameworkAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
241 result := make(map[string]runtime.Producer)
242 for _, mt := range mediaTypes {
245 case "application/json":
246 result["application/json"] = o.JSONProducer
248 case "application/xml":
249 result["application/xml"] = o.XMLProducer
253 if p, ok := o.customProducers[mt]; ok {
261 // HandlerFor gets a http.Handler for the provided operation method and path
262 func (o *XappFrameworkAPI) HandlerFor(method, path string) (http.Handler, bool) {
263 if o.handlers == nil {
266 um := strings.ToUpper(method)
267 if _, ok := o.handlers[um]; !ok {
273 h, ok := o.handlers[um][path]
277 // Context returns the middleware context for the xapp framework API
278 func (o *XappFrameworkAPI) Context() *middleware.Context {
279 if o.context == nil {
280 o.context = middleware.NewRoutableContext(o.spec, o, nil)
286 func (o *XappFrameworkAPI) initHandlerCache() {
287 o.Context() // don't care about the result, just that the initialization happened
289 if o.handlers == nil {
290 o.handlers = make(map[string]map[string]http.Handler)
293 if o.handlers["DELETE"] == nil {
294 o.handlers["DELETE"] = make(map[string]http.Handler)
296 o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler)
298 if o.handlers["GET"] == nil {
299 o.handlers["GET"] = make(map[string]http.Handler)
301 o.handlers["GET"]["/subscriptions"] = query.NewGetAllSubscriptions(o.context, o.QueryGetAllSubscriptionsHandler)
303 if o.handlers["GET"] == nil {
304 o.handlers["GET"] = make(map[string]http.Handler)
306 o.handlers["GET"]["/config"] = xapp.NewGetXappConfigList(o.context, o.XappGetXappConfigListHandler)
308 if o.handlers["POST"] == nil {
309 o.handlers["POST"] = make(map[string]http.Handler)
311 o.handlers["POST"]["/subscriptions/policy"] = policy.NewSubscribePolicy(o.context, o.PolicySubscribePolicyHandler)
313 if o.handlers["POST"] == nil {
314 o.handlers["POST"] = make(map[string]http.Handler)
316 o.handlers["POST"]["/subscriptions/report"] = report.NewSubscribeReport(o.context, o.ReportSubscribeReportHandler)
320 // Serve creates a http handler to serve the API over HTTP
321 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
322 func (o *XappFrameworkAPI) Serve(builder middleware.Builder) http.Handler {
325 if o.Middleware != nil {
326 return o.Middleware(builder)
328 return o.context.APIHandler(builder)
331 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
332 func (o *XappFrameworkAPI) Init() {
333 if len(o.handlers) == 0 {
338 // RegisterConsumer allows you to add (or override) a consumer for a media type.
339 func (o *XappFrameworkAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
340 o.customConsumers[mediaType] = consumer
343 // RegisterProducer allows you to add (or override) a producer for a media type.
344 func (o *XappFrameworkAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
345 o.customProducers[mediaType] = producer