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/report"
28 // NewXappFrameworkAPI creates a new XappFramework instance
29 func NewXappFrameworkAPI(spec *loads.Document) *XappFrameworkAPI {
30 return &XappFrameworkAPI{
31 handlers: make(map[string]map[string]http.Handler),
32 formats: strfmt.Default,
33 defaultConsumes: "application/json",
34 defaultProduces: "application/json",
35 customConsumers: make(map[string]runtime.Consumer),
36 customProducers: make(map[string]runtime.Producer),
37 ServerShutdown: func() {},
39 ServeError: errors.ServeError,
40 BasicAuthenticator: security.BasicAuth,
41 APIKeyAuthenticator: security.APIKeyAuth,
42 BearerAuthenticator: security.BearerAuth,
43 JSONConsumer: runtime.JSONConsumer(),
44 JSONProducer: runtime.JSONProducer(),
45 CommonUnsubscribeHandler: common.UnsubscribeHandlerFunc(func(params common.UnsubscribeParams) middleware.Responder {
46 return middleware.NotImplemented("operation CommonUnsubscribe has not yet been implemented")
48 ControlSubscribeControlHandler: control.SubscribeControlHandlerFunc(func(params control.SubscribeControlParams) middleware.Responder {
49 return middleware.NotImplemented("operation ControlSubscribeControl has not yet been implemented")
51 PolicySubscribePolicyHandler: policy.SubscribePolicyHandlerFunc(func(params policy.SubscribePolicyParams) middleware.Responder {
52 return middleware.NotImplemented("operation PolicySubscribePolicy has not yet been implemented")
54 ReportSubscribeReportHandler: report.SubscribeReportHandlerFunc(func(params report.SubscribeReportParams) middleware.Responder {
55 return middleware.NotImplemented("operation ReportSubscribeReport has not yet been implemented")
60 /*XappFrameworkAPI This is the initial REST API for RIC subscription */
61 type XappFrameworkAPI struct {
63 context *middleware.Context
64 handlers map[string]map[string]http.Handler
65 formats strfmt.Registry
66 customConsumers map[string]runtime.Consumer
67 customProducers map[string]runtime.Producer
68 defaultConsumes string
69 defaultProduces string
70 Middleware func(middleware.Builder) http.Handler
72 // BasicAuthenticator generates a runtime.Authenticator from the supplied basic auth function.
73 // It has a default implementation in the security package, however you can replace it for your particular usage.
74 BasicAuthenticator func(security.UserPassAuthentication) runtime.Authenticator
75 // APIKeyAuthenticator generates a runtime.Authenticator from the supplied token auth function.
76 // It has a default implementation in the security package, however you can replace it for your particular usage.
77 APIKeyAuthenticator func(string, string, security.TokenAuthentication) runtime.Authenticator
78 // BearerAuthenticator generates a runtime.Authenticator from the supplied bearer token auth function.
79 // It has a default implementation in the security package, however you can replace it for your particular usage.
80 BearerAuthenticator func(string, security.ScopedTokenAuthentication) runtime.Authenticator
82 // JSONConsumer registers a consumer for a "application/json" mime type
83 JSONConsumer runtime.Consumer
85 // JSONProducer registers a producer for a "application/json" mime type
86 JSONProducer runtime.Producer
88 // CommonUnsubscribeHandler sets the operation handler for the unsubscribe operation
89 CommonUnsubscribeHandler common.UnsubscribeHandler
90 // ControlSubscribeControlHandler sets the operation handler for the subscribe control operation
91 ControlSubscribeControlHandler control.SubscribeControlHandler
92 // PolicySubscribePolicyHandler sets the operation handler for the subscribe policy operation
93 PolicySubscribePolicyHandler policy.SubscribePolicyHandler
94 // ReportSubscribeReportHandler sets the operation handler for the subscribe report operation
95 ReportSubscribeReportHandler report.SubscribeReportHandler
97 // ServeError is called when an error is received, there is a default handler
98 // but you can set your own with this
99 ServeError func(http.ResponseWriter, *http.Request, error)
101 // ServerShutdown is called when the HTTP(S) server is shut down and done
102 // handling all active connections and does not accept connections any more
103 ServerShutdown func()
105 // Custom command line argument groups with their descriptions
106 CommandLineOptionsGroups []swag.CommandLineOptionsGroup
108 // User defined logger function.
109 Logger func(string, ...interface{})
112 // SetDefaultProduces sets the default produces media type
113 func (o *XappFrameworkAPI) SetDefaultProduces(mediaType string) {
114 o.defaultProduces = mediaType
117 // SetDefaultConsumes returns the default consumes media type
118 func (o *XappFrameworkAPI) SetDefaultConsumes(mediaType string) {
119 o.defaultConsumes = mediaType
122 // SetSpec sets a spec that will be served for the clients.
123 func (o *XappFrameworkAPI) SetSpec(spec *loads.Document) {
127 // DefaultProduces returns the default produces media type
128 func (o *XappFrameworkAPI) DefaultProduces() string {
129 return o.defaultProduces
132 // DefaultConsumes returns the default consumes media type
133 func (o *XappFrameworkAPI) DefaultConsumes() string {
134 return o.defaultConsumes
137 // Formats returns the registered string formats
138 func (o *XappFrameworkAPI) Formats() strfmt.Registry {
142 // RegisterFormat registers a custom format validator
143 func (o *XappFrameworkAPI) RegisterFormat(name string, format strfmt.Format, validator strfmt.Validator) {
144 o.formats.Add(name, format, validator)
147 // Validate validates the registrations in the XappFrameworkAPI
148 func (o *XappFrameworkAPI) Validate() error {
149 var unregistered []string
151 if o.JSONConsumer == nil {
152 unregistered = append(unregistered, "JSONConsumer")
155 if o.JSONProducer == nil {
156 unregistered = append(unregistered, "JSONProducer")
159 if o.CommonUnsubscribeHandler == nil {
160 unregistered = append(unregistered, "common.UnsubscribeHandler")
163 if o.ControlSubscribeControlHandler == nil {
164 unregistered = append(unregistered, "control.SubscribeControlHandler")
167 if o.PolicySubscribePolicyHandler == nil {
168 unregistered = append(unregistered, "policy.SubscribePolicyHandler")
171 if o.ReportSubscribeReportHandler == nil {
172 unregistered = append(unregistered, "report.SubscribeReportHandler")
175 if len(unregistered) > 0 {
176 return fmt.Errorf("missing registration: %s", strings.Join(unregistered, ", "))
182 // ServeErrorFor gets a error handler for a given operation id
183 func (o *XappFrameworkAPI) ServeErrorFor(operationID string) func(http.ResponseWriter, *http.Request, error) {
187 // AuthenticatorsFor gets the authenticators for the specified security schemes
188 func (o *XappFrameworkAPI) AuthenticatorsFor(schemes map[string]spec.SecurityScheme) map[string]runtime.Authenticator {
194 // Authorizer returns the registered authorizer
195 func (o *XappFrameworkAPI) Authorizer() runtime.Authorizer {
201 // ConsumersFor gets the consumers for the specified media types
202 func (o *XappFrameworkAPI) ConsumersFor(mediaTypes []string) map[string]runtime.Consumer {
204 result := make(map[string]runtime.Consumer)
205 for _, mt := range mediaTypes {
208 case "application/json":
209 result["application/json"] = o.JSONConsumer
213 if c, ok := o.customConsumers[mt]; ok {
221 // ProducersFor gets the producers for the specified media types
222 func (o *XappFrameworkAPI) ProducersFor(mediaTypes []string) map[string]runtime.Producer {
224 result := make(map[string]runtime.Producer)
225 for _, mt := range mediaTypes {
228 case "application/json":
229 result["application/json"] = o.JSONProducer
233 if p, ok := o.customProducers[mt]; ok {
241 // HandlerFor gets a http.Handler for the provided operation method and path
242 func (o *XappFrameworkAPI) HandlerFor(method, path string) (http.Handler, bool) {
243 if o.handlers == nil {
246 um := strings.ToUpper(method)
247 if _, ok := o.handlers[um]; !ok {
253 h, ok := o.handlers[um][path]
257 // Context returns the middleware context for the xapp framework API
258 func (o *XappFrameworkAPI) Context() *middleware.Context {
259 if o.context == nil {
260 o.context = middleware.NewRoutableContext(o.spec, o, nil)
266 func (o *XappFrameworkAPI) initHandlerCache() {
267 o.Context() // don't care about the result, just that the initialization happened
269 if o.handlers == nil {
270 o.handlers = make(map[string]map[string]http.Handler)
273 if o.handlers["DELETE"] == nil {
274 o.handlers["DELETE"] = make(map[string]http.Handler)
276 o.handlers["DELETE"]["/subscriptions/{subscriptionId}"] = common.NewUnsubscribe(o.context, o.CommonUnsubscribeHandler)
278 if o.handlers["POST"] == nil {
279 o.handlers["POST"] = make(map[string]http.Handler)
281 o.handlers["POST"]["/subscriptions/control"] = control.NewSubscribeControl(o.context, o.ControlSubscribeControlHandler)
283 if o.handlers["POST"] == nil {
284 o.handlers["POST"] = make(map[string]http.Handler)
286 o.handlers["POST"]["/subscriptions/policy"] = policy.NewSubscribePolicy(o.context, o.PolicySubscribePolicyHandler)
288 if o.handlers["POST"] == nil {
289 o.handlers["POST"] = make(map[string]http.Handler)
291 o.handlers["POST"]["/subscriptions/report"] = report.NewSubscribeReport(o.context, o.ReportSubscribeReportHandler)
295 // Serve creates a http handler to serve the API over HTTP
296 // can be used directly in http.ListenAndServe(":8000", api.Serve(nil))
297 func (o *XappFrameworkAPI) Serve(builder middleware.Builder) http.Handler {
300 if o.Middleware != nil {
301 return o.Middleware(builder)
303 return o.context.APIHandler(builder)
306 // Init allows you to just initialize the handler cache, you can then recompose the middleware as you see fit
307 func (o *XappFrameworkAPI) Init() {
308 if len(o.handlers) == 0 {
313 // RegisterConsumer allows you to add (or override) a consumer for a media type.
314 func (o *XappFrameworkAPI) RegisterConsumer(mediaType string, consumer runtime.Consumer) {
315 o.customConsumers[mediaType] = consumer
318 // RegisterProducer allows you to add (or override) a producer for a media type.
319 func (o *XappFrameworkAPI) RegisterProducer(mediaType string, producer runtime.Producer) {
320 o.customProducers[mediaType] = producer