17748be9235f42e02c16be99ea16e5fe274c522e
[nonrtric/plt/sme.git] / capifcore / internal / discoverserviceapi / discoverserviceapi-server.gen.go
1 // Package discoverserviceapi provides primitives to interact with the openapi HTTP API.
2 //
3 // Code generated by github.com/deepmap/oapi-codegen version v1.10.1 DO NOT EDIT.
4 package discoverserviceapi
5
6 import (
7         "bytes"
8         "compress/gzip"
9         "encoding/base64"
10         "encoding/json"
11         "fmt"
12         "net/http"
13         "net/url"
14         "path"
15         "strings"
16
17         "github.com/deepmap/oapi-codegen/pkg/runtime"
18         "github.com/getkin/kin-openapi/openapi3"
19         "github.com/labstack/echo/v4"
20         externalRef0 "oransc.org/nonrtric/capifcore/internal/common29122"
21         externalRef1 "oransc.org/nonrtric/capifcore/internal/common29571"
22         externalRef2 "oransc.org/nonrtric/capifcore/internal/publishserviceapi"
23 )
24
25 // ServerInterface represents all server handlers.
26 type ServerInterface interface {
27
28         // (GET /allServiceAPIs)
29         GetAllServiceAPIs(ctx echo.Context, params GetAllServiceAPIsParams) error
30 }
31
32 // ServerInterfaceWrapper converts echo contexts to parameters.
33 type ServerInterfaceWrapper struct {
34         Handler ServerInterface
35 }
36
37 // GetAllServiceAPIs converts echo context to params.
38 func (w *ServerInterfaceWrapper) GetAllServiceAPIs(ctx echo.Context) error {
39         var err error
40
41         // Parameter object where we will unmarshal all parameters from the context
42         var params GetAllServiceAPIsParams
43         // ------------- Required query parameter "api-invoker-id" -------------
44
45         err = runtime.BindQueryParameter("form", true, true, "api-invoker-id", ctx.QueryParams(), &params.ApiInvokerId)
46         if err != nil {
47                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter api-invoker-id: %s", err))
48         }
49
50         // ------------- Optional query parameter "api-name" -------------
51
52         err = runtime.BindQueryParameter("form", true, false, "api-name", ctx.QueryParams(), &params.ApiName)
53         if err != nil {
54                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter api-name: %s", err))
55         }
56
57         // ------------- Optional query parameter "api-version" -------------
58
59         err = runtime.BindQueryParameter("form", true, false, "api-version", ctx.QueryParams(), &params.ApiVersion)
60         if err != nil {
61                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter api-version: %s", err))
62         }
63
64         // ------------- Optional query parameter "comm-type" -------------
65
66         err = runtime.BindQueryParameter("form", true, false, "comm-type", ctx.QueryParams(), &params.CommType)
67         if err != nil {
68                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter comm-type: %s", err))
69         }
70
71         // ------------- Optional query parameter "protocol" -------------
72
73         err = runtime.BindQueryParameter("form", true, false, "protocol", ctx.QueryParams(), &params.Protocol)
74         if err != nil {
75                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter protocol: %s", err))
76         }
77
78         // ------------- Optional query parameter "aef-id" -------------
79
80         err = runtime.BindQueryParameter("form", true, false, "aef-id", ctx.QueryParams(), &params.AefId)
81         if err != nil {
82                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter aef-id: %s", err))
83         }
84
85         // ------------- Optional query parameter "data-format" -------------
86
87         err = runtime.BindQueryParameter("form", true, false, "data-format", ctx.QueryParams(), &params.DataFormat)
88         if err != nil {
89                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter data-format: %s", err))
90         }
91
92         // ------------- Optional query parameter "preferred-aef-loc" -------------
93
94         if paramValue := ctx.QueryParam("preferred-aef-loc"); paramValue != "" {
95
96                 var value externalRef2.AefLocation
97                 err = json.Unmarshal([]byte(paramValue), &value)
98                 if err != nil {
99                         return echo.NewHTTPError(http.StatusBadRequest, "Error unmarshaling parameter 'preferred-aef-loc' as JSON")
100                 }
101                 params.PreferredAefLoc = &value
102
103         }
104
105         // ------------- Optional query parameter "supported-features" -------------
106
107         err = runtime.BindQueryParameter("form", true, false, "supported-features", ctx.QueryParams(), &params.SupportedFeatures)
108         if err != nil {
109                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter supported-features: %s", err))
110         }
111
112         // ------------- Optional query parameter "api-supported-features" -------------
113
114         err = runtime.BindQueryParameter("form", true, false, "api-supported-features", ctx.QueryParams(), &params.ApiSupportedFeatures)
115         if err != nil {
116                 return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter api-supported-features: %s", err))
117         }
118
119         // Invoke the callback with all the unmarshalled arguments
120         err = w.Handler.GetAllServiceAPIs(ctx, params)
121         return err
122 }
123
124 // This is a simple interface which specifies echo.Route addition functions which
125 // are present on both echo.Echo and echo.Group, since we want to allow using
126 // either of them for path registration
127 type EchoRouter interface {
128         CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
129         DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
130         GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
131         HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
132         OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
133         PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
134         POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
135         PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
136         TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
137 }
138
139 // RegisterHandlers adds each server route to the EchoRouter.
140 func RegisterHandlers(router EchoRouter, si ServerInterface) {
141         RegisterHandlersWithBaseURL(router, si, "")
142 }
143
144 // Registers handlers, and prepends BaseURL to the paths, so that the paths
145 // can be served under a prefix.
146 func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string) {
147
148         wrapper := ServerInterfaceWrapper{
149                 Handler: si,
150         }
151
152         router.GET(baseURL+"/allServiceAPIs", wrapper.GetAllServiceAPIs)
153
154 }
155
156 // Base64 encoded, gzipped, json marshaled Swagger object
157 var swaggerSpec = []string{
158
159         "H4sIAAAAAAAC/7xX224bNxD9lQHbhwSQdq31LdabasuBisJRLaUvTWBQ3FmJCZfckFw5qqEP6m/0y4oh",
160         "Vxc7kgtHQV9iZz08c2bOzHD4wIQpK6NRe8e6D8yJGZY8/HolnTBztJj3hoPwJUcnrKy8NJp12S1WFh0d",
161         "BA5KOg+mADIFUVuL2qsFWJxK5wkDpAY/Q7jsDQfXIIxFKGotCAu4zsFxL12xkHoKHHRdTtASXiGVRwvC",
162         "So9Wcqismcscc5gsAlxvOABhtKtLtMkHzVqssqZC6yXGeNDOpcDecHC1Ib8jmK2/kluCbo4GF9xBVU+U",
163         "dLON6+bvCfS5mD2y3oIGN+NKgdRC1TlCr39NIRRSoYOSezGjgAntSaAxFumxDGR/tliwLhuPsossy+5C",
164         "Eu+GkdHdKLq+6w0HyYKX6qd0o2naCJqOdiWCLVuslHoQ3XRazC8qZF3GreULtlyuP5jJJxSeLekTfvVo",
165         "NVdXRuxI5PHb4RDGI8gukizL4I/OeXKWHMGlKUujQ3auLS/x3tjPUBgLwf7GWD+bmFrnoYBYi9VWsS6b",
166         "eV+5bpre398nx9OqSoydpoWv0lGFwqXcipmcY5pd3Dm0El0avaYUl9SF+ZYeESC3eVPclP4t6VwC8EH/",
167         "8zdkR1nWiuTe2SnX8i9OCFzBkFuv0Tp41bsd/NKC3ngwasHl5ajXgv54NGjBeHQVfox79M/l64DZUwqs",
168         "nM68A+oaO8c8auylV5TiqOmq6bZFZS02R+tiAJ0kSzoUn6lQ80pSypOj5Igqn/tZUCTlSm30Dp+m6HcU",
169         "feNsq7a3cxH60qK3EucIHIRRCsWqRaKFEMbmoYYNCLSeS727lKkpQwoHOeuyt+h7jzkSfSoMj9ax7p9P",
170         "qY58kErmqL2MY2LV/lLPzWe0wJ2TU73pzx2TJoGBB66cAbsZXsH28nqFLdE+mlXts/QMQWqPtuACm8Yk",
171         "Tl9qtAvWYpqXoWkq2W64tGXOWszil1pazFnX2xpbzWwlGZquciEo6rNdZUqwLZAepAOHnmbQA6/kDS9x",
172         "CRW3fjWo3t8OwHlbC19bJLMcC6njyBWK1w7hNMmSE7Lfas9Olj0fTPj1xbRL/slYaAp2ze8VJtME5p3X",
173         "yTMOV1X+Ip80WWotRSguIHOo3eMLIjq/7f/+vj8a3932R8N3N6P+XirClGU7+N0mcvgIfsR0TPg7whla",
174         "440w6mkQ+8hWjf0P5rqisVPl/rpZ0O7VE4vYBS+Q8op7TtO55N7tEZHmPFfNNIZV8PDr6N1NOLFX1Jx7",
175         "3o7Y/0VKGO1Rh3nJq0o1gqWfHJF8+KFp7mHxm4n48XJ9nJDxDKGyWKClDYryrhrr/eXQWLdJAGUE+zbN",
176         "18hpUjhwdVUZ6zd5vrleL1PhltyM0fVVMdpcEPs4rGHbReNpX3Gennfu4mZA0j+zvKwQV9R3Vc/+sPL1",
177         "JvtoTZM6J22j3WrgwfoaSmA8k7SlLcBotYBJ0ILuDJDFxj4EvzlF07oxe366/j9Z+kjXkKuMdnEfzo6O",
178         "6MdLS3ynvycPhD31u3IPE5MvqLxoR4i3rkVXK7/Zt2mfg1Bl9P/Vk2LrDRE2tA9hbT0+On+Spg614DNp",
179         "WuchpbMB4s0BEG8I4iSm87sg6GyA6BwA0YkQxwdAHEeIkwMgTiLE2QEQZwGicwCLTmSRXXw/RHZBEKcH",
180         "iHoaRT09QJHTqEiOBa+V/26Y1fnlMjRmeHI0q3V8XNEyeWuMX6bNUGzzSrp03qH3BreST1ScGY1dfD80",
181         "pNZPM/zKy0phIkzJnrZ/c3D3SnqenD5ZSLMsS4jux+W/AQAA//8zY8i1lhAAAA==",
182 }
183
184 // GetSwagger returns the content of the embedded swagger specification file
185 // or error if failed to decode
186 func decodeSpec() ([]byte, error) {
187         zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
188         if err != nil {
189                 return nil, fmt.Errorf("error base64 decoding spec: %s", err)
190         }
191         zr, err := gzip.NewReader(bytes.NewReader(zipped))
192         if err != nil {
193                 return nil, fmt.Errorf("error decompressing spec: %s", err)
194         }
195         var buf bytes.Buffer
196         _, err = buf.ReadFrom(zr)
197         if err != nil {
198                 return nil, fmt.Errorf("error decompressing spec: %s", err)
199         }
200
201         return buf.Bytes(), nil
202 }
203
204 var rawSpec = decodeSpecCached()
205
206 // a naive cached of a decoded swagger spec
207 func decodeSpecCached() func() ([]byte, error) {
208         data, err := decodeSpec()
209         return func() ([]byte, error) {
210                 return data, err
211         }
212 }
213
214 // Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
215 func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
216         var res = make(map[string]func() ([]byte, error))
217         if len(pathToFile) > 0 {
218                 res[pathToFile] = rawSpec
219         }
220
221         pathPrefix := path.Dir(pathToFile)
222
223         for rawPath, rawFunc := range externalRef0.PathToRawSpec(path.Join(pathPrefix, "TS29122_CommonData.yaml")) {
224                 if _, ok := res[rawPath]; ok {
225                         // it is not possible to compare functions in golang, so always overwrite the old value
226                 }
227                 res[rawPath] = rawFunc
228         }
229         for rawPath, rawFunc := range externalRef2.PathToRawSpec(path.Join(pathPrefix, "TS29222_CAPIF_Publish_Service_API.yaml")) {
230                 if _, ok := res[rawPath]; ok {
231                         // it is not possible to compare functions in golang, so always overwrite the old value
232                 }
233                 res[rawPath] = rawFunc
234         }
235         for rawPath, rawFunc := range externalRef1.PathToRawSpec(path.Join(pathPrefix, "TS29571_CommonData.yaml")) {
236                 if _, ok := res[rawPath]; ok {
237                         // it is not possible to compare functions in golang, so always overwrite the old value
238                 }
239                 res[rawPath] = rawFunc
240         }
241         return res
242 }
243
244 // GetSwagger returns the Swagger specification corresponding to the generated code
245 // in this file. The external references of Swagger specification are resolved.
246 // The logic of resolving external references is tightly connected to "import-mapping" feature.
247 // Externally referenced files must be embedded in the corresponding golang packages.
248 // Urls can be supported but this task was out of the scope.
249 func GetSwagger() (swagger *openapi3.T, err error) {
250         var resolvePath = PathToRawSpec("")
251
252         loader := openapi3.NewLoader()
253         loader.IsExternalRefsAllowed = true
254         loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
255                 var pathToFile = url.String()
256                 pathToFile = path.Clean(pathToFile)
257                 getSpec, ok := resolvePath[pathToFile]
258                 if !ok {
259                         err1 := fmt.Errorf("path not found: %s", pathToFile)
260                         return nil, err1
261                 }
262                 return getSpec()
263         }
264         var specData []byte
265         specData, err = rawSpec()
266         if err != nil {
267                 return
268         }
269         swagger, err = loader.LoadFromData(specData)
270         if err != nil {
271                 return
272         }
273         return
274 }