mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-04 21:17:37 +03:00
1386 lines
46 KiB
Go
1386 lines
46 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.20230513000919-14548c7e7bbe 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 albums
|
|
// (GET /albums)
|
|
GetAlbums(w http.ResponseWriter, r *http.Request, params GetAlbumsParams)
|
|
// Retrieve an individual album
|
|
// (GET /albums/{albumId})
|
|
GetAlbum(w http.ResponseWriter, r *http.Request, albumId string, params GetAlbumParams)
|
|
// 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
|
|
|
|
// GetAlbums operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetAlbums(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetAlbumsParams
|
|
|
|
// ------------- 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.GetAlbums(w, r, params)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetAlbum operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetAlbum(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
// ------------- Path parameter "albumId" -------------
|
|
var albumId string
|
|
|
|
err = runtime.BindStyledParameterWithLocation("simple", false, "albumId", runtime.ParamLocationPath, chi.URLParam(r, "albumId"), &albumId)
|
|
if err != nil {
|
|
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "albumId", Err: err})
|
|
return
|
|
}
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
// Parameter object where we will unmarshal all parameters from the context
|
|
var params GetAlbumParams
|
|
|
|
// ------------- 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.GetAlbum(w, r, albumId, params)
|
|
})
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r.WithContext(ctx))
|
|
}
|
|
|
|
// GetArtists operation middleware
|
|
func (siw *ServerInterfaceWrapper) GetArtists(w http.ResponseWriter, r *http.Request) {
|
|
ctx := r.Context()
|
|
|
|
var err error
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
// 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
|
|
}
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
// 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()
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
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
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
// 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
|
|
}
|
|
|
|
ctx = context.WithValue(ctx, BearerAuthScopes, []string{})
|
|
|
|
// 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+"/albums", wrapper.GetAlbums)
|
|
})
|
|
r.Group(func(r chi.Router) {
|
|
r.Get(options.BaseURL+"/albums/{albumId}", wrapper.GetAlbum)
|
|
})
|
|
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 GetAlbumsRequestObject struct {
|
|
Params GetAlbumsParams
|
|
}
|
|
|
|
type GetAlbumsResponseObject interface {
|
|
VisitGetAlbumsResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetAlbums200JSONResponse struct {
|
|
Data []Album `json:"data"`
|
|
Links PaginationLinks `json:"links"`
|
|
Meta *PaginationMeta `json:"meta,omitempty"`
|
|
}
|
|
|
|
func (response GetAlbums200JSONResponse) VisitGetAlbumsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbums400JSONResponse struct{ BadRequestJSONResponse }
|
|
|
|
func (response GetAlbums400JSONResponse) VisitGetAlbumsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(400)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbums403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetAlbums403JSONResponse) VisitGetAlbumsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbums500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetAlbums500JSONResponse) VisitGetAlbumsResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbumRequestObject struct {
|
|
AlbumId string `json:"albumId"`
|
|
Params GetAlbumParams
|
|
}
|
|
|
|
type GetAlbumResponseObject interface {
|
|
VisitGetAlbumResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type GetAlbum200JSONResponse struct {
|
|
Data Album `json:"data"`
|
|
}
|
|
|
|
func (response GetAlbum200JSONResponse) VisitGetAlbumResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(200)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbum403JSONResponse struct{ NotAuthorizedJSONResponse }
|
|
|
|
func (response GetAlbum403JSONResponse) VisitGetAlbumResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(403)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbum404JSONResponse struct{ NotFoundJSONResponse }
|
|
|
|
func (response GetAlbum404JSONResponse) VisitGetAlbumResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(404)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
type GetAlbum500JSONResponse struct {
|
|
InternalServerErrorJSONResponse
|
|
}
|
|
|
|
func (response GetAlbum500JSONResponse) VisitGetAlbumResponse(w http.ResponseWriter) error {
|
|
w.Header().Set("Content-Type", "application/vnd.api+json")
|
|
w.WriteHeader(500)
|
|
|
|
return json.NewEncoder(w).Encode(response)
|
|
}
|
|
|
|
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 albums
|
|
// (GET /albums)
|
|
GetAlbums(ctx context.Context, request GetAlbumsRequestObject) (GetAlbumsResponseObject, error)
|
|
// Retrieve an individual album
|
|
// (GET /albums/{albumId})
|
|
GetAlbum(ctx context.Context, request GetAlbumRequestObject) (GetAlbumResponseObject, error)
|
|
// 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 = runtime.StrictHttpHandlerFunc
|
|
type StrictMiddlewareFunc = runtime.StrictHttpMiddlewareFunc
|
|
|
|
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
|
|
}
|
|
|
|
// GetAlbums operation middleware
|
|
func (sh *strictHandler) GetAlbums(w http.ResponseWriter, r *http.Request, params GetAlbumsParams) {
|
|
var request GetAlbumsRequestObject
|
|
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetAlbums(ctx, request.(GetAlbumsRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetAlbums")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetAlbumsResponseObject); ok {
|
|
if err := validResponse.VisitGetAlbumsResponse(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))
|
|
}
|
|
}
|
|
|
|
// GetAlbum operation middleware
|
|
func (sh *strictHandler) GetAlbum(w http.ResponseWriter, r *http.Request, albumId string, params GetAlbumParams) {
|
|
var request GetAlbumRequestObject
|
|
|
|
request.AlbumId = albumId
|
|
request.Params = params
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.GetAlbum(ctx, request.(GetAlbumRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "GetAlbum")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(GetAlbumResponseObject); ok {
|
|
if err := validResponse.VisitGetAlbumResponse(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))
|
|
}
|
|
}
|
|
|
|
// 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/+xb224bOdJ+FYL/D8wMpkfyJrN7IWAvnNk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8vz69ftvIF",
|
|
"7vgtjvCy6qjw0eTZ5MhMFQVwUlA8w88nrk0qiM7sNp02gWnhHj+YBbBecZIaXcAdnStL1DwCHWh6minT",
|
|
"5tWHaXlGTPbvL0bM7rxZHD2/fq86mqJ+J7UXRfW4bDRR+y3evkR7C2u9hhpv6eoV7AgK+xBkxLzq6dD6",
|
|
"duNhyLOjo4NeGXzKzZQtEQLJlVWns9uoNw9zR/a3G+elwVuvCkEg6fbyWnNm5Lf0OsK/OluGYNQ2n7Ze",
|
|
"4liS57tJum9T1hH+6xhBobc2tnooc9MR23dqPjmRnjLrqIpV0wf770m63hm19g5atVdG405ON27P7cso",
|
|
"E1ubh1EeK26vrjsQHH4r9bhbYsROGHkD2/dB7g8ymuL4MH/69ejXUVT+ddAjOCBHlKd0SdOSML++zgeb",
|
|
"envQ9eoD1+8Z83vGfJoZ0/XRTydl+i37RHJmpU0rYE0f3B+70mZ1QPJl8mYlLZQ4PdxvJXP6HfEpqdPf",
|
|
"CDyx3NkYZtrcKg75X+tu9qstZQvDwct50/o/Kv777/8oZCjRe1ihnBTumKG+xfYrjlJqjxWIXCEJhQRl",
|
|
"tgtfdC49v3a0eQ3aY/lBoQUTMWH2JMmtb/NOcGh9b9yM76XR99LoiZZG7nnAk6mM/Jb+BgsjE6pIT48m",
|
|
"TE0f7L87CqIbf1H0Reqh6lYqUA55rN9INeQ3wcHFUHXv97RKIe2t0roxs87Uvit7e2uWzaVY52rusmBK",
|
|
"CjpdPsPr2/X/AgAA//8ulwADnUEAAA==",
|
|
}
|
|
|
|
// 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
|
|
}
|