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/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 ServerShutdown: func() {},
37 ServeError: errors.ServeError,
38 BasicAuthenticator: security.BasicAuth,
39 APIKeyAuthenticator: security.APIKeyAuth,
40 BearerAuthenticator: security.BearerAuth,
41 JSONConsumer: runtime.JSONConsumer(),
42 JSONProducer: runtime.JSONProducer(),
43 XMLProducer: runtime.XMLProducer(),
44 CommonSubscribeHandler: common.SubscribeHandlerFunc(func(params common.SubscribeParams) middleware.Responder {
45 return middleware.NotImplemented("operation CommonSubscribe has not yet been implemented")
47 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
48 return middleware.NotImplemented("operation CommonUnsubscribe has not yet been implemented")
50 CommonGetAllSubscriptionsHandler: common.GetAllSubscriptionsHandlerFunc(func(params common.GetAllSubscriptionsParams) middleware.Responder {
51 return middleware.NotImplemented("operation CommonGetAllSubscriptions 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")
59 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
60 type XappFrameworkAPI struct {
62 context *middleware.Context
63 handlers map[string]map[string]http.Handler
64 formats strfmt.Registry
65 customConsumers map[string]runtime.Consumer
66 customProducers map[string]runtime.Producer
67 defaultConsumes string
68 defaultProduces string
69 Middleware func(middleware.Builder) http.Handler
71 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
72 // It has a default implementation in the security package, however you can replace it for your particular usage.
73 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
74 // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
75 // It has a default implementation in the security package, however you can replace it for your particular usage.
76 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
77 // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
78 // It has a default implementation in the security package, however you can replace it for your particular usage.
79 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
81 // JSONConsumer registers a consumer for a "application/json" mime type
82 JSONConsumer runtime.Consumer
84 // JSONProducer registers a producer for a "application/json" mime type
85 JSONProducer runtime.Producer
86 // XMLProducer registers a producer for a "application/xml" mime type
87 XMLProducer runtime.Producer
89 // CommonSubscribeHandler sets the operation handler for the subscribe operation
90 CommonSubscribeHandler common.SubscribeHandler
91 // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation
92 CommonUnsubscribeHandler common.UnsubscribeHandler
93 // CommonGetAllSubscriptionsHandler sets the operation handler for the get all subscriptions operation
94 CommonGetAllSubscriptionsHandler common.GetAllSubscriptionsHandler
95 // XappGetXappConfigListHandler sets the operation handler for the get xapp config list operation
96 XappGetXappConfigListHandler xapp.GetXappConfigListHandler
98 // ServeError is called when an error is received, there is a default handler
99 // but you can set your own with this
100 ServeError func(http.ResponseWriter, *http.Request, error)
102 // ServerShutdown is called when the HTTP(S) server is shut down and done
103 // handling all active connections and does not accept connections any more
104 ServerShutdown func()
106 // Custom command line argument groups with their descriptions
107 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
109 // User defined logger function.
110 Logger func(string, ...interface{})
113 // SetDefaultProduces sets the default produces media type
114 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
115 o.defaultProduces = mediaType
118 // SetDefaultConsumes returns the default consumes media type
119 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
120 o.defaultConsumes = mediaType
123 // SetSpec sets a spec that will be served for the clients.
124 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
128 // DefaultProduces returns the default produces media type
129 func (o *XappFrameworkAPI) DefaultProduces() string {
130 return o.defaultProduces
133 // DefaultConsumes returns the default consumes media type
134 func (o *XappFrameworkAPI) DefaultConsumes() string {
135 return o.defaultConsumes
138 // Formats returns the registered string formats
139 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
143 // RegisterFormat registers a custom format validator
144 func (o *XappFrameworkAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
145 o.formats.Add(name, format, validator)
148 // Validate validates the registrations in the XappFrameworkAPI
149 func (o *XappFrameworkAPI) Validate() error {
150 var unregistered []string
152 if o.JSONConsumer == nil {
153 unregistered = append(unregistered, "JSONConsumer")
156 if o.JSONProducer == nil {
157 unregistered = append(unregistered, "JSONProducer")
160 if o.XMLProducer == nil {
161 unregistered = append(unregistered, "XMLProducer")
164 if o.CommonSubscribeHandler == nil {
165 unregistered = append(unregistered, "common.SubscribeHandler")
168 if o.CommonUnsubscribeHandler == nil {
169 unregistered = append(unregistered, "common.UnsubscribeHandler")
172 if o.CommonGetAllSubscriptionsHandler == nil {
173 unregistered = append(unregistered, "common.GetAllSubscriptionsHandler")
176 if o.XappGetXappConfigListHandler == nil {
177 unregistered = append(unregistered, "xapp.GetXappConfigListHandler")
180 if len(unregistered) > 0 {
181 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
187 // ServeErrorFor gets a error handler for a given operation id
188 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
192 // AuthenticatorsFor gets the authenticators for the specified security schemes
193 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
199 // Authorizer returns the registered authorizer
200 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
206 // ConsumersFor gets the consumers for the specified media types
207 func (o *XappFrameworkAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
209 result := make(map[string]runtime.Consumer)
210 for _, mt := range mediaTypes {
213 case "application/json":
214 result["application/json"] = o.JSONConsumer
218 if c, ok := o.customConsumers[mt]; ok {
226 // ProducersFor gets the producers for the specified media types
227 func (o *XappFrameworkAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
229 result := make(map[string]runtime.Producer)
230 for _, mt := range mediaTypes {
233 case "application/json":
234 result["application/json"] = o.JSONProducer
236 case "application/xml":
237 result["application/xml"] = o.XMLProducer
241 if p, ok := o.customProducers[mt]; ok {
249 // HandlerFor gets a http.Handler for the provided operation method and path
250 func (o *XappFrameworkAPI) HandlerFor(method, path string) (http.Handler, bool) {
251 if o.handlers == nil {
254 um := strings.ToUpper(method)
255 if _, ok := o.handlers[um]; !ok {
261 h, ok := o.handlers[um][path]
265 // Context returns the middleware context for the xapp framework API
266 func (o *XappFrameworkAPI) Context() *middleware.Context {
267 if o.context == nil {
268 o.context = middleware.NewRoutableContext(o.spec, o, nil)
274 func (o *XappFrameworkAPI) initHandlerCache() {
275 o.Context() // don't care about the result, just that the initialization happened
277 if o.handlers == nil {
278 o.handlers = make(map[string]map[string]http.Handler)
281 if o.handlers["POST"] == nil {
282 o.handlers["POST"] = make(map[string]http.Handler)
284 o.handlers["POST"]["/subscriptions"] = common.NewSubscribe(o.context, o.CommonSubscribeHandler)
286 if o.handlers["DELETE"] == nil {
287 o.handlers["DELETE"] = make(map[string]http.Handler)
289 o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler)
291 if o.handlers["GET"] == nil {
292 o.handlers["GET"] = make(map[string]http.Handler)
294 o.handlers["GET"]["/subscriptions"] = common.NewGetAllSubscriptions(o.context, o.CommonGetAllSubscriptionsHandler)
296 if o.handlers["GET"] == nil {
297 o.handlers["GET"] = make(map[string]http.Handler)
299 o.handlers["GET"]["/config"] = xapp.NewGetXappConfigList(o.context, o.XappGetXappConfigListHandler)
303 // Serve creates a http handler to serve the API over HTTP
304 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
305 func (o *XappFrameworkAPI) Serve(builder middleware.Builder) http.Handler {
308 if o.Middleware != nil {
309 return o.Middleware(builder)
311 return o.context.APIHandler(builder)
314 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
315 func (o *XappFrameworkAPI) Init() {
316 if len(o.handlers) == 0 {
321 // RegisterConsumer allows you to add (or override) a consumer for a media type.
322 func (o *XappFrameworkAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
323 o.customConsumers[mediaType] = consumer
326 // RegisterProducer allows you to add (or override) a producer for a media type.
327 func (o *XappFrameworkAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
328 o.customProducers[mediaType] = producer