mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
1040 lines
34 KiB
Go
1040 lines
34 KiB
Go
// Package api provides primitives to interact with the openapi HTTP API.
|
|
//
|
|
// Code generated by github.com/deepmap/oapi-codegen version v1.12.5-0.20230314231417-0cfaaa77a7d2 DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"context"
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/deepmap/oapi-codegen/pkg/runtime"
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/go-chi/chi/v5"
|
|
)
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
// Retrieve a list of artists
|
|
// (GET /artists)
|
|
GetArtists(w http.ResponseWriter, r *http.Request, params GetArtistsParams)
|
|
// Retrieve an individual artist
|
|
// (GET /artists/{artistId})
|
|
GetArtist(w http.ResponseWriter, r *http.Request, artistId string, params GetArtistParams)
|
|
// Get server's global info
|
|
// (GET /server)
|
|
GetServerInfo(w http.ResponseWriter, r *http.Request)
|
|
// Get a list of tracks
|
|
// (GET /tracks)
|
|
GetTracks(w http.ResponseWriter, r *http.Request, params GetTracksParams)
|
|
// Retrieve an individual track
|
|
// (GET /tracks/{trackId})
|
|
GetTrack(w http.ResponseWriter, r *http.Request, trackId string, params GetTrackParams)
|
|
}
|
|
|
|
// ServerInterfaceWrapper converts contexts to parameters.
|
|
type ServerInterfaceWrapper struct {
|
|
Handler ServerInterface
|
|
HandlerMiddlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
type MiddlewareFunc func(http.Handler) http.Handler
|
|
|
|
// GetArtists operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetArtists(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetArtistsParams
|
|
|
|
// ------------- Optional query parameter "page[limit]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "page[limit]", r.URL.Query(), ¶ms.PageLimit)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "page[limit]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "page[offset]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "page[offset]", r.URL.Query(), ¶ms.PageOffset)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "page[offset]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[equals]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[equals]", r.URL.Query(), ¶ms.FilterEquals)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[equals]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[contains]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[contains]", r.URL.Query(), ¶ms.FilterContains)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[contains]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[lessThan]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[lessThan]", r.URL.Query(), ¶ms.FilterLessThan)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[lessThan]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[lessOrEqual]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[lessOrEqual]", r.URL.Query(), ¶ms.FilterLessOrEqual)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[lessOrEqual]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[greaterThan]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[greaterThan]", r.URL.Query(), ¶ms.FilterGreaterThan)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[greaterThan]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[greaterOrEqual]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[greaterOrEqual]", r.URL.Query(), ¶ms.FilterGreaterOrEqual)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[greaterOrEqual]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[startsWith]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[startsWith]", r.URL.Query(), ¶ms.FilterStartsWith)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[startsWith]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[endsWith]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[endsWith]", r.URL.Query(), ¶ms.FilterEndsWith)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[endsWith]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "sort" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "sort", r.URL.Query(), ¶ms.Sort)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sort", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "include" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "include", r.URL.Query(), ¶ms.Include)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "include", Err: err})
|
|
return
|
|
}
|
|
|
|
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetArtists(w, r, params)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetArtist operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetArtist(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// ------------- Path parameter "artistId" -------------
|
|
var artistId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "artistId", runtime.ParamLocationPath, chi.URLParam(r, "artistId"), &artistId)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "artistId", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetArtistParams
|
|
|
|
// ------------- Optional query parameter "include" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "include", r.URL.Query(), ¶ms.Include)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "include", Err: err})
|
|
return
|
|
}
|
|
|
|
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetArtist(w, r, artistId, params)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetServerInfo operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetServerInfo(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetServerInfo(w, r)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetTracks operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetTracks(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetTracksParams
|
|
|
|
// ------------- Optional query parameter "page[limit]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "page[limit]", r.URL.Query(), ¶ms.PageLimit)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "page[limit]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "page[offset]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "page[offset]", r.URL.Query(), ¶ms.PageOffset)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "page[offset]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[equals]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[equals]", r.URL.Query(), ¶ms.FilterEquals)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[equals]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[contains]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[contains]", r.URL.Query(), ¶ms.FilterContains)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[contains]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[lessThan]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[lessThan]", r.URL.Query(), ¶ms.FilterLessThan)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[lessThan]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[lessOrEqual]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[lessOrEqual]", r.URL.Query(), ¶ms.FilterLessOrEqual)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[lessOrEqual]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[greaterThan]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[greaterThan]", r.URL.Query(), ¶ms.FilterGreaterThan)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[greaterThan]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[greaterOrEqual]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[greaterOrEqual]", r.URL.Query(), ¶ms.FilterGreaterOrEqual)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[greaterOrEqual]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[startsWith]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[startsWith]", r.URL.Query(), ¶ms.FilterStartsWith)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[startsWith]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "filter[endsWith]" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "filter[endsWith]", r.URL.Query(), ¶ms.FilterEndsWith)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "filter[endsWith]", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "sort" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "sort", r.URL.Query(), ¶ms.Sort)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "sort", Err: err})
|
|
return
|
|
}
|
|
|
|
// ------------- Optional query parameter "include" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "include", r.URL.Query(), ¶ms.Include)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "include", Err: err})
|
|
return
|
|
}
|
|
|
|
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetTracks(w, r, params)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetTrack operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetTrack(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// ------------- Path parameter "trackId" -------------
|
|
var trackId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "trackId", runtime.ParamLocationPath, chi.URLParam(r, "trackId"), &trackId)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "trackId", Err: err})
|
|
return
|
|
}
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetTrackParams
|
|
|
|
// ------------- Optional query parameter "include" -------------
|
|
|
|
err = runtime.BindQueryParameter("form", true, false, "include", r.URL.Query(), ¶ms.Include)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "include", Err: err})
|
|
return
|
|
}
|
|
|
|
var handler http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.GetTrack(w, r, trackId, params)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
type UnescapedCookieParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Error() string {
|
|
return fmt.Sprintf("error unescaping cookie parameter '%s'", e.ParamName)
|
|
}
|
|
|
|
func (e *UnescapedCookieParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type UnmarshallingParamError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *UnmarshallingParamError) Error() string {
|
|
return fmt.Sprintf("Error unmarshalling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *UnmarshallingParamError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type RequiredParamError struct {
|
|
ParamName string
|
|
}
|
|
|
|
func (e *RequiredParamError) Error() string {
|
|
return fmt.Sprintf("Query argument %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
type RequiredHeaderError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Error() string {
|
|
return fmt.Sprintf("Header parameter %s is required, but not found", e.ParamName)
|
|
}
|
|
|
|
func (e *RequiredHeaderError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type InvalidParamFormatError struct {
|
|
ParamName string
|
|
Err error
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Error() string {
|
|
return fmt.Sprintf("Invalid format for parameter %s: %s", e.ParamName, e.Err.Error())
|
|
}
|
|
|
|
func (e *InvalidParamFormatError) Unwrap() error {
|
|
return e.Err
|
|
}
|
|
|
|
type TooManyValuesForParamError struct {
|
|
ParamName string
|
|
Count int
|
|
}
|
|
|
|
func (e *TooManyValuesForParamError) Error() string {
|
|
return fmt.Sprintf("Expected one value for %s, got %d", e.ParamName, e.Count)
|
|
}
|
|
|
|
// Handler creates http.Handler with routing matching OpenAPI spec.
|
|
func Handler(si ServerInterface) http.Handler {
|
|
return HandlerWithOptions(si, ChiServerOptions{})
|
|
}
|
|
|
|
type ChiServerOptions struct {
|
|
BaseURL string
|
|
BaseRouter chi.Router
|
|
Middlewares []MiddlewareFunc
|
|
ErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
// HandlerFromMux creates http.Handler with routing matching OpenAPI spec based on the provided mux.
|
|
func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
|
|
return HandlerWithOptions(si, ChiServerOptions{
|
|
BaseRouter: r,
|
|
})
|
|
}
|
|
|
|
func HandlerFromMuxWithBaseURL(si ServerInterface, r chi.Router, baseURL string) http.Handler {
|
|
return HandlerWithOptions(si, ChiServerOptions{
|
|
BaseURL: baseURL,
|
|
BaseRouter: r,
|
|
})
|
|
}
|
|
|
|
// HandlerWithOptions creates http.Handler with additional options
|
|
func HandlerWithOptions(si ServerInterface, options ChiServerOptions) http.Handler {
|
|
r := options.BaseRouter
|
|
|
|
if r == nil {
|
|
r = chi.NewRouter()
|
|
}
|
|
if options.ErrorHandlerFunc == nil {
|
|
options.ErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
}
|
|
wrapper := ServerInterfaceWrapper{
|
|
Handler: si,
|
|
HandlerMiddlewares: options.Middlewares,
|
|
ErrorHandlerFunc: options.ErrorHandlerFunc,
|
|
}
|
|
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/artists", wrapper.GetArtists)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/artists/{artistId}", wrapper.GetArtist)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/server", wrapper.GetServerInfo)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/tracks", wrapper.GetTracks)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/tracks/{trackId}", wrapper.GetTrack)
|
|
})
|
|
|
|
return r
|
|
}
|
|
|
|
type BadRequestJSONResponse ErrorList
|
|
|
|
type InternalServerErrorJSONResponse ErrorList
|
|
|
|
type NotAuthorizedJSONResponse ErrorList
|
|
|
|
type NotFoundJSONResponse ErrorList
|
|
|
|
type GetArtistsRequestObject struct {
|
|
Params GetArtistsParams
|
|
}
|
|
|
|
type GetArtistsResponseObject interface {
|
|
VisitGetArtistsResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetArtists200JSONResponse struct {
|
|
Data []Artist `json:"data"`
|
|
Links PaginationLinks `json:"links"`
|
|
Meta *PaginationMeta `json:"meta,omitempty"`
|
|
}
|
|
|
|
func (response GetArtists200JSONResponse) VisitGetArtistsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtists400JSONResponse struct{ BadRequestJSONResponse }
|
|
|
|
func (response GetArtists400JSONResponse) VisitGetArtistsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(400)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtists403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetArtists403JSONResponse) VisitGetArtistsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtists500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetArtists500JSONResponse) VisitGetArtistsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtistRequestObject struct {
|
|
ArtistId string `json:"artistId"`
|
|
Params GetArtistParams
|
|
}
|
|
|
|
type GetArtistResponseObject interface {
|
|
VisitGetArtistResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetArtist200JSONResponse struct {
|
|
Data Artist `json:"data"`
|
|
}
|
|
|
|
func (response GetArtist200JSONResponse) VisitGetArtistResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtist403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetArtist403JSONResponse) VisitGetArtistResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtist404JSONResponse struct{ NotFoundJSONResponse }
|
|
|
|
func (response GetArtist404JSONResponse) VisitGetArtistResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(404)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetArtist500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetArtist500JSONResponse) VisitGetArtistResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetServerInfoRequestObject struct {
|
|
}
|
|
|
|
type GetServerInfoResponseObject interface {
|
|
VisitGetServerInfoResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetServerInfo200JSONResponse struct {
|
|
Data ServerInfo `json:"data"`
|
|
}
|
|
|
|
func (response GetServerInfo200JSONResponse) VisitGetServerInfoResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetServerInfo403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetServerInfo403JSONResponse) VisitGetServerInfoResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetServerInfo500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetServerInfo500JSONResponse) VisitGetServerInfoResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTracksRequestObject struct {
|
|
Params GetTracksParams
|
|
}
|
|
|
|
type GetTracksResponseObject interface {
|
|
VisitGetTracksResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetTracks200JSONResponse struct {
|
|
Data []Track `json:"data"`
|
|
Links PaginationLinks `json:"links"`
|
|
Meta *PaginationMeta `json:"meta,omitempty"`
|
|
}
|
|
|
|
func (response GetTracks200JSONResponse) VisitGetTracksResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTracks400JSONResponse struct{ BadRequestJSONResponse }
|
|
|
|
func (response GetTracks400JSONResponse) VisitGetTracksResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(400)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTracks403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetTracks403JSONResponse) VisitGetTracksResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTracks500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetTracks500JSONResponse) VisitGetTracksResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTrackRequestObject struct {
|
|
TrackId string `json:"trackId"`
|
|
Params GetTrackParams
|
|
}
|
|
|
|
type GetTrackResponseObject interface {
|
|
VisitGetTrackResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetTrack200JSONResponse struct {
|
|
Data Track `json:"data"`
|
|
}
|
|
|
|
func (response GetTrack200JSONResponse) VisitGetTrackResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTrack403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetTrack403JSONResponse) VisitGetTrackResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTrack404JSONResponse struct{ NotFoundJSONResponse }
|
|
|
|
func (response GetTrack404JSONResponse) VisitGetTrackResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(404)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetTrack500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetTrack500JSONResponse) VisitGetTrackResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
// StrictServerInterface represents all server handlers.
|
|
type StrictServerInterface interface {
|
|
// Retrieve a list of artists
|
|
// (GET /artists)
|
|
GetArtists(ctx context.Context, request GetArtistsRequestObject) (GetArtistsResponseObject, error)
|
|
// Retrieve an individual artist
|
|
// (GET /artists/{artistId})
|
|
GetArtist(ctx context.Context, request GetArtistRequestObject) (GetArtistResponseObject, error)
|
|
// Get server's global info
|
|
// (GET /server)
|
|
GetServerInfo(ctx context.Context, request GetServerInfoRequestObject) (GetServerInfoResponseObject, error)
|
|
// Get a list of tracks
|
|
// (GET /tracks)
|
|
GetTracks(ctx context.Context, request GetTracksRequestObject) (GetTracksResponseObject, error)
|
|
// Retrieve an individual track
|
|
// (GET /tracks/{trackId})
|
|
GetTrack(ctx context.Context, request GetTrackRequestObject) (GetTrackResponseObject, error)
|
|
}
|
|
|
|
type StrictHandlerFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, args interface{}) (interface{}, error)
|
|
|
|
type StrictMiddlewareFunc func(f StrictHandlerFunc, operationID string) StrictHandlerFunc
|
|
|
|
type StrictHTTPServerOptions struct {
|
|
RequestErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
ResponseErrorHandlerFunc func(w http.ResponseWriter, r *http.Request, err error)
|
|
}
|
|
|
|
func NewStrictHandler(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc) ServerInterface {
|
|
return &strictHandler{ssi: ssi, middlewares: middlewares, options: StrictHTTPServerOptions{
|
|
RequestErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
},
|
|
ResponseErrorHandlerFunc: func(w http.ResponseWriter, r *http.Request, err error) {
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
},
|
|
}}
|
|
}
|
|
|
|
func NewStrictHandlerWithOptions(ssi StrictServerInterface, middlewares []StrictMiddlewareFunc, options StrictHTTPServerOptions) ServerInterface {
|
|
return &strictHandler{ssi: ssi, middlewares: middlewares, options: options}
|
|
}
|
|
|
|
type strictHandler struct {
|
|
ssi StrictServerInterface
|
|
middlewares []StrictMiddlewareFunc
|
|
options StrictHTTPServerOptions
|
|
}
|
|
|
|
// GetArtists operation middleware
|
|
func (sh *strictHandler) GetArtists(w http.ResponseWriter, r *http.Request, params GetArtistsParams) {
|
|
var request GetArtistsRequestObject
|
|
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetArtists(ctx, request.(GetArtistsRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetArtists")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetArtistsResponseObject); ok {
|
|
if err := validResponse.VisitGetArtistsResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("Unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetArtist operation middleware
|
|
func (sh *strictHandler) GetArtist(w http.ResponseWriter, r *http.Request, artistId string, params GetArtistParams) {
|
|
var request GetArtistRequestObject
|
|
|
|
request.ArtistId = artistId
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetArtist(ctx, request.(GetArtistRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetArtist")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetArtistResponseObject); ok {
|
|
if err := validResponse.VisitGetArtistResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("Unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetServerInfo operation middleware
|
|
func (sh *strictHandler) GetServerInfo(w http.ResponseWriter, r *http.Request) {
|
|
var request GetServerInfoRequestObject
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetServerInfo(ctx, request.(GetServerInfoRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetServerInfo")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetServerInfoResponseObject); ok {
|
|
if err := validResponse.VisitGetServerInfoResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("Unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetTracks operation middleware
|
|
func (sh *strictHandler) GetTracks(w http.ResponseWriter, r *http.Request, params GetTracksParams) {
|
|
var request GetTracksRequestObject
|
|
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetTracks(ctx, request.(GetTracksRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetTracks")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetTracksResponseObject); ok {
|
|
if err := validResponse.VisitGetTracksResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("Unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// GetTrack operation middleware
|
|
func (sh *strictHandler) GetTrack(w http.ResponseWriter, r *http.Request, trackId string, params GetTrackParams) {
|
|
var request GetTrackRequestObject
|
|
|
|
request.TrackId = trackId
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetTrack(ctx, request.(GetTrackRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetTrack")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetTrackResponseObject); ok {
|
|
if err := validResponse.VisitGetTrackResponse(w); err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
}
|
|
} else if response != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, fmt.Errorf("Unexpected response type: %T", response))
|
|
}
|
|
}
|
|
|
|
// Base64 encoded, gzipped, json marshaled Swagger object
|
|
var swaggerSpec = []string{
|
|
|
|
"H4sIAAAAAAAC/+xZX4/buBH/KgRbIA+n2m6S9sFAH/YOd8EWaRJsts1DsgXG0tjiHUVqScq77sJAv0a/",
|
|
"Xj9JwSEly5a0lp1uggvuJVmLnP/DmR+HDzzVRakVKmf5/IGXYKBAh4Z+LYV0aH7QyoFQ9CVDmxpROqEV",
|
|
"n/OfaJ0tNgzUhpVGl2jchqWBQKgVc3jvJuzvFlY4Z4Hdx7hsb/5SU8zXICvkCRee622FZsMTrqBAPueH",
|
|
"VDzhNs2xAK+PcFhExZ1D48n/+enT3Xdz/w9PuNuUnod1RqgV3zYfwBjY8O02iex/VJn9IFw+2kaXg2Oo",
|
|
"MsvuhMt77cTI8zQ7G6qnsfO2Ajk+kmQbKIb3kDpWgEvzjpXE8UQbA82TWPjKIDg0b4OpxyxVVYFGpDuL",
|
|
"V4Hcx1cxbRipypxmwMiwQ/NXe+JOc8MB7Vh3ZGe44zoH9Xm+eNx+z/8s44nwSSx/jdaemwUSrR2dAnIn",
|
|
"6DQXtAmfzAVnRX5n/yM2nx7zhupJrH3vwLgzqrgluuE6bhu+p1nbovs/VzqhUlll2DXzCiU4zJhBqyuT",
|
|
"ovVpG3czoZjL0a+VWllMmEXf7v3+hW/aRQF2wKJaYNuMAzW3CS9hha9FIVxXsescfZYt0DC9ZOQBVqJh",
|
|
"nmRApl/6KD27ffdluIRKOj7/4yzhS20KcKShe/GcJ7wQShRVweezxm9COVyhaVR8u1xaHNBR0xpbalJN",
|
|
"KKC1RxQMBAManqGg1aZHtffauDp4lXTWB0wr9NWp0AbrhBZoe6M6Ye8MLsU9sdhv7s/+8Iys9fJQZR6z",
|
|
"aZOhmQwYTfo9lgbbhNcZRkn+PWRXeFuhJbM8ikNFf0JZSpGSg6drlU2gFN/9bDUVqx373xtc8jn/3XSH",
|
|
"U6dh1U5/NEab18K6IHbfZd9DxmrB24RfKn/UQL5Hs0ZDlF9Wn1oBFjRgQYVtwt9od1G5XBvxL8y+rE5v",
|
|
"tGMt2UGZn3SlvoIeQSwdgUDiOV4YJ0LigJRvl3z+8XEpV7HuvV38jKmP+wPfHQ1i45wRi8qFX4+xCqIv",
|
|
"dvspsSX5wOaiDBV8j7kzkP7S8z0Dt1/4j8u99qyuWuJ6+4DB20oYnzUfg5CbZpOOHjjYFVXs3Xfw5Wab",
|
|
"8I4TOrYthO6Wqwtmc1+xFkKvDJT5xhd9X3sgxLOnx4Xy0ts2oMBj9F3ta92vtBzga7Qkvh7k0FbfIIGR",
|
|
"h3xhBbmoCp5wVL5af+T0+6JWgCJn0fCEr3UK0n+96bFrKJyDSXJSevMCA9U+LxONPp5n5J7DJCHyo6lE",
|
|
"opOhvEv47sR39EO/ZEcfCeK0s/nRYxBZDyoU2XTdjw6E7GloCRdZ72frwFW2d8kJFwLQTdORur5rwMdr",
|
|
"ofpqylKY4NkGYFRG9B0sCeP2Kbwfta80uD6+b/uoTX/rzdq0MgaVe+chYe+JjRsINNZoNtVSYhpRWgds",
|
|
"HQKshDvtQF7WWdeVQesdqPo5wrw9x4RhlOYtO1Nan8cP6kXH4yGzu3pVStxWyESGyomlQEMQMeJP4jh8",
|
|
"Tem1c1M2JXyYw8HpEFm9pe+ABBR1qZa6axZULr9qOB0q9CFHl2Mwp7JoWA6WQZrSlVfTZ0vMPQTGeyhK",
|
|
"f5adqbBRY6G1RFBejyWCq0xfgC+YbwrebE2fQLJ6c0sIs1VZauMsAe46L/d6jr+UhQ5F17OC8unm6D0x",
|
|
"4UHC8a5aa6KX7g4M7tnNFaxFZnTRG/JA+Q80VmjVL2gdFltHasDDfDb582wyO5oX0apD4cl+2FuR6Usf",
|
|
"ashfBVeS5JNgZR37se0ySAjt/RQEGcHVWGw4JObbRzaHIexGjKDjcTTrt9FfAXQuUGq18lWo76xBcxca",
|
|
"g5HZXa5Zicb3Dcx2Qvo4N1j2KO96J3FPaYJ7hHdWmTBD6eVdr9b8gx+EYhZTrTLbbnxLqaEF/UM92UNb",
|
|
"PY3HL+0xP1peArfG3Qmv7wGNJT35QzO50IronSo02zgyedOqoJWRfM5z50o7n06b2jrRJnjrwAJhmS0x",
|
|
"ZeH7InaOhiG7eHeZsLtcpDkDKfWdpY5GfWxh9J1FBipjBSiPmFyOwrCisiJlUiwMmA1bC2DA/vr+7Zv5",
|
|
"xbtLxhZgMWMeVJglpDhh3ot+pTR6LTK0DFVWaqGcJUwQGlQSfGuTmHw2YaWEje9/ljQITSth4BM8TlpJ",
|
|
"G7ZX+ybsByn8WWYpKGbQGYFrD/VCEvhEgYWuwihsD5lFe5I4syWh1l9B48AsoS/1gWBAsMoyW3nP2ZDK",
|
|
"Qq1oV4YS6Udjw4R9CCoLG1ye4RqlP/FB00UlZBY9C2UZbKYeJ2gGm4Mjn64MOAzm72IYyEIzS6KfSRVm",
|
|
"EQqaxON9iUagSpGc3sQ4ohaS1hPkHYCcfPINMh4Uvpc//gJb928+mzyfzHwi6hIVlILP+YtJaMoluJyK",
|
|
"27TVj1Zhjuo9QeG5zPicv0J30cCV9oPyQJPdbZnuJsi+xY7YHGe5I3bvvX+O3t+8fY+maN5cTqKoH6pG",
|
|
"E7Xf9U4lOllY62VlvKfrF/URFDRUHrGvfobY3hwMmZ/PZmdNLD97TtcHu2V9Y3+M/PCC30I848joDt07",
|
|
"BKw16O9TQ5eU+lRvE/4yeLNPj8br09Zcn0heHCfZn3RvE/6nMYL6Jvc0Jq6KAsyGXr1io4CuNdukKVjT",
|
|
"h/DHZbY9XrtOLl1NbibjbtSHE016bPFFdvfWUqvL20EOF9Hh95enPRpjTsTIwXQ3F5tB7A5qn5dXL2cv",
|
|
"R1HFN4cnSETFhMrEWmQVyDrGlIu7O/lQ/rUmG18tlC0dzg7ndeut+b///o9lnpL9ghtWQBngSzMMihFn",
|
|
"mSC44pGpwdKg9cdFrfZGBl+72rxCF3V5ZtlK6gVIQqghvrs3oKH4Xocdv0Gj36DRNwqNwnDtm0FG8Uj/",
|
|
"CoGRL1XQsWNXpqYP9P8RQHQd5yZfBA/VQ5oeOBR1/ZWgoXgIzgZD9UP0twWFXPRK83YQcimMxaZQiun6",
|
|
"Od/ebP8XAAD//1dw5/GYLgAA",
|
|
}
|
|
|
|
// GetSwagger returns the content of the embedded swagger specification file
|
|
// or error if failed to decode
|
|
func decodeSpec() ([]byte, error) {
|
|
zipped, err := base64.StdEncoding.DecodeString(strings.Join(swaggerSpec, ""))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error base64 decoding spec: %s", err)
|
|
}
|
|
zr, err := gzip.NewReader(bytes.NewReader(zipped))
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
|
}
|
|
var buf bytes.Buffer
|
|
_, err = buf.ReadFrom(zr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error decompressing spec: %s", err)
|
|
}
|
|
|
|
return buf.Bytes(), nil
|
|
}
|
|
|
|
var rawSpec = decodeSpecCached()
|
|
|
|
// a naive cached of a decoded swagger spec
|
|
func decodeSpecCached() func() ([]byte, error) {
|
|
data, err := decodeSpec()
|
|
return func() ([]byte, error) {
|
|
return data, err
|
|
}
|
|
}
|
|
|
|
// Constructs a synthetic filesystem for resolving external references when loading openapi specifications.
|
|
func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error) {
|
|
var res = make(map[string]func() ([]byte, error))
|
|
if len(pathToFile) > 0 {
|
|
res[pathToFile] = rawSpec
|
|
}
|
|
|
|
return res
|
|
}
|
|
|
|
// GetSwagger returns the Swagger specification corresponding to the generated code
|
|
// in this file. The external references of Swagger specification are resolved.
|
|
// The logic of resolving external references is tightly connected to "import-mapping" feature.
|
|
// Externally referenced files must be embedded in the corresponding golang packages.
|
|
// Urls can be supported but this task was out of the scope.
|
|
func GetSwagger() (swagger *openapi3.T, err error) {
|
|
var resolvePath = PathToRawSpec("")
|
|
|
|
loader := openapi3.NewLoader()
|
|
loader.IsExternalRefsAllowed = true
|
|
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
|
|
var pathToFile = url.String()
|
|
pathToFile = path.Clean(pathToFile)
|
|
getSpec, ok := resolvePath[pathToFile]
|
|
if !ok {
|
|
err1 := fmt.Errorf("path not found: %s", pathToFile)
|
|
return nil, err1
|
|
}
|
|
return getSpec()
|
|
}
|
|
var specData []byte
|
|
specData, err = rawSpec()
|
|
if err != nil {
|
|
return
|
|
}
|
|
swagger, err = loader.LoadFromData(specData)
|
|
if err != nil {
|
|
return
|
|
}
|
|
return
|
|
}
|