Files
media-preload/internal/api/api.gen.go
T
Claude a18d45714e media-preload: on-demand VPS cache warm-up API and agent
OpenAPI 3.0 contract (api/openapi.yaml) with oapi-codegen generated server,
client and models; preload-api (Jellyfin lookup, SQLite queue, bearer roles)
runs at home, preload-agent runs on the VPS and fills the rclone cache.
mise manages Go 1.27.3 and oapi-codegen 2.8.2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GUebqghNwNssAZuWTxUq1y
2026-11-04 17:49:06 -07:00

3201 lines
101 KiB
Go

//go:build go1.22
// Package api provides primitives to interact with the openapi HTTP API.
//
// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.8.2 DO NOT EDIT.
package api
import (
"bytes"
"compress/flate"
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"net/url"
"path"
"strings"
"time"
"github.com/getkin/kin-openapi/openapi3"
"github.com/oapi-codegen/runtime"
)
// Defines values for FileReportResult.
const (
FileReportResultAlreadyCached FileReportResult = "already_cached"
FileReportResultCached FileReportResult = "cached"
FileReportResultFailed FileReportResult = "failed"
)
// Valid indicates whether the value is a known member of the FileReportResult enum.
func (e FileReportResult) Valid() bool {
switch e {
case FileReportResultAlreadyCached:
return true
case FileReportResultCached:
return true
case FileReportResultFailed:
return true
default:
return false
}
}
// Defines values for FileStatus.
const (
FileStatusCached FileStatus = "cached"
FileStatusCanceled FileStatus = "canceled"
FileStatusFailed FileStatus = "failed"
FileStatusFetching FileStatus = "fetching"
FileStatusNotCacheable FileStatus = "not_cacheable"
FileStatusQueued FileStatus = "queued"
)
// Valid indicates whether the value is a known member of the FileStatus enum.
func (e FileStatus) Valid() bool {
switch e {
case FileStatusCached:
return true
case FileStatusCanceled:
return true
case FileStatusFailed:
return true
case FileStatusFetching:
return true
case FileStatusNotCacheable:
return true
case FileStatusQueued:
return true
default:
return false
}
}
// Defines values for MediaType.
const (
Movie MediaType = "movie"
Series MediaType = "series"
)
// Valid indicates whether the value is a known member of the MediaType enum.
func (e MediaType) Valid() bool {
switch e {
case Movie:
return true
case Series:
return true
default:
return false
}
}
// Defines values for RequestStatus.
const (
RequestStatusCanceled RequestStatus = "canceled"
RequestStatusDone RequestStatus = "done"
RequestStatusFailed RequestStatus = "failed"
RequestStatusFetching RequestStatus = "fetching"
RequestStatusPartial RequestStatus = "partial"
RequestStatusQueued RequestStatus = "queued"
)
// Valid indicates whether the value is a known member of the RequestStatus enum.
func (e RequestStatus) Valid() bool {
switch e {
case RequestStatusCanceled:
return true
case RequestStatusDone:
return true
case RequestStatusFailed:
return true
case RequestStatusFetching:
return true
case RequestStatusPartial:
return true
case RequestStatusQueued:
return true
default:
return false
}
}
// AgentJob defines model for AgentJob.
type AgentJob struct {
FileId int64 `json:"fileId"`
Path string `json:"path"`
SizeBytes int64 `json:"sizeBytes"`
}
// ClaimRequest defines model for ClaimRequest.
type ClaimRequest struct {
// AgentId Example: vps-dcruit2r
AgentId string `json:"agentId"`
}
// CreateRequest defines model for CreateRequest.
type CreateRequest struct {
// Episodes Episode numbers within `season`
Episodes *[]int `json:"episodes,omitempty"`
// ItemId Jellyfin item id from /v1/search
ItemId string `json:"itemId"`
// JellyfinUser Jellyfin user name whose watch progress decides "next"
JellyfinUser *string `json:"jellyfinUser,omitempty"`
// Next Next N unwatched episodes for jellyfinUser
Next *int `json:"next,omitempty"`
Note *string `json:"note,omitempty"`
// RequestedBy Who asked
RequestedBy string `json:"requestedBy"`
Season *int `json:"season,omitempty"`
}
// FileReport defines model for FileReport.
type FileReport struct {
// Bytes Bytes read from home for this file
Bytes *int64 `json:"bytes,omitempty"`
Error *string `json:"error,omitempty"`
Result FileReportResult `json:"result"`
}
// FileReportResult defines model for FileReport.Result.
type FileReportResult string
// FileStatus defines model for FileStatus.
type FileStatus string
// Health defines model for Health.
type Health struct {
// Status Example: ok
Status string `json:"status"`
Version string `json:"version"`
}
// MediaItem defines model for MediaItem.
type MediaItem struct {
// Cacheable False when the item lives outside the cached folders
Cacheable bool `json:"cacheable"`
// Id Jellyfin item id
Id string `json:"id"`
// Library Jellyfin library path prefix, e.g. /media2/Videos/tvshows
Library *string `json:"library,omitempty"`
Name string `json:"name"`
SeasonCount *int `json:"seasonCount,omitempty"`
Type MediaType `json:"type"`
Year *int `json:"year,omitempty"`
}
// MediaType defines model for MediaType.
type MediaType string
// PreloadFile defines model for PreloadFile.
type PreloadFile struct {
Error *string `json:"error,omitempty"`
FetchedBytes *int64 `json:"fetchedBytes,omitempty"`
Id int64 `json:"id"`
// Path Path as seen by Jellyfin and webdav, e.g. /media2/Videos/tvshows/...
Path string `json:"path"`
SizeBytes int64 `json:"sizeBytes"`
Status FileStatus `json:"status"`
// Title e.g. Dark Matter S02E08
Title string `json:"title"`
UpdatedAt *time.Time `json:"updatedAt,omitempty"`
}
// PreloadRequest defines model for PreloadRequest.
type PreloadRequest struct {
CreatedAt time.Time `json:"createdAt"`
Files []PreloadFile `json:"files"`
Id int64 `json:"id"`
ItemId string `json:"itemId"`
Note *string `json:"note,omitempty"`
RequestedBy string `json:"requestedBy"`
Status RequestStatus `json:"status"`
Title string `json:"title"`
}
// Problem defines model for Problem.
type Problem struct {
// Error Example: series requests need jellyfinUser when using next
Error string `json:"error"`
}
// RequestStatus defines model for RequestStatus.
type RequestStatus string
// ListRequestsParams defines parameters for ListRequests.
type ListRequestsParams struct {
Status *RequestStatus `form:"status,omitempty" json:"status,omitempty"`
Limit *int `form:"limit,omitempty" json:"limit,omitempty"`
}
// SearchLibraryParams defines parameters for SearchLibrary.
type SearchLibraryParams struct {
// Q Title to search for
Q string `form:"q" json:"q"`
Type *MediaType `form:"type,omitempty" json:"type,omitempty"`
Limit *int `form:"limit,omitempty" json:"limit,omitempty"`
}
// ClaimFileJSONRequestBody defines body for ClaimFile for application/json ContentType.
type ClaimFileJSONRequestBody = ClaimRequest
// ReportFileJSONRequestBody defines body for ReportFile for application/json ContentType.
type ReportFileJSONRequestBody = FileReport
// CreateRequestJSONRequestBody defines body for CreateRequest for application/json ContentType.
type CreateRequestJSONRequestBody = CreateRequest
// RequestEditorFn is the function signature for the RequestEditor callback function
type RequestEditorFn func(ctx context.Context, req *http.Request) error
// Doer performs HTTP requests.
//
// The standard http.Client implements this interface.
type HttpRequestDoer interface {
Do(req *http.Request) (*http.Response, error)
}
// Client which conforms to the OpenAPI3 specification for this service.
type Client struct {
// The endpoint of the server conforming to this interface, with scheme,
// https://api.deepmap.com for example. This can contain a path relative
// to the server, such as https://api.deepmap.com/dev-test, and all the
// paths in the swagger spec will be appended to the server.
Server string
// Doer for performing requests, typically a *http.Client with any
// customized settings, such as certificate chains.
Client HttpRequestDoer
// A list of callbacks for modifying requests which are generated before sending over
// the network.
RequestEditors []RequestEditorFn
}
// ClientOption allows setting custom parameters during construction
type ClientOption func(*Client) error
// Creates a new Client, with reasonable defaults
func NewClient(server string, opts ...ClientOption) (*Client, error) {
// create a client with sane default values
client := Client{
Server: server,
}
// mutate client and add all optional params
for _, o := range opts {
if err := o(&client); err != nil {
return nil, err
}
}
// ensure the server URL always has a trailing slash
if !strings.HasSuffix(client.Server, "/") {
client.Server += "/"
}
// create httpClient, if not already present
if client.Client == nil {
client.Client = &http.Client{}
}
return &client, nil
}
// WithHTTPClient allows overriding the default Doer, which is
// automatically created using http.Client. This is useful for tests.
func WithHTTPClient(doer HttpRequestDoer) ClientOption {
return func(c *Client) error {
c.Client = doer
return nil
}
}
// WithRequestEditorFn allows setting up a callback function, which will be
// called right before sending the request. This can be used to mutate the request.
func WithRequestEditorFn(fn RequestEditorFn) ClientOption {
return func(c *Client) error {
c.RequestEditors = append(c.RequestEditors, fn)
return nil
}
}
// The interface specification for the client above.
type ClientInterface interface {
// ClaimFileWithBody Agent takes the next queued file
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
ClaimFileWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
// ClaimFile Agent takes the next queued file
//
// Takes a body of the `application/json` content type.
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
ClaimFile(ctx context.Context, body ClaimFileJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// ReportFileWithBody Agent reports the result for a claimed file
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
ReportFileWithBody(ctx context.Context, fileId int64, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
// ReportFile Agent reports the result for a claimed file
//
// Takes a body of the `application/json` content type.
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
ReportFile(ctx context.Context, fileId int64, body ReportFileJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// GetHealth Liveness and version
//
// Corresponds with GET /v1/health (the `GetHealth` operationId).
GetHealth(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
// ListRequests Recent requests, newest first
//
// Corresponds with GET /v1/requests (the `ListRequests` operationId).
ListRequests(ctx context.Context, params *ListRequestsParams, reqEditors ...RequestEditorFn) (*http.Response, error)
// CreateRequestWithBody Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
CreateRequestWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
// CreateRequest Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes a body of the `application/json` content type.
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
CreateRequest(ctx context.Context, body CreateRequestJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// CancelRequest Cancel the files of a request that are still queued
//
// Corresponds with DELETE /v1/requests/{id} (the `CancelRequest` operationId).
CancelRequest(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
// GetRequest One request with per-file progress
//
// Corresponds with GET /v1/requests/{id} (the `GetRequest` operationId).
GetRequest(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error)
// SearchLibrary Search movies and series in Jellyfin
//
// Corresponds with GET /v1/search (the `SearchLibrary` operationId).
SearchLibrary(ctx context.Context, params *SearchLibraryParams, reqEditors ...RequestEditorFn) (*http.Response, error)
}
// ClaimFileWithBody Agent takes the next queued file
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
func (c *Client) ClaimFileWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewClaimFileRequestWithBody(c.Server, contentType, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// ClaimFile Agent takes the next queued file
//
// Takes a body of the `application/json` content type.
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
func (c *Client) ClaimFile(ctx context.Context, body ClaimFileJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewClaimFileRequest(c.Server, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// ReportFileWithBody Agent reports the result for a claimed file
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
func (c *Client) ReportFileWithBody(ctx context.Context, fileId int64, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewReportFileRequestWithBody(c.Server, fileId, contentType, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// ReportFile Agent reports the result for a claimed file
//
// Takes a body of the `application/json` content type.
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
func (c *Client) ReportFile(ctx context.Context, fileId int64, body ReportFileJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewReportFileRequest(c.Server, fileId, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// GetHealth Liveness and version
//
// Corresponds with GET /v1/health (the `GetHealth` operationId).
func (c *Client) GetHealth(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewGetHealthRequest(c.Server)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// ListRequests Recent requests, newest first
//
// Corresponds with GET /v1/requests (the `ListRequests` operationId).
func (c *Client) ListRequests(ctx context.Context, params *ListRequestsParams, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewListRequestsRequest(c.Server, params)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// CreateRequestWithBody Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
func (c *Client) CreateRequestWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewCreateRequestRequestWithBody(c.Server, contentType, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// CreateRequest Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes a body of the `application/json` content type.
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
func (c *Client) CreateRequest(ctx context.Context, body CreateRequestJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewCreateRequestRequest(c.Server, body)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// CancelRequest Cancel the files of a request that are still queued
//
// Corresponds with DELETE /v1/requests/{id} (the `CancelRequest` operationId).
func (c *Client) CancelRequest(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewCancelRequestRequest(c.Server, id)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// GetRequest One request with per-file progress
//
// Corresponds with GET /v1/requests/{id} (the `GetRequest` operationId).
func (c *Client) GetRequest(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewGetRequestRequest(c.Server, id)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// SearchLibrary Search movies and series in Jellyfin
//
// Corresponds with GET /v1/search (the `SearchLibrary` operationId).
func (c *Client) SearchLibrary(ctx context.Context, params *SearchLibraryParams, reqEditors ...RequestEditorFn) (*http.Response, error) {
req, err := NewSearchLibraryRequest(c.Server, params)
if err != nil {
return nil, err
}
req = req.WithContext(ctx)
if err := c.applyEditors(ctx, req, reqEditors); err != nil {
return nil, err
}
return c.Client.Do(req)
}
// NewClaimFileRequest calls the generic ClaimFile builder with application/json body
func NewClaimFileRequest(server string, body ClaimFileJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewClaimFileRequestWithBody(server, "application/json", bodyReader)
}
// NewClaimFileRequestWithBody constructs an http.Request for the ClaimFile method, with any body, and a specified content type
func NewClaimFileRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
var err error
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/agent/claim")
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, queryURL.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
return req, nil
}
// NewReportFileRequest calls the generic ReportFile builder with application/json body
func NewReportFileRequest(server string, fileId int64, body ReportFileJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewReportFileRequestWithBody(server, fileId, "application/json", bodyReader)
}
// NewReportFileRequestWithBody constructs an http.Request for the ReportFile method, with any body, and a specified content type
func NewReportFileRequestWithBody(server string, fileId int64, contentType string, body io.Reader) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithOptions("simple", false, "fileId", fileId, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "integer", Format: "int64"})
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/agent/files/%s", pathParam0)
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, queryURL.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
return req, nil
}
// NewGetHealthRequest constructs an http.Request for the GetHealth method
func NewGetHealthRequest(server string) (*http.Request, error) {
var err error
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/health")
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
// NewListRequestsRequest constructs an http.Request for the ListRequests method
func NewListRequestsRequest(server string, params *ListRequestsParams) (*http.Request, error) {
var err error
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/requests")
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
if params != nil {
// queryValues collects non-styled parameters (passthrough, JSON)
// that are safe to round-trip through url.Values.Encode().
queryValues := queryURL.Query()
// rawQueryFragments collects pre-encoded query fragments from
// styled parameters, preserving literal commas as delimiters
// per the OpenAPI spec (e.g. "color=blue,black,brown").
var rawQueryFragments []string
if params.Status != nil {
if queryFrag, err := runtime.StyleParamWithOptions("form", true, "status", *params.Status, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil {
return nil, err
} else {
for _, qp := range strings.Split(queryFrag, "&") {
rawQueryFragments = append(rawQueryFragments, qp)
}
}
}
if params.Limit != nil {
if queryFrag, err := runtime.StyleParamWithOptions("form", true, "limit", *params.Limit, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "integer", Format: ""}); err != nil {
return nil, err
} else {
for _, qp := range strings.Split(queryFrag, "&") {
rawQueryFragments = append(rawQueryFragments, qp)
}
}
}
if encoded := queryValues.Encode(); encoded != "" {
rawQueryFragments = append(rawQueryFragments, encoded)
}
queryURL.RawQuery = strings.Join(rawQueryFragments, "&")
}
req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
// NewCreateRequestRequest calls the generic CreateRequest builder with application/json body
func NewCreateRequestRequest(server string, body CreateRequestJSONRequestBody) (*http.Request, error) {
var bodyReader io.Reader
buf, err := json.Marshal(body)
if err != nil {
return nil, err
}
bodyReader = bytes.NewReader(buf)
return NewCreateRequestRequestWithBody(server, "application/json", bodyReader)
}
// NewCreateRequestRequestWithBody constructs an http.Request for the CreateRequest method, with any body, and a specified content type
func NewCreateRequestRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error) {
var err error
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/requests")
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodPost, queryURL.String(), body)
if err != nil {
return nil, err
}
req.Header.Add("Content-Type", contentType)
return req, nil
}
// NewCancelRequestRequest constructs an http.Request for the CancelRequest method
func NewCancelRequestRequest(server string, id int64) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "integer", Format: "int64"})
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/requests/%s", pathParam0)
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodDelete, queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
// NewGetRequestRequest constructs an http.Request for the GetRequest method
func NewGetRequestRequest(server string, id int64) (*http.Request, error) {
var err error
var pathParam0 string
pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "integer", Format: "int64"})
if err != nil {
return nil, err
}
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/requests/%s", pathParam0)
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
// NewSearchLibraryRequest constructs an http.Request for the SearchLibrary method
func NewSearchLibraryRequest(server string, params *SearchLibraryParams) (*http.Request, error) {
var err error
serverURL, err := url.Parse(server)
if err != nil {
return nil, err
}
operationPath := fmt.Sprintf("/v1/search")
if operationPath[0] == '/' {
operationPath = "." + operationPath
}
queryURL, err := serverURL.Parse(operationPath)
if err != nil {
return nil, err
}
if params != nil {
// queryValues collects non-styled parameters (passthrough, JSON)
// that are safe to round-trip through url.Values.Encode().
queryValues := queryURL.Query()
// rawQueryFragments collects pre-encoded query fragments from
// styled parameters, preserving literal commas as delimiters
// per the OpenAPI spec (e.g. "color=blue,black,brown").
var rawQueryFragments []string
if queryFrag, err := runtime.StyleParamWithOptions("form", true, "q", params.Q, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil {
return nil, err
} else {
for _, qp := range strings.Split(queryFrag, "&") {
rawQueryFragments = append(rawQueryFragments, qp)
}
}
if params.Type != nil {
if queryFrag, err := runtime.StyleParamWithOptions("form", true, "type", *params.Type, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "string", Format: ""}); err != nil {
return nil, err
} else {
for _, qp := range strings.Split(queryFrag, "&") {
rawQueryFragments = append(rawQueryFragments, qp)
}
}
}
if params.Limit != nil {
if queryFrag, err := runtime.StyleParamWithOptions("form", true, "limit", *params.Limit, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationQuery, Type: "integer", Format: ""}); err != nil {
return nil, err
} else {
for _, qp := range strings.Split(queryFrag, "&") {
rawQueryFragments = append(rawQueryFragments, qp)
}
}
}
if encoded := queryValues.Encode(); encoded != "" {
rawQueryFragments = append(rawQueryFragments, encoded)
}
queryURL.RawQuery = strings.Join(rawQueryFragments, "&")
}
req, err := http.NewRequest(http.MethodGet, queryURL.String(), nil)
if err != nil {
return nil, err
}
return req, nil
}
func (c *Client) applyEditors(ctx context.Context, req *http.Request, additionalEditors []RequestEditorFn) error {
for _, r := range c.RequestEditors {
if err := r(ctx, req); err != nil {
return err
}
}
for _, r := range additionalEditors {
if err := r(ctx, req); err != nil {
return err
}
}
return nil
}
// ClientWithResponses builds on ClientInterface to offer response payloads
type ClientWithResponses struct {
ClientInterface
}
// NewClientWithResponses creates a new ClientWithResponses, which wraps
// Client with return type handling
func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error) {
client, err := NewClient(server, opts...)
if err != nil {
return nil, err
}
return &ClientWithResponses{client}, nil
}
// WithBaseURL overrides the baseURL.
func WithBaseURL(baseURL string) ClientOption {
return func(c *Client) error {
newBaseURL, err := url.Parse(baseURL)
if err != nil {
return err
}
c.Server = newBaseURL.String()
return nil
}
}
// ClientWithResponsesInterface is the interface specification for the client with responses above.
type ClientWithResponsesInterface interface {
// ClaimFileWithBodyWithResponse Agent takes the next queued file
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
ClaimFileWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ClaimFileResponse, error)
// ClaimFileWithResponse Agent takes the next queued file
//
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
ClaimFileWithResponse(ctx context.Context, body ClaimFileJSONRequestBody, reqEditors ...RequestEditorFn) (*ClaimFileResponse, error)
// ReportFileWithBodyWithResponse Agent reports the result for a claimed file
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
ReportFileWithBodyWithResponse(ctx context.Context, fileId int64, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ReportFileResponse, error)
// ReportFileWithResponse Agent reports the result for a claimed file
//
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
ReportFileWithResponse(ctx context.Context, fileId int64, body ReportFileJSONRequestBody, reqEditors ...RequestEditorFn) (*ReportFileResponse, error)
// GetHealthWithResponse Liveness and version
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/health (the `GetHealth` operationId).
GetHealthWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetHealthResponse, error)
// ListRequestsWithResponse Recent requests, newest first
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/requests (the `ListRequests` operationId).
ListRequestsWithResponse(ctx context.Context, params *ListRequestsParams, reqEditors ...RequestEditorFn) (*ListRequestsResponse, error)
// CreateRequestWithBodyWithResponse Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
CreateRequestWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateRequestResponse, error)
// CreateRequestWithResponse Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
CreateRequestWithResponse(ctx context.Context, body CreateRequestJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateRequestResponse, error)
// CancelRequestWithResponse Cancel the files of a request that are still queued
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with DELETE /v1/requests/{id} (the `CancelRequest` operationId).
CancelRequestWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*CancelRequestResponse, error)
// GetRequestWithResponse One request with per-file progress
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/requests/{id} (the `GetRequest` operationId).
GetRequestWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*GetRequestResponse, error)
// SearchLibraryWithResponse Search movies and series in Jellyfin
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/search (the `SearchLibrary` operationId).
SearchLibraryWithResponse(ctx context.Context, params *SearchLibraryParams, reqEditors ...RequestEditorFn) (*SearchLibraryResponse, error)
}
type ClaimFileResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON200 the response for an HTTP 200 `application/json` response
JSON200 *AgentJob
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
// JSON403 the response for an HTTP 403 `application/json` response
JSON403 *Problem
}
// GetJSON200 returns the response for an HTTP 200 `application/json` response
func (r ClaimFileResponse) GetJSON200() *AgentJob {
return r.JSON200
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r ClaimFileResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetJSON403 returns the response for an HTTP 403 `application/json` response
func (r ClaimFileResponse) GetJSON403() *Problem {
return r.JSON403
}
// GetBody returns the raw response body bytes
func (r ClaimFileResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r ClaimFileResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r ClaimFileResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r ClaimFileResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type ReportFileResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
// JSON403 the response for an HTTP 403 `application/json` response
JSON403 *Problem
// JSON404 the response for an HTTP 404 `application/json` response
JSON404 *Problem
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r ReportFileResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetJSON403 returns the response for an HTTP 403 `application/json` response
func (r ReportFileResponse) GetJSON403() *Problem {
return r.JSON403
}
// GetJSON404 returns the response for an HTTP 404 `application/json` response
func (r ReportFileResponse) GetJSON404() *Problem {
return r.JSON404
}
// GetBody returns the raw response body bytes
func (r ReportFileResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r ReportFileResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r ReportFileResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r ReportFileResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type GetHealthResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON200 the response for an HTTP 200 `application/json` response
JSON200 *Health
}
// GetJSON200 returns the response for an HTTP 200 `application/json` response
func (r GetHealthResponse) GetJSON200() *Health {
return r.JSON200
}
// GetBody returns the raw response body bytes
func (r GetHealthResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r GetHealthResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r GetHealthResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r GetHealthResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type ListRequestsResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON200 the response for an HTTP 200 `application/json` response
JSON200 *[]PreloadRequest
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
}
// GetJSON200 returns the response for an HTTP 200 `application/json` response
func (r ListRequestsResponse) GetJSON200() *[]PreloadRequest {
return r.JSON200
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r ListRequestsResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetBody returns the raw response body bytes
func (r ListRequestsResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r ListRequestsResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r ListRequestsResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r ListRequestsResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type CreateRequestResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON201 the response for an HTTP 201 `application/json` response
JSON201 *PreloadRequest
// JSON400 the response for an HTTP 400 `application/json` response
JSON400 *Problem
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
// JSON404 the response for an HTTP 404 `application/json` response
JSON404 *Problem
}
// GetJSON201 returns the response for an HTTP 201 `application/json` response
func (r CreateRequestResponse) GetJSON201() *PreloadRequest {
return r.JSON201
}
// GetJSON400 returns the response for an HTTP 400 `application/json` response
func (r CreateRequestResponse) GetJSON400() *Problem {
return r.JSON400
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r CreateRequestResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetJSON404 returns the response for an HTTP 404 `application/json` response
func (r CreateRequestResponse) GetJSON404() *Problem {
return r.JSON404
}
// GetBody returns the raw response body bytes
func (r CreateRequestResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r CreateRequestResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r CreateRequestResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r CreateRequestResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type CancelRequestResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON200 the response for an HTTP 200 `application/json` response
JSON200 *PreloadRequest
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
// JSON404 the response for an HTTP 404 `application/json` response
JSON404 *Problem
}
// GetJSON200 returns the response for an HTTP 200 `application/json` response
func (r CancelRequestResponse) GetJSON200() *PreloadRequest {
return r.JSON200
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r CancelRequestResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetJSON404 returns the response for an HTTP 404 `application/json` response
func (r CancelRequestResponse) GetJSON404() *Problem {
return r.JSON404
}
// GetBody returns the raw response body bytes
func (r CancelRequestResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r CancelRequestResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r CancelRequestResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r CancelRequestResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type GetRequestResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON200 the response for an HTTP 200 `application/json` response
JSON200 *PreloadRequest
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
// JSON404 the response for an HTTP 404 `application/json` response
JSON404 *Problem
}
// GetJSON200 returns the response for an HTTP 200 `application/json` response
func (r GetRequestResponse) GetJSON200() *PreloadRequest {
return r.JSON200
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r GetRequestResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetJSON404 returns the response for an HTTP 404 `application/json` response
func (r GetRequestResponse) GetJSON404() *Problem {
return r.JSON404
}
// GetBody returns the raw response body bytes
func (r GetRequestResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r GetRequestResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r GetRequestResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r GetRequestResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
type SearchLibraryResponse struct {
Body []byte
HTTPResponse *http.Response
// JSON200 the response for an HTTP 200 `application/json` response
JSON200 *[]MediaItem
// JSON400 the response for an HTTP 400 `application/json` response
JSON400 *Problem
// JSON401 the response for an HTTP 401 `application/json` response
JSON401 *Problem
}
// GetJSON200 returns the response for an HTTP 200 `application/json` response
func (r SearchLibraryResponse) GetJSON200() *[]MediaItem {
return r.JSON200
}
// GetJSON400 returns the response for an HTTP 400 `application/json` response
func (r SearchLibraryResponse) GetJSON400() *Problem {
return r.JSON400
}
// GetJSON401 returns the response for an HTTP 401 `application/json` response
func (r SearchLibraryResponse) GetJSON401() *Problem {
return r.JSON401
}
// GetBody returns the raw response body bytes
func (r SearchLibraryResponse) GetBody() []byte {
return r.Body
}
// Status returns HTTPResponse.Status
func (r SearchLibraryResponse) Status() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Status
}
return http.StatusText(0)
}
// StatusCode returns HTTPResponse.StatusCode
func (r SearchLibraryResponse) StatusCode() int {
if r.HTTPResponse != nil {
return r.HTTPResponse.StatusCode
}
return 0
}
// ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (r SearchLibraryResponse) ContentType() string {
if r.HTTPResponse != nil {
return r.HTTPResponse.Header.Get("Content-Type")
}
return ""
}
// ClaimFileWithBodyWithResponse Agent takes the next queued file
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
func (c *ClientWithResponses) ClaimFileWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ClaimFileResponse, error) {
rsp, err := c.ClaimFileWithBody(ctx, contentType, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseClaimFileResponse(rsp)
}
// ClaimFileWithResponse Agent takes the next queued file
//
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/claim (the `ClaimFile` operationId).
func (c *ClientWithResponses) ClaimFileWithResponse(ctx context.Context, body ClaimFileJSONRequestBody, reqEditors ...RequestEditorFn) (*ClaimFileResponse, error) {
rsp, err := c.ClaimFile(ctx, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseClaimFileResponse(rsp)
}
// ReportFileWithBodyWithResponse Agent reports the result for a claimed file
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
func (c *ClientWithResponses) ReportFileWithBodyWithResponse(ctx context.Context, fileId int64, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*ReportFileResponse, error) {
rsp, err := c.ReportFileWithBody(ctx, fileId, contentType, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseReportFileResponse(rsp)
}
// ReportFileWithResponse Agent reports the result for a claimed file
//
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/agent/files/{fileId} (the `ReportFile` operationId).
func (c *ClientWithResponses) ReportFileWithResponse(ctx context.Context, fileId int64, body ReportFileJSONRequestBody, reqEditors ...RequestEditorFn) (*ReportFileResponse, error) {
rsp, err := c.ReportFile(ctx, fileId, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseReportFileResponse(rsp)
}
// GetHealthWithResponse Liveness and version
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/health (the `GetHealth` operationId).
func (c *ClientWithResponses) GetHealthWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetHealthResponse, error) {
rsp, err := c.GetHealth(ctx, reqEditors...)
if err != nil {
return nil, err
}
return ParseGetHealthResponse(rsp)
}
// ListRequestsWithResponse Recent requests, newest first
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/requests (the `ListRequests` operationId).
func (c *ClientWithResponses) ListRequestsWithResponse(ctx context.Context, params *ListRequestsParams, reqEditors ...RequestEditorFn) (*ListRequestsResponse, error) {
rsp, err := c.ListRequests(ctx, params, reqEditors...)
if err != nil {
return nil, err
}
return ParseListRequestsResponse(rsp)
}
// CreateRequestWithBodyWithResponse Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
func (c *ClientWithResponses) CreateRequestWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*CreateRequestResponse, error) {
rsp, err := c.CreateRequestWithBody(ctx, contentType, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseCreateRequestResponse(rsp)
}
// CreateRequestWithResponse Ask for a movie or episodes to be cached
//
// For a movie, `season`, `episodes` and `next` are ignored.
// For a series, give exactly one of:
// - `season` (whole season), optionally with `episodes` (those episode numbers of that season);
// - `next` (the next N unwatched episodes for `jellyfinUser`).
// With none of them, a series defaults to `next: 3` and then needs `jellyfinUser`.
//
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /v1/requests (the `CreateRequest` operationId).
func (c *ClientWithResponses) CreateRequestWithResponse(ctx context.Context, body CreateRequestJSONRequestBody, reqEditors ...RequestEditorFn) (*CreateRequestResponse, error) {
rsp, err := c.CreateRequest(ctx, body, reqEditors...)
if err != nil {
return nil, err
}
return ParseCreateRequestResponse(rsp)
}
// CancelRequestWithResponse Cancel the files of a request that are still queued
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with DELETE /v1/requests/{id} (the `CancelRequest` operationId).
func (c *ClientWithResponses) CancelRequestWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*CancelRequestResponse, error) {
rsp, err := c.CancelRequest(ctx, id, reqEditors...)
if err != nil {
return nil, err
}
return ParseCancelRequestResponse(rsp)
}
// GetRequestWithResponse One request with per-file progress
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/requests/{id} (the `GetRequest` operationId).
func (c *ClientWithResponses) GetRequestWithResponse(ctx context.Context, id int64, reqEditors ...RequestEditorFn) (*GetRequestResponse, error) {
rsp, err := c.GetRequest(ctx, id, reqEditors...)
if err != nil {
return nil, err
}
return ParseGetRequestResponse(rsp)
}
// SearchLibraryWithResponse Search movies and series in Jellyfin
//
// Returns a wrapper object for the known response body format(s).
//
// Corresponds with GET /v1/search (the `SearchLibrary` operationId).
func (c *ClientWithResponses) SearchLibraryWithResponse(ctx context.Context, params *SearchLibraryParams, reqEditors ...RequestEditorFn) (*SearchLibraryResponse, error) {
rsp, err := c.SearchLibrary(ctx, params, reqEditors...)
if err != nil {
return nil, err
}
return ParseSearchLibraryResponse(rsp)
}
// ParseClaimFileResponse parses an HTTP response from a ClaimFileWithResponse call
func ParseClaimFileResponse(rsp *http.Response) (*ClaimFileResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &ClaimFileResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest AgentJob
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
case rsp.StatusCode == 204:
break // No content-type
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON403 = &dest
}
return response, nil
}
// ParseReportFileResponse parses an HTTP response from a ReportFileWithResponse call
func ParseReportFileResponse(rsp *http.Response) (*ReportFileResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &ReportFileResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case rsp.StatusCode == 204:
break // No content-type
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 403:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON403 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON404 = &dest
}
return response, nil
}
// ParseGetHealthResponse parses an HTTP response from a GetHealthWithResponse call
func ParseGetHealthResponse(rsp *http.Response) (*GetHealthResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &GetHealthResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest Health
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
}
return response, nil
}
// ParseListRequestsResponse parses an HTTP response from a ListRequestsWithResponse call
func ParseListRequestsResponse(rsp *http.Response) (*ListRequestsResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &ListRequestsResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest []PreloadRequest
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
}
return response, nil
}
// ParseCreateRequestResponse parses an HTTP response from a CreateRequestWithResponse call
func ParseCreateRequestResponse(rsp *http.Response) (*CreateRequestResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &CreateRequestResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 201:
var dest PreloadRequest
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON201 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON400 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON404 = &dest
}
return response, nil
}
// ParseCancelRequestResponse parses an HTTP response from a CancelRequestWithResponse call
func ParseCancelRequestResponse(rsp *http.Response) (*CancelRequestResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &CancelRequestResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest PreloadRequest
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON404 = &dest
}
return response, nil
}
// ParseGetRequestResponse parses an HTTP response from a GetRequestWithResponse call
func ParseGetRequestResponse(rsp *http.Response) (*GetRequestResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &GetRequestResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest PreloadRequest
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 404:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON404 = &dest
}
return response, nil
}
// ParseSearchLibraryResponse parses an HTTP response from a SearchLibraryWithResponse call
func ParseSearchLibraryResponse(rsp *http.Response) (*SearchLibraryResponse, error) {
bodyBytes, err := io.ReadAll(rsp.Body)
defer func() { _ = rsp.Body.Close() }()
if err != nil {
return nil, err
}
response := &SearchLibraryResponse{
Body: bodyBytes,
HTTPResponse: rsp,
}
switch {
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
var dest []MediaItem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON200 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 400:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON400 = &dest
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 401:
var dest Problem
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
return nil, err
}
response.JSON401 = &dest
}
return response, nil
}
// ServerInterface represents all server handlers.
type ServerInterface interface {
// ClaimFile Agent takes the next queued file
// (POST /v1/agent/claim)
ClaimFile(w http.ResponseWriter, r *http.Request)
// ReportFile Agent reports the result for a claimed file
// (POST /v1/agent/files/{fileId})
ReportFile(w http.ResponseWriter, r *http.Request, fileId int64)
// GetHealth Liveness and version
// (GET /v1/health)
GetHealth(w http.ResponseWriter, r *http.Request)
// ListRequests Recent requests, newest first
// (GET /v1/requests)
ListRequests(w http.ResponseWriter, r *http.Request, params ListRequestsParams)
// CreateRequest Ask for a movie or episodes to be cached
// (POST /v1/requests)
CreateRequest(w http.ResponseWriter, r *http.Request)
// CancelRequest Cancel the files of a request that are still queued
// (DELETE /v1/requests/{id})
CancelRequest(w http.ResponseWriter, r *http.Request, id int64)
// GetRequest One request with per-file progress
// (GET /v1/requests/{id})
GetRequest(w http.ResponseWriter, r *http.Request, id int64)
// SearchLibrary Search movies and series in Jellyfin
// (GET /v1/search)
SearchLibrary(w http.ResponseWriter, r *http.Request, params SearchLibraryParams)
}
// 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
// ClaimFile operation middleware
func (siw *ServerInterfaceWrapper) ClaimFile(w http.ResponseWriter, r *http.Request) {
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ClaimFile(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// ReportFile operation middleware
func (siw *ServerInterfaceWrapper) ReportFile(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "fileId" -------------
var fileId int64
err = runtime.BindStyledParameterWithOptions("simple", "fileId", r.PathValue("fileId"), &fileId, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "integer", Format: "int64", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "fileId", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ReportFile(w, r, fileId)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// GetHealth operation middleware
func (siw *ServerInterfaceWrapper) GetHealth(w http.ResponseWriter, r *http.Request) {
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetHealth(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// ListRequests operation middleware
func (siw *ServerInterfaceWrapper) ListRequests(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// Parameter object where we will unmarshal all parameters from the context
var params ListRequestsParams
// ------------- Optional query parameter "status" -------------
err = runtime.BindQueryParameterWithOptions("form", true, false, "status", r.URL.Query(), &params.Status, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
if err != nil {
var requiredError *runtime.RequiredParameterError
if errors.As(err, &requiredError) {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "status"})
} else {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "status", Err: err})
}
return
}
// ------------- Optional query parameter "limit" -------------
err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), &params.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: ""})
if err != nil {
var requiredError *runtime.RequiredParameterError
if errors.As(err, &requiredError) {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "limit"})
} else {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
}
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.ListRequests(w, r, params)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// CreateRequest operation middleware
func (siw *ServerInterfaceWrapper) CreateRequest(w http.ResponseWriter, r *http.Request) {
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.CreateRequest(w, r)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// CancelRequest operation middleware
func (siw *ServerInterfaceWrapper) CancelRequest(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "id" -------------
var id int64
err = runtime.BindStyledParameterWithOptions("simple", "id", r.PathValue("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "integer", Format: "int64", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.CancelRequest(w, r, id)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// GetRequest operation middleware
func (siw *ServerInterfaceWrapper) GetRequest(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// ------------- Path parameter "id" -------------
var id int64
err = runtime.BindStyledParameterWithOptions("simple", "id", r.PathValue("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "integer", Format: "int64", ValueIsUnescaped: true})
if err != nil {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "id", Err: err})
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.GetRequest(w, r, id)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
// SearchLibrary operation middleware
func (siw *ServerInterfaceWrapper) SearchLibrary(w http.ResponseWriter, r *http.Request) {
var err error
_ = err
// Parameter object where we will unmarshal all parameters from the context
var params SearchLibraryParams
// ------------- Required query parameter "q" -------------
err = runtime.BindQueryParameterWithOptions("form", true, true, "q", r.URL.Query(), &params.Q, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
if err != nil {
var requiredError *runtime.RequiredParameterError
if errors.As(err, &requiredError) {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "q"})
} else {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "q", Err: err})
}
return
}
// ------------- Optional query parameter "type" -------------
err = runtime.BindQueryParameterWithOptions("form", true, false, "type", r.URL.Query(), &params.Type, runtime.BindQueryParameterOptions{Type: "string", Format: ""})
if err != nil {
var requiredError *runtime.RequiredParameterError
if errors.As(err, &requiredError) {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "type"})
} else {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "type", Err: err})
}
return
}
// ------------- Optional query parameter "limit" -------------
err = runtime.BindQueryParameterWithOptions("form", true, false, "limit", r.URL.Query(), &params.Limit, runtime.BindQueryParameterOptions{Type: "integer", Format: ""})
if err != nil {
var requiredError *runtime.RequiredParameterError
if errors.As(err, &requiredError) {
siw.ErrorHandlerFunc(w, r, &RequiredParamError{ParamName: "limit"})
} else {
siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "limit", Err: err})
}
return
}
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
siw.Handler.SearchLibrary(w, r, params)
}))
for _, middleware := range siw.HandlerMiddlewares {
handler = middleware(handler)
}
handler.ServeHTTP(w, r)
}
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 UnmarshalingParamError struct {
ParamName string
Err error
}
func (e *UnmarshalingParamError) Error() string {
return fmt.Sprintf("Error unmarshaling parameter %s as JSON: %s", e.ParamName, e.Err.Error())
}
func (e *UnmarshalingParamError) 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, StdHTTPServerOptions{})
}
// ServeMux is an abstraction of [http.ServeMux].
type ServeMux interface {
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
http.Handler
}
type StdHTTPServerOptions struct {
BaseURL string
BaseRouter ServeMux
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, m ServeMux) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{
BaseRouter: m,
})
}
func HandlerFromMuxWithBaseURL(si ServerInterface, m ServeMux, baseURL string) http.Handler {
return HandlerWithOptions(si, StdHTTPServerOptions{
BaseURL: baseURL,
BaseRouter: m,
})
}
// HandlerWithOptions creates http.Handler with additional options
func HandlerWithOptions(si ServerInterface, options StdHTTPServerOptions) http.Handler {
m := options.BaseRouter
if m == nil {
m = http.NewServeMux()
}
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,
}
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/health", wrapper.GetHealth)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/search", wrapper.SearchLibrary)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/requests", wrapper.ListRequests)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/requests", wrapper.CreateRequest)
m.HandleFunc(http.MethodDelete+" "+options.BaseURL+"/v1/requests/{id}", wrapper.CancelRequest)
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/requests/{id}", wrapper.GetRequest)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/agent/claim", wrapper.ClaimFile)
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/agent/files/{fileId}", wrapper.ReportFile)
return m
}
type ProblemJSONResponse Problem
type ClaimFileRequestObject struct {
Body *ClaimFileJSONRequestBody
}
type ClaimFileResponseObject interface {
VisitClaimFileResponse(w http.ResponseWriter) error
}
type ClaimFile200JSONResponse AgentJob
func (response ClaimFile200JSONResponse) VisitClaimFileResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
_, err := buf.WriteTo(w)
return err
}
type ClaimFile204Response struct {
}
func (response ClaimFile204Response) VisitClaimFileResponse(w http.ResponseWriter) error {
w.WriteHeader(204)
return nil
}
type ClaimFile401JSONResponse struct{ ProblemJSONResponse }
func (response ClaimFile401JSONResponse) VisitClaimFileResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
type ClaimFile403JSONResponse Problem
func (response ClaimFile403JSONResponse) VisitClaimFileResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(403)
_, err := buf.WriteTo(w)
return err
}
type ReportFileRequestObject struct {
FileId int64 `json:"fileId"`
Body *ReportFileJSONRequestBody
}
type ReportFileResponseObject interface {
VisitReportFileResponse(w http.ResponseWriter) error
}
type ReportFile204Response struct {
}
func (response ReportFile204Response) VisitReportFileResponse(w http.ResponseWriter) error {
w.WriteHeader(204)
return nil
}
type ReportFile401JSONResponse struct{ ProblemJSONResponse }
func (response ReportFile401JSONResponse) VisitReportFileResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
type ReportFile403JSONResponse Problem
func (response ReportFile403JSONResponse) VisitReportFileResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(403)
_, err := buf.WriteTo(w)
return err
}
type ReportFile404JSONResponse Problem
func (response ReportFile404JSONResponse) VisitReportFileResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(404)
_, err := buf.WriteTo(w)
return err
}
type GetHealthRequestObject struct {
}
type GetHealthResponseObject interface {
VisitGetHealthResponse(w http.ResponseWriter) error
}
type GetHealth200JSONResponse Health
func (response GetHealth200JSONResponse) VisitGetHealthResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
_, err := buf.WriteTo(w)
return err
}
type ListRequestsRequestObject struct {
Params ListRequestsParams
}
type ListRequestsResponseObject interface {
VisitListRequestsResponse(w http.ResponseWriter) error
}
type ListRequests200JSONResponse []PreloadRequest
func (response ListRequests200JSONResponse) VisitListRequestsResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
_, err := buf.WriteTo(w)
return err
}
type ListRequests401JSONResponse struct{ ProblemJSONResponse }
func (response ListRequests401JSONResponse) VisitListRequestsResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
type CreateRequestRequestObject struct {
Body *CreateRequestJSONRequestBody
}
type CreateRequestResponseObject interface {
VisitCreateRequestResponse(w http.ResponseWriter) error
}
type CreateRequest201JSONResponse PreloadRequest
func (response CreateRequest201JSONResponse) VisitCreateRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(201)
_, err := buf.WriteTo(w)
return err
}
type CreateRequest400JSONResponse struct{ ProblemJSONResponse }
func (response CreateRequest400JSONResponse) VisitCreateRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
_, err := buf.WriteTo(w)
return err
}
type CreateRequest401JSONResponse Problem
func (response CreateRequest401JSONResponse) VisitCreateRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
type CreateRequest404JSONResponse Problem
func (response CreateRequest404JSONResponse) VisitCreateRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(404)
_, err := buf.WriteTo(w)
return err
}
type CancelRequestRequestObject struct {
Id int64 `json:"id"`
}
type CancelRequestResponseObject interface {
VisitCancelRequestResponse(w http.ResponseWriter) error
}
type CancelRequest200JSONResponse PreloadRequest
func (response CancelRequest200JSONResponse) VisitCancelRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
_, err := buf.WriteTo(w)
return err
}
type CancelRequest401JSONResponse struct{ ProblemJSONResponse }
func (response CancelRequest401JSONResponse) VisitCancelRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
type CancelRequest404JSONResponse Problem
func (response CancelRequest404JSONResponse) VisitCancelRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(404)
_, err := buf.WriteTo(w)
return err
}
type GetRequestRequestObject struct {
Id int64 `json:"id"`
}
type GetRequestResponseObject interface {
VisitGetRequestResponse(w http.ResponseWriter) error
}
type GetRequest200JSONResponse PreloadRequest
func (response GetRequest200JSONResponse) VisitGetRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
_, err := buf.WriteTo(w)
return err
}
type GetRequest401JSONResponse struct{ ProblemJSONResponse }
func (response GetRequest401JSONResponse) VisitGetRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
type GetRequest404JSONResponse Problem
func (response GetRequest404JSONResponse) VisitGetRequestResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(404)
_, err := buf.WriteTo(w)
return err
}
type SearchLibraryRequestObject struct {
Params SearchLibraryParams
}
type SearchLibraryResponseObject interface {
VisitSearchLibraryResponse(w http.ResponseWriter) error
}
type SearchLibrary200JSONResponse []MediaItem
func (response SearchLibrary200JSONResponse) VisitSearchLibraryResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(200)
_, err := buf.WriteTo(w)
return err
}
type SearchLibrary400JSONResponse struct{ ProblemJSONResponse }
func (response SearchLibrary400JSONResponse) VisitSearchLibraryResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(400)
_, err := buf.WriteTo(w)
return err
}
type SearchLibrary401JSONResponse Problem
func (response SearchLibrary401JSONResponse) VisitSearchLibraryResponse(w http.ResponseWriter) error {
var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(response); err != nil {
return err
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(401)
_, err := buf.WriteTo(w)
return err
}
// StrictServerInterface represents all server handlers.
type StrictServerInterface interface {
// ClaimFile Agent takes the next queued file
// (POST /v1/agent/claim)
ClaimFile(ctx context.Context, request ClaimFileRequestObject) (ClaimFileResponseObject, error)
// ReportFile Agent reports the result for a claimed file
// (POST /v1/agent/files/{fileId})
ReportFile(ctx context.Context, request ReportFileRequestObject) (ReportFileResponseObject, error)
// GetHealth Liveness and version
// (GET /v1/health)
GetHealth(ctx context.Context, request GetHealthRequestObject) (GetHealthResponseObject, error)
// ListRequests Recent requests, newest first
// (GET /v1/requests)
ListRequests(ctx context.Context, request ListRequestsRequestObject) (ListRequestsResponseObject, error)
// CreateRequest Ask for a movie or episodes to be cached
// (POST /v1/requests)
CreateRequest(ctx context.Context, request CreateRequestRequestObject) (CreateRequestResponseObject, error)
// CancelRequest Cancel the files of a request that are still queued
// (DELETE /v1/requests/{id})
CancelRequest(ctx context.Context, request CancelRequestRequestObject) (CancelRequestResponseObject, error)
// GetRequest One request with per-file progress
// (GET /v1/requests/{id})
GetRequest(ctx context.Context, request GetRequestRequestObject) (GetRequestResponseObject, error)
// SearchLibrary Search movies and series in Jellyfin
// (GET /v1/search)
SearchLibrary(ctx context.Context, request SearchLibraryRequestObject) (SearchLibraryResponseObject, error)
}
type StrictHandlerFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request, request any) (any, 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 {
if options.RequestErrorHandlerFunc == nil {
options.RequestErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusBadRequest)
}
}
if options.ResponseErrorHandlerFunc == nil {
options.ResponseErrorHandlerFunc = func(w http.ResponseWriter, r *http.Request, err error) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
return &strictHandler{ssi: ssi, middlewares: middlewares, options: options}
}
type strictHandler struct {
ssi StrictServerInterface
middlewares []StrictMiddlewareFunc
options StrictHTTPServerOptions
}
// ClaimFile operation middleware
func (sh *strictHandler) ClaimFile(w http.ResponseWriter, r *http.Request) {
var request ClaimFileRequestObject
var body ClaimFileJSONRequestBody
if err := runtime.BindJSONBody(r, &body); err != nil {
sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
return
}
request.Body = &body
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.ClaimFile(ctx, request.(ClaimFileRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "ClaimFile")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(ClaimFileResponseObject); ok {
if err := validResponse.VisitClaimFileResponse(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))
}
}
// ReportFile operation middleware
func (sh *strictHandler) ReportFile(w http.ResponseWriter, r *http.Request, fileId int64) {
var request ReportFileRequestObject
request.FileId = fileId
var body ReportFileJSONRequestBody
if err := runtime.BindJSONBody(r, &body); err != nil {
sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
return
}
request.Body = &body
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.ReportFile(ctx, request.(ReportFileRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "ReportFile")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(ReportFileResponseObject); ok {
if err := validResponse.VisitReportFileResponse(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))
}
}
// GetHealth operation middleware
func (sh *strictHandler) GetHealth(w http.ResponseWriter, r *http.Request) {
var request GetHealthRequestObject
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.GetHealth(ctx, request.(GetHealthRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "GetHealth")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(GetHealthResponseObject); ok {
if err := validResponse.VisitGetHealthResponse(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))
}
}
// ListRequests operation middleware
func (sh *strictHandler) ListRequests(w http.ResponseWriter, r *http.Request, params ListRequestsParams) {
var request ListRequestsRequestObject
request.Params = params
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.ListRequests(ctx, request.(ListRequestsRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "ListRequests")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(ListRequestsResponseObject); ok {
if err := validResponse.VisitListRequestsResponse(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))
}
}
// CreateRequest operation middleware
func (sh *strictHandler) CreateRequest(w http.ResponseWriter, r *http.Request) {
var request CreateRequestRequestObject
var body CreateRequestJSONRequestBody
if err := runtime.BindJSONBody(r, &body); err != nil {
sh.options.RequestErrorHandlerFunc(w, r, fmt.Errorf("can't decode JSON body: %w", err))
return
}
request.Body = &body
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.CreateRequest(ctx, request.(CreateRequestRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "CreateRequest")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(CreateRequestResponseObject); ok {
if err := validResponse.VisitCreateRequestResponse(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))
}
}
// CancelRequest operation middleware
func (sh *strictHandler) CancelRequest(w http.ResponseWriter, r *http.Request, id int64) {
var request CancelRequestRequestObject
request.Id = id
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.CancelRequest(ctx, request.(CancelRequestRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "CancelRequest")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(CancelRequestResponseObject); ok {
if err := validResponse.VisitCancelRequestResponse(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))
}
}
// GetRequest operation middleware
func (sh *strictHandler) GetRequest(w http.ResponseWriter, r *http.Request, id int64) {
var request GetRequestRequestObject
request.Id = id
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.GetRequest(ctx, request.(GetRequestRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "GetRequest")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(GetRequestResponseObject); ok {
if err := validResponse.VisitGetRequestResponse(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))
}
}
// SearchLibrary operation middleware
func (sh *strictHandler) SearchLibrary(w http.ResponseWriter, r *http.Request, params SearchLibraryParams) {
var request SearchLibraryRequestObject
request.Params = params
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
return sh.ssi.SearchLibrary(ctx, request.(SearchLibraryRequestObject))
}
for _, middleware := range sh.middlewares {
handler = middleware(handler, "SearchLibrary")
}
response, err := handler(r.Context(), w, r, request)
if err != nil {
sh.options.ResponseErrorHandlerFunc(w, r, err)
} else if validResponse, ok := response.(SearchLibraryResponseObject); ok {
if err := validResponse.VisitSearchLibraryResponse(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, compressed with deflate, json marshaled OpenAPI spec.
// Stored as a slice of fixed-width chunks rather than one concatenated
// const string: with thousands of chunks the chained `+` fold is several
// times slower for the Go compiler than parsing a slice literal.
var swaggerSpec = []string{
"zFlfc9s4Dv8qGN49JDeK7bjt7Y77lHa3d91tt72m132oM2dagi02EqmSlB1vxt/9BiT1z5YTZ/tn9ikK",
"JYIg8APwA3zLYpUXSqK0hk1umUZTKGnQ/fNWq3mGOT3GSlqUlh55UWQi5lYoOfxklKQ1E6eYc3r6u8YF",
"m7C/DRu5Q//WDCt52+02YgmaWIuCxLAJ+1lrpRmth49J1sUSpf1Fzem50KpAbYXXbCEyfJm4J6VzbtmE",
"CWn/+ZhFzG4K9P/iEjXbRqzgNqVPwxtjtZBLemHEH/hsY9EcJWgbMY2fS6ExYZOPlQpBfFvYVb1XzT9h",
"bOmo5xkX+Tv8XKKx+9fhdFF/H7zheZHR5lVhzpJYl8KONYt2td/RppLQe7ZGbvHg4VgIoxL/vOMU/wZk",
"mc9RG1gLmwoJM4PcKDljERMWc7cxF1LkZc4moz4PhBWuNd+wrd/2Mtk/8BfMss1CSKAPQCSw0CqH4ep8",
"aJDrON03Q8Q+hT3/NajvkFga1CB5jrBOlUFYcxunUGi11GgMJBiLBA1MmcQbO2V9J9Gb/RN+wxsLv0Ep",
"nURMoLInLJSGjnYRy/mNN9N4FDU2O++zmVQWnWX5zSuUS4Lwk9GoRy3tHYvJs82+dr+nCri5RgIqDpYD",
"4PCTMLHSSWMRNpFllkXtk857T/J+v8/dO8gMvu7q2QfTFyLDd1go3YPReRWl3du5eAONPCAlVTk6s9tU",
"GKAIZdExGQJd9ulLERpNmTmFUNJ9P7KYk5dZxHhGB2/+Vy8suMiwHYIHYjXIPGSDS8ttadpHfi6x9Ceg",
"jVMSGbHdU2lFxugfpbJeLT7PsEehiP0beWbTfUOb5vA6EanrvmhYoTbCo+Hu6waRzY6+i7/GRPCXFvN9",
"lZqL7Pn/Bc8olFOUYFP0WSMTKzSgSmtEgm7ZmwoWKktQm+Yuc6Uy5NIlpCOSUZ8RMjHXXG/u2By+AKoS",
"UGhciJsIXCQOc7rzePhBJKjM0K5MqtamN/G4IL09FJDPVSlt6/1e4r27KjvTv6cPtxHbINd9onaDOmFB",
"rXBGxPrwtuPf90GbCte5WgnaalCLTt1sbvhWY6Z4QnHRU7kOhq0LFMo0xxb3CgIPoBNdh78l/3IDBlHC",
"fAM1ALhMYI3zhK/u9PtwMBj0+f5hHCVqBfBdPm/lGUKJsH3R5bT9ietreM2tRQ2Xo/HPox/7tCyLhFtM",
"LmxHS1o7syLH/S19eApEymsTNXnjbmYVEHKQ3sQaH6Za5Kid21vTm7tZbQPRPq5zLK4aUrSfAAIXuK/2",
"770/Dg3Bdj2AOMJrdX2v/NbWqeXFxg+Vgfu9WbccB2K9qUs+bUA4z4BETDqEy1eG0gi5BEfe7oOhP6RP",
"r66J7qnNiZLo8Kyt4Flvje4lCQbjUgu7uSS/BOKDXKO+KH3KcQ5zpcstN/dJrS18WyXkQvXQQK5zVws/",
"vL0El398VYQTn5oGS5VgXqBWOlFLHCi9PIU5LpRGMCpHJQNjRuP+pz5gOZjKqbyAOBMoLZwQ7wrOcUdV",
"PHOu7Cl4/o7GvdkrjpQjHSaAV+6cypMpewlrkWX+5E4m8oUPxlN2OoD3KcLF25eg0aiMir+wYFW4ZhAr",
"E3Cecgrkg6mkTYWPXHDNEyhZWyimbs34HUlLBBE+LwFsqlW5TN2WTMU8Ax1nSuJUOsNGYBS924CxGnnu",
"+WklX0hjibSqBagVarfuuGtZZEJeO8O+kdkGXlOFNHAiZJyVCeH4QvO5iOGSasapU4o227WC9x+CPWkH",
"1wh1RX4Kyqaoq4tonErtiDYmVLJmHbo4824tbTqBGf1RWvzhuv0JPHOwg2k5Gj2KrbpG6R5xNoDnHgVu",
"0UDON9RfON2864P9nG8BZVIoIa15OpV8ubNPycxvnlHj514P/0Fa1Tlmwpxvz4L/WtRyws4Ho8GIIlYV",
"KHkh2IQ9GowGj0J9cUHVyHWOpqVC+dpBKcddljKx79pfiHZae6aSzVcbiHSmAttuNrK6xG3UHciMR6Ov",
"dnY9XOmZxlw4qFAQuaxG5hyPHvf0vsolghAo9Nnj0fmhg+ubNHMg+v7RA76nHFnmuWPcfjoEll+HrEIZ",
"vh2yLGKWL009HWFXtL/xPX1jhrd+jrN1IOCa52hR06ZbJuiKgZR4Ct4Mfbp+ilo2v3+OdBUdgJvvfr8h",
"3lot9lFo63H5O6Sk/j2cTd8//jJw+Czn4eG7bjcd4D7B34uTtG6Sl9jjrn+hDW30NwzTcEJPkL75tUMa",
"2OTjVdsCr8QKJRpfuKr8WN2s4kwH7/ZKGPuu+ijqjYzPJepNExoNXT/qXjuccxv1S81ELmxHaIIL7kYy",
"41FrnuYGVncN1LZXX+ikh/QCdUrfbQf6vfjQSOog/R3GHureWRFIXKOxsBDa2Ba2qw/Y1bbJPzvjFBcb",
"riuP6ilvBLNqojlzWJpRop05hiGWUmlMBlPpt3pGHsFSrJC4YGwzqucIajGZyrNaJpysU5VhoHGnESin",
"As+yjRsyt488sW5eizuzaLUAm3JbiXjqxHvNTupqcHAsO2u3CbPTwVT+TsdKr6tjeFF9HwiQM1QQ3RkT",
"eDSruJd0fYfZEenpyg6b6MzhvxGj6JxxVJI//4q/73TRv4/2//jyfBKYqJ+gVgM6QlTO9TUmMPNLM9Bi",
"mVrga76hoQo51uXoUx80oweWk/PvVn7MNSyaaAKlG/xZBfNqKNkfnztJengrPD9JMEM/CNgBlusq28D6",
"RsXofgc/Dw3urovDQA6M5ZW/T7+zT7xqDkNeN7Vo2k2fTAiBxlLLWbf1venzEB34S7jgza/f2bBvJNZm",
"dNm7QH3mGojq57WDZehewi2+mGyHYAo/IB7iO5fu9aswzt/TrGvh99SFUhx7oRTpLOqlL5/v1D4XsvrB",
"bdwzD+pnRGHcfhxaWrP9P8GwztsMa/zkr0Cwmt+JjuBWr/3EKoJ5Q4i+ed3ohIaHlS8CnokHSiFkPQVr",
"BUf1c9LVdofZdweBH6/I2Ab1qh+fSsJmhZl1s8dSZ2FAOBkOz8c/0HxkcD758Xz8hG2j3a3tMVXUDKfW",
"yzM3n7KllLgvdTT4geSOg9Sr+ka3Dcr8zbZRvVRngtaab8C2V9v/DwA=",
}
// decodeSpec returns the embedded OpenAPI spec as raw JSON bytes,
// after base64-decoding and flate-decompressing the embedded blob.
func decodeSpec() ([]byte, error) {
encoded := strings.Join(swaggerSpec, "")
compressed, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return nil, fmt.Errorf("error base64 decoding spec: %w", err)
}
zr := flate.NewReader(bytes.NewReader(compressed))
var buf bytes.Buffer
if _, err := buf.ReadFrom(zr); err != nil {
return nil, fmt.Errorf("read flate: %w", err)
}
if err := zr.Close(); err != nil {
return nil, fmt.Errorf("close flate reader: %w", err)
}
return buf.Bytes(), nil
}
var rawSpec = decodeSpecCached()
// a naive cache of the decoded OpenAPI 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) {
res := make(map[string]func() ([]byte, error))
if len(pathToFile) > 0 {
res[pathToFile] = rawSpec
}
return res
}
// GetSpec returns the OpenAPI specification corresponding to the generated
// code in this file. External references in the spec are resolved through
// PathToRawSpec; externally-referenced files must be embedded in their
// corresponding Go packages (via the import-mapping feature). URL-based
// external refs are not supported.
func GetSpec() (swagger *openapi3.T, err error) {
resolvePath := PathToRawSpec("")
loader := openapi3.NewLoader()
loader.IsExternalRefsAllowed = true
loader.ReadFromURIFunc = func(loader *openapi3.Loader, url *url.URL) ([]byte, error) {
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
}
// GetSpecJSON returns the raw JSON bytes of the embedded OpenAPI
// specification: decompressed but not unmarshaled. External references
// are not resolved here; the bytes are the spec exactly as embedded by
// codegen. The result is cached at package init time, so repeated calls
// are cheap.
func GetSpecJSON() ([]byte, error) {
return rawSpec()
}
// GetSwagger returns the OpenAPI specification corresponding to the
// generated code in this file.
//
// Deprecated: GetSwagger predates kin-openapi renaming openapi3.Swagger
// to openapi3.T. Use [GetSpec] instead. This wrapper is retained for
// backwards compatibility.
func GetSwagger() (*openapi3.T, error) {
return GetSpec()
}