The proxy leases a not-yet-loaded model's size (+20%) and forces CPU-only with 4 threads on a CPU grant; loaded models, other endpoints and a down broker pass through. Spread leases let a model use both cards, as Ollama does with gemma4-12b (8.4 GB > the 1080's 8 GB). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1745 lines
52 KiB
Go
1745 lines
52 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"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/getkin/kin-openapi/openapi3"
|
|
"github.com/oapi-codegen/runtime"
|
|
)
|
|
|
|
// Defines values for GrantDevice.
|
|
const (
|
|
Cpu GrantDevice = "cpu"
|
|
Gpu GrantDevice = "gpu"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the GrantDevice enum.
|
|
func (e GrantDevice) Valid() bool {
|
|
switch e {
|
|
case Cpu:
|
|
return true
|
|
case Gpu:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for HealthStatus.
|
|
const (
|
|
NoSample HealthStatus = "no_sample"
|
|
Ok HealthStatus = "ok"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the HealthStatus enum.
|
|
func (e HealthStatus) Valid() bool {
|
|
switch e {
|
|
case NoSample:
|
|
return true
|
|
case Ok:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// Defines values for Priority.
|
|
const (
|
|
Batch Priority = "batch"
|
|
Interactive Priority = "interactive"
|
|
Realtime Priority = "realtime"
|
|
)
|
|
|
|
// Valid indicates whether the value is a known member of the Priority enum.
|
|
func (e Priority) Valid() bool {
|
|
switch e {
|
|
case Batch:
|
|
return true
|
|
case Interactive:
|
|
return true
|
|
case Realtime:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
// GpuStatus defines model for GpuStatus.
|
|
type GpuStatus struct {
|
|
FreeMb int `json:"free_mb"`
|
|
Index int `json:"index"`
|
|
ReserveMb int `json:"reserve_mb"`
|
|
TotalMb int `json:"total_mb"`
|
|
UsedMb int `json:"used_mb"`
|
|
}
|
|
|
|
// Grant defines model for Grant.
|
|
type Grant struct {
|
|
Device GrantDevice `json:"device"`
|
|
ExpiresAt *time.Time `json:"expires_at,omitempty"`
|
|
|
|
// Gpu GPU index, -1 for the CPU.
|
|
Gpu int `json:"gpu"`
|
|
|
|
// LeaseId Absent for CPU grants.
|
|
LeaseId *string `json:"lease_id,omitempty"`
|
|
}
|
|
|
|
// GrantDevice defines model for Grant.Device.
|
|
type GrantDevice string
|
|
|
|
// Health defines model for Health.
|
|
type Health struct {
|
|
Status HealthStatus `json:"status"`
|
|
}
|
|
|
|
// HealthStatus defines model for Health.Status.
|
|
type HealthStatus string
|
|
|
|
// LeaseInfo defines model for LeaseInfo.
|
|
type LeaseInfo struct {
|
|
Client string `json:"client"`
|
|
ExpiresAt time.Time `json:"expires_at"`
|
|
Gpu int `json:"gpu"`
|
|
GrantedAt time.Time `json:"granted_at"`
|
|
Id string `json:"id"`
|
|
VramMb int `json:"vram_mb"`
|
|
}
|
|
|
|
// LeaseRequest defines model for LeaseRequest.
|
|
type LeaseRequest struct {
|
|
// Client Who is asking, e.g. ollama-proxy, genres-guess.
|
|
Client string `json:"client"`
|
|
CpuFallback *bool `json:"cpu_fallback,omitempty"`
|
|
|
|
// MaxWaitS 0 or absent: wait as long as it takes.
|
|
MaxWaitS *int `json:"max_wait_s,omitempty"`
|
|
|
|
// Prefer GPU indexes to try first.
|
|
Prefer *[]int `json:"prefer,omitempty"`
|
|
Priority Priority `json:"priority"`
|
|
|
|
// Spread May be split across GPUs (Ollama splits a model that fits no single card).
|
|
Spread *bool `json:"spread,omitempty"`
|
|
VramMb int `json:"vram_mb"`
|
|
}
|
|
|
|
// Priority defines model for Priority.
|
|
type Priority string
|
|
|
|
// Problem defines model for Problem.
|
|
type Problem struct {
|
|
Error string `json:"error"`
|
|
}
|
|
|
|
// Status defines model for Status.
|
|
type Status struct {
|
|
Gpus []GpuStatus `json:"gpus"`
|
|
Leases []LeaseInfo `json:"leases"`
|
|
TtlS int `json:"ttl_s"`
|
|
Waiting []WaitInfo `json:"waiting"`
|
|
}
|
|
|
|
// WaitInfo defines model for WaitInfo.
|
|
type WaitInfo struct {
|
|
Client string `json:"client"`
|
|
Priority Priority `json:"priority"`
|
|
Since time.Time `json:"since"`
|
|
VramMb int `json:"vram_mb"`
|
|
}
|
|
|
|
// LeaseId defines model for LeaseId.
|
|
type LeaseId = string
|
|
|
|
// AcquireLeaseJSONRequestBody defines body for AcquireLease for application/json ContentType.
|
|
type AcquireLeaseJSONRequestBody = LeaseRequest
|
|
|
|
// 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 {
|
|
|
|
// Health performs a GET /v1/health (the `Health` operationId) request.
|
|
Health(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
|
|
|
|
// AcquireLeaseWithBody performs a POST /v1/leases (the `AcquireLease` operationId) request,
|
|
// with any type of body and a specified content type.
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
AcquireLeaseWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
|
|
|
|
// AcquireLease performs a POST /v1/leases (the `AcquireLease` operationId) request.
|
|
// Takes a body of the `application/json` content type.
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
AcquireLease(ctx context.Context, body AcquireLeaseJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
|
|
|
|
// ReleaseLease performs a DELETE /v1/leases/{id} (the `ReleaseLease` operationId) request.
|
|
ReleaseLease(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*http.Response, error)
|
|
|
|
// RenewLease performs a POST /v1/leases/{id}/renew (the `RenewLease` operationId) request.
|
|
RenewLease(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*http.Response, error)
|
|
|
|
// Status performs a GET /v1/status (the `Status` operationId) request.
|
|
Status(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
|
|
}
|
|
|
|
// Health performs a GET /v1/health (the `Health` operationId) request.
|
|
func (c *Client) Health(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
|
req, err := NewHealthRequest(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)
|
|
}
|
|
|
|
// AcquireLeaseWithBody performs a POST /v1/leases (the `AcquireLease` operationId) request,
|
|
// with any type of body and a specified content type.
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
func (c *Client) AcquireLeaseWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
|
req, err := NewAcquireLeaseRequestWithBody(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)
|
|
}
|
|
|
|
// AcquireLease performs a POST /v1/leases (the `AcquireLease` operationId) request.
|
|
// Takes a body of the `application/json` content type.
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
func (c *Client) AcquireLease(ctx context.Context, body AcquireLeaseJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
|
req, err := NewAcquireLeaseRequest(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)
|
|
}
|
|
|
|
// ReleaseLease performs a DELETE /v1/leases/{id} (the `ReleaseLease` operationId) request.
|
|
func (c *Client) ReleaseLease(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
|
req, err := NewReleaseLeaseRequest(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)
|
|
}
|
|
|
|
// RenewLease performs a POST /v1/leases/{id}/renew (the `RenewLease` operationId) request.
|
|
func (c *Client) RenewLease(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
|
req, err := NewRenewLeaseRequest(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)
|
|
}
|
|
|
|
// Status performs a GET /v1/status (the `Status` operationId) request.
|
|
func (c *Client) Status(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error) {
|
|
req, err := NewStatusRequest(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)
|
|
}
|
|
|
|
// NewHealthRequest constructs an http.Request for the Health method
|
|
func NewHealthRequest(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
|
|
}
|
|
|
|
// NewAcquireLeaseRequest calls the generic AcquireLease builder with application/json body
|
|
func NewAcquireLeaseRequest(server string, body AcquireLeaseJSONRequestBody) (*http.Request, error) {
|
|
var bodyReader io.Reader
|
|
buf, err := json.Marshal(body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
bodyReader = bytes.NewReader(buf)
|
|
return NewAcquireLeaseRequestWithBody(server, "application/json", bodyReader)
|
|
}
|
|
|
|
// NewAcquireLeaseRequestWithBody constructs an http.Request for the AcquireLease method, with any body, and a specified content type
|
|
func NewAcquireLeaseRequestWithBody(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/leases")
|
|
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
|
|
}
|
|
|
|
// NewReleaseLeaseRequest constructs an http.Request for the ReleaseLease method
|
|
func NewReleaseLeaseRequest(server string, id LeaseId) (*http.Request, error) {
|
|
var err error
|
|
|
|
var pathParam0 string
|
|
|
|
pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
serverURL, err := url.Parse(server)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
operationPath := fmt.Sprintf("/v1/leases/%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
|
|
}
|
|
|
|
// NewRenewLeaseRequest constructs an http.Request for the RenewLease method
|
|
func NewRenewLeaseRequest(server string, id LeaseId) (*http.Request, error) {
|
|
var err error
|
|
|
|
var pathParam0 string
|
|
|
|
pathParam0, err = runtime.StyleParamWithOptions("simple", false, "id", id, runtime.StyleParamOptions{ParamLocation: runtime.ParamLocationPath, Type: "string", Format: ""})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
serverURL, err := url.Parse(server)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
operationPath := fmt.Sprintf("/v1/leases/%s/renew", 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(), nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return req, nil
|
|
}
|
|
|
|
// NewStatusRequest constructs an http.Request for the Status method
|
|
func NewStatusRequest(server string) (*http.Request, error) {
|
|
var err error
|
|
|
|
serverURL, err := url.Parse(server)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
operationPath := fmt.Sprintf("/v1/status")
|
|
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
|
|
}
|
|
|
|
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 {
|
|
|
|
// HealthWithResponse performs a GET /v1/health (the `Health` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
HealthWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*HealthResponse, error)
|
|
|
|
// AcquireLeaseWithBodyWithResponse performs a POST /v1/leases (the `AcquireLease` operationId) request,
|
|
// with any type of body and a specified content type.
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
AcquireLeaseWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AcquireLeaseResponse, error)
|
|
|
|
// AcquireLeaseWithResponse performs a POST /v1/leases (the `AcquireLease` operationId) request.
|
|
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
AcquireLeaseWithResponse(ctx context.Context, body AcquireLeaseJSONRequestBody, reqEditors ...RequestEditorFn) (*AcquireLeaseResponse, error)
|
|
|
|
// ReleaseLeaseWithResponse performs a DELETE /v1/leases/{id} (the `ReleaseLease` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
ReleaseLeaseWithResponse(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*ReleaseLeaseResponse, error)
|
|
|
|
// RenewLeaseWithResponse performs a POST /v1/leases/{id}/renew (the `RenewLease` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
RenewLeaseWithResponse(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*RenewLeaseResponse, error)
|
|
|
|
// StatusWithResponse performs a GET /v1/status (the `Status` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
StatusWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*StatusResponse, error)
|
|
}
|
|
|
|
type HealthResponse 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 HealthResponse) GetJSON200() *Health {
|
|
return r.JSON200
|
|
}
|
|
|
|
// GetBody returns the raw response body bytes
|
|
func (r HealthResponse) GetBody() []byte {
|
|
return r.Body
|
|
}
|
|
|
|
// Status returns HTTPResponse.Status
|
|
func (r HealthResponse) Status() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Status
|
|
}
|
|
return http.StatusText(0)
|
|
}
|
|
|
|
// StatusCode returns HTTPResponse.StatusCode
|
|
func (r HealthResponse) 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 HealthResponse) ContentType() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Header.Get("Content-Type")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
type AcquireLeaseResponse struct {
|
|
Body []byte
|
|
HTTPResponse *http.Response
|
|
// JSON200 the response for an HTTP 200 `application/json` response
|
|
JSON200 *Grant
|
|
// JSON400 the response for an HTTP 400 `application/json` response
|
|
JSON400 *Problem
|
|
// JSON413 the response for an HTTP 413 `application/json` response
|
|
JSON413 *Problem
|
|
// JSON503 the response for an HTTP 503 `application/json` response
|
|
JSON503 *Problem
|
|
}
|
|
|
|
// GetJSON200 returns the response for an HTTP 200 `application/json` response
|
|
func (r AcquireLeaseResponse) GetJSON200() *Grant {
|
|
return r.JSON200
|
|
}
|
|
|
|
// GetJSON400 returns the response for an HTTP 400 `application/json` response
|
|
func (r AcquireLeaseResponse) GetJSON400() *Problem {
|
|
return r.JSON400
|
|
}
|
|
|
|
// GetJSON413 returns the response for an HTTP 413 `application/json` response
|
|
func (r AcquireLeaseResponse) GetJSON413() *Problem {
|
|
return r.JSON413
|
|
}
|
|
|
|
// GetJSON503 returns the response for an HTTP 503 `application/json` response
|
|
func (r AcquireLeaseResponse) GetJSON503() *Problem {
|
|
return r.JSON503
|
|
}
|
|
|
|
// GetBody returns the raw response body bytes
|
|
func (r AcquireLeaseResponse) GetBody() []byte {
|
|
return r.Body
|
|
}
|
|
|
|
// Status returns HTTPResponse.Status
|
|
func (r AcquireLeaseResponse) Status() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Status
|
|
}
|
|
return http.StatusText(0)
|
|
}
|
|
|
|
// StatusCode returns HTTPResponse.StatusCode
|
|
func (r AcquireLeaseResponse) 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 AcquireLeaseResponse) ContentType() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Header.Get("Content-Type")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
type ReleaseLeaseResponse struct {
|
|
Body []byte
|
|
HTTPResponse *http.Response
|
|
}
|
|
|
|
// GetBody returns the raw response body bytes
|
|
func (r ReleaseLeaseResponse) GetBody() []byte {
|
|
return r.Body
|
|
}
|
|
|
|
// Status returns HTTPResponse.Status
|
|
func (r ReleaseLeaseResponse) Status() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Status
|
|
}
|
|
return http.StatusText(0)
|
|
}
|
|
|
|
// StatusCode returns HTTPResponse.StatusCode
|
|
func (r ReleaseLeaseResponse) 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 ReleaseLeaseResponse) ContentType() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Header.Get("Content-Type")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
type RenewLeaseResponse struct {
|
|
Body []byte
|
|
HTTPResponse *http.Response
|
|
// JSON404 the response for an HTTP 404 `application/json` response
|
|
JSON404 *Problem
|
|
}
|
|
|
|
// GetJSON404 returns the response for an HTTP 404 `application/json` response
|
|
func (r RenewLeaseResponse) GetJSON404() *Problem {
|
|
return r.JSON404
|
|
}
|
|
|
|
// GetBody returns the raw response body bytes
|
|
func (r RenewLeaseResponse) GetBody() []byte {
|
|
return r.Body
|
|
}
|
|
|
|
// Status returns HTTPResponse.Status
|
|
func (r RenewLeaseResponse) Status() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Status
|
|
}
|
|
return http.StatusText(0)
|
|
}
|
|
|
|
// StatusCode returns HTTPResponse.StatusCode
|
|
func (r RenewLeaseResponse) 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 RenewLeaseResponse) ContentType() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Header.Get("Content-Type")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
type StatusResponse struct {
|
|
Body []byte
|
|
HTTPResponse *http.Response
|
|
// JSON200 the response for an HTTP 200 `application/json` response
|
|
JSON200 *Status
|
|
}
|
|
|
|
// GetJSON200 returns the response for an HTTP 200 `application/json` response
|
|
func (r StatusResponse) GetJSON200() *Status {
|
|
return r.JSON200
|
|
}
|
|
|
|
// GetBody returns the raw response body bytes
|
|
func (r StatusResponse) GetBody() []byte {
|
|
return r.Body
|
|
}
|
|
|
|
// Status returns HTTPResponse.Status
|
|
func (r StatusResponse) Status() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Status
|
|
}
|
|
return http.StatusText(0)
|
|
}
|
|
|
|
// StatusCode returns HTTPResponse.StatusCode
|
|
func (r StatusResponse) 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 StatusResponse) ContentType() string {
|
|
if r.HTTPResponse != nil {
|
|
return r.HTTPResponse.Header.Get("Content-Type")
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// HealthWithResponse performs a GET /v1/health (the `Health` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
func (c *ClientWithResponses) HealthWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*HealthResponse, error) {
|
|
rsp, err := c.Health(ctx, reqEditors...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseHealthResponse(rsp)
|
|
}
|
|
|
|
// AcquireLeaseWithBodyWithResponse performs a POST /v1/leases (the `AcquireLease` operationId) request,
|
|
// with any type of body and a specified content type.
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
func (c *ClientWithResponses) AcquireLeaseWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*AcquireLeaseResponse, error) {
|
|
rsp, err := c.AcquireLeaseWithBody(ctx, contentType, body, reqEditors...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseAcquireLeaseResponse(rsp)
|
|
}
|
|
|
|
// AcquireLeaseWithResponse performs a POST /v1/leases (the `AcquireLease` operationId) request.
|
|
// Takes a body of the `application/json` content type, and returns a wrapper object for the known response body format(s).
|
|
//
|
|
// Blocks until a GPU is free, the CPU fallback applies, or max_wait_s passes.
|
|
func (c *ClientWithResponses) AcquireLeaseWithResponse(ctx context.Context, body AcquireLeaseJSONRequestBody, reqEditors ...RequestEditorFn) (*AcquireLeaseResponse, error) {
|
|
rsp, err := c.AcquireLease(ctx, body, reqEditors...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseAcquireLeaseResponse(rsp)
|
|
}
|
|
|
|
// ReleaseLeaseWithResponse performs a DELETE /v1/leases/{id} (the `ReleaseLease` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
func (c *ClientWithResponses) ReleaseLeaseWithResponse(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*ReleaseLeaseResponse, error) {
|
|
rsp, err := c.ReleaseLease(ctx, id, reqEditors...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseReleaseLeaseResponse(rsp)
|
|
}
|
|
|
|
// RenewLeaseWithResponse performs a POST /v1/leases/{id}/renew (the `RenewLease` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
func (c *ClientWithResponses) RenewLeaseWithResponse(ctx context.Context, id LeaseId, reqEditors ...RequestEditorFn) (*RenewLeaseResponse, error) {
|
|
rsp, err := c.RenewLease(ctx, id, reqEditors...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseRenewLeaseResponse(rsp)
|
|
}
|
|
|
|
// StatusWithResponse performs a GET /v1/status (the `Status` operationId) request.
|
|
//
|
|
// Returns a wrapper object for the known response body format(s).
|
|
func (c *ClientWithResponses) StatusWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*StatusResponse, error) {
|
|
rsp, err := c.Status(ctx, reqEditors...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return ParseStatusResponse(rsp)
|
|
}
|
|
|
|
// ParseHealthResponse parses an HTTP response from a HealthWithResponse call
|
|
func ParseHealthResponse(rsp *http.Response) (*HealthResponse, error) {
|
|
bodyBytes, err := io.ReadAll(rsp.Body)
|
|
defer func() { _ = rsp.Body.Close() }()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := &HealthResponse{
|
|
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
|
|
}
|
|
|
|
// ParseAcquireLeaseResponse parses an HTTP response from a AcquireLeaseWithResponse call
|
|
func ParseAcquireLeaseResponse(rsp *http.Response) (*AcquireLeaseResponse, error) {
|
|
bodyBytes, err := io.ReadAll(rsp.Body)
|
|
defer func() { _ = rsp.Body.Close() }()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := &AcquireLeaseResponse{
|
|
Body: bodyBytes,
|
|
HTTPResponse: rsp,
|
|
}
|
|
|
|
switch {
|
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
|
|
var dest Grant
|
|
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 == 413:
|
|
var dest Problem
|
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
|
return nil, err
|
|
}
|
|
response.JSON413 = &dest
|
|
|
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 503:
|
|
var dest Problem
|
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
|
return nil, err
|
|
}
|
|
response.JSON503 = &dest
|
|
|
|
}
|
|
|
|
return response, nil
|
|
}
|
|
|
|
// ParseReleaseLeaseResponse parses an HTTP response from a ReleaseLeaseWithResponse call
|
|
func ParseReleaseLeaseResponse(rsp *http.Response) (*ReleaseLeaseResponse, error) {
|
|
bodyBytes, err := io.ReadAll(rsp.Body)
|
|
defer func() { _ = rsp.Body.Close() }()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := &ReleaseLeaseResponse{
|
|
Body: bodyBytes,
|
|
HTTPResponse: rsp,
|
|
}
|
|
|
|
return response, nil
|
|
}
|
|
|
|
// ParseRenewLeaseResponse parses an HTTP response from a RenewLeaseWithResponse call
|
|
func ParseRenewLeaseResponse(rsp *http.Response) (*RenewLeaseResponse, error) {
|
|
bodyBytes, err := io.ReadAll(rsp.Body)
|
|
defer func() { _ = rsp.Body.Close() }()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := &RenewLeaseResponse{
|
|
Body: bodyBytes,
|
|
HTTPResponse: rsp,
|
|
}
|
|
|
|
switch {
|
|
case rsp.StatusCode == 204:
|
|
break // No content-type
|
|
|
|
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
|
|
}
|
|
|
|
// ParseStatusResponse parses an HTTP response from a StatusWithResponse call
|
|
func ParseStatusResponse(rsp *http.Response) (*StatusResponse, error) {
|
|
bodyBytes, err := io.ReadAll(rsp.Body)
|
|
defer func() { _ = rsp.Body.Close() }()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
response := &StatusResponse{
|
|
Body: bodyBytes,
|
|
HTTPResponse: rsp,
|
|
}
|
|
|
|
switch {
|
|
case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200:
|
|
var dest Status
|
|
if err := json.Unmarshal(bodyBytes, &dest); err != nil {
|
|
return nil, err
|
|
}
|
|
response.JSON200 = &dest
|
|
|
|
}
|
|
|
|
return response, nil
|
|
}
|
|
|
|
// ServerInterface represents all server handlers.
|
|
type ServerInterface interface {
|
|
|
|
// (GET /v1/health)
|
|
Health(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (POST /v1/leases)
|
|
AcquireLease(w http.ResponseWriter, r *http.Request)
|
|
|
|
// (DELETE /v1/leases/{id})
|
|
ReleaseLease(w http.ResponseWriter, r *http.Request, id LeaseId)
|
|
|
|
// (POST /v1/leases/{id}/renew)
|
|
RenewLease(w http.ResponseWriter, r *http.Request, id LeaseId)
|
|
|
|
// (GET /v1/status)
|
|
Status(w http.ResponseWriter, r *http.Request)
|
|
}
|
|
|
|
// 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
|
|
|
|
// Health operation middleware
|
|
func (siw *ServerInterfaceWrapper) Health(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.Health(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// AcquireLease operation middleware
|
|
func (siw *ServerInterfaceWrapper) AcquireLease(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.AcquireLease(w, r)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// ReleaseLease operation middleware
|
|
func (siw *ServerInterfaceWrapper) ReleaseLease(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "id" -------------
|
|
var id LeaseId
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", r.PathValue("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", 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.ReleaseLease(w, r, id)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// RenewLease operation middleware
|
|
func (siw *ServerInterfaceWrapper) RenewLease(w http.ResponseWriter, r *http.Request) {
|
|
|
|
var err error
|
|
_ = err
|
|
|
|
// ------------- Path parameter "id" -------------
|
|
var id LeaseId
|
|
|
|
err = runtime.BindStyledParameterWithOptions("simple", "id", r.PathValue("id"), &id, runtime.BindStyledParameterOptions{ParamLocation: runtime.ParamLocationPath, Explode: false, Required: true, Type: "string", Format: "", 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.RenewLease(w, r, id)
|
|
}))
|
|
|
|
for _, middleware := range siw.HandlerMiddlewares {
|
|
handler = middleware(handler)
|
|
}
|
|
|
|
handler.ServeHTTP(w, r)
|
|
}
|
|
|
|
// Status operation middleware
|
|
func (siw *ServerInterfaceWrapper) Status(w http.ResponseWriter, r *http.Request) {
|
|
|
|
handler := http.Handler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
siw.Handler.Status(w, r)
|
|
}))
|
|
|
|
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.Health)
|
|
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/leases", wrapper.AcquireLease)
|
|
m.HandleFunc(http.MethodPost+" "+options.BaseURL+"/v1/leases/{id}/renew", wrapper.RenewLease)
|
|
m.HandleFunc(http.MethodDelete+" "+options.BaseURL+"/v1/leases/{id}", wrapper.ReleaseLease)
|
|
m.HandleFunc(http.MethodGet+" "+options.BaseURL+"/v1/status", wrapper.Status)
|
|
|
|
return m
|
|
}
|
|
|
|
type ProblemJSONResponse Problem
|
|
|
|
type HealthRequestObject struct {
|
|
}
|
|
|
|
type HealthResponseObject interface {
|
|
VisitHealthResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type Health200JSONResponse Health
|
|
|
|
func (response Health200JSONResponse) VisitHealthResponse(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 AcquireLeaseRequestObject struct {
|
|
Body *AcquireLeaseJSONRequestBody
|
|
}
|
|
|
|
type AcquireLeaseResponseObject interface {
|
|
VisitAcquireLeaseResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type AcquireLease200JSONResponse Grant
|
|
|
|
func (response AcquireLease200JSONResponse) VisitAcquireLeaseResponse(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 AcquireLease400JSONResponse struct{ ProblemJSONResponse }
|
|
|
|
func (response AcquireLease400JSONResponse) VisitAcquireLeaseResponse(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 AcquireLease413JSONResponse Problem
|
|
|
|
func (response AcquireLease413JSONResponse) VisitAcquireLeaseResponse(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(413)
|
|
_, err := buf.WriteTo(w)
|
|
return err
|
|
}
|
|
|
|
type AcquireLease503JSONResponse Problem
|
|
|
|
func (response AcquireLease503JSONResponse) VisitAcquireLeaseResponse(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(503)
|
|
_, err := buf.WriteTo(w)
|
|
return err
|
|
}
|
|
|
|
type ReleaseLeaseRequestObject struct {
|
|
Id LeaseId `json:"id"`
|
|
}
|
|
|
|
type ReleaseLeaseResponseObject interface {
|
|
VisitReleaseLeaseResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type ReleaseLease204Response struct {
|
|
}
|
|
|
|
func (response ReleaseLease204Response) VisitReleaseLeaseResponse(w http.ResponseWriter) error {
|
|
w.WriteHeader(204)
|
|
return nil
|
|
}
|
|
|
|
type RenewLeaseRequestObject struct {
|
|
Id LeaseId `json:"id"`
|
|
}
|
|
|
|
type RenewLeaseResponseObject interface {
|
|
VisitRenewLeaseResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type RenewLease204Response struct {
|
|
}
|
|
|
|
func (response RenewLease204Response) VisitRenewLeaseResponse(w http.ResponseWriter) error {
|
|
w.WriteHeader(204)
|
|
return nil
|
|
}
|
|
|
|
type RenewLease404JSONResponse struct{ ProblemJSONResponse }
|
|
|
|
func (response RenewLease404JSONResponse) VisitRenewLeaseResponse(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 StatusRequestObject struct {
|
|
}
|
|
|
|
type StatusResponseObject interface {
|
|
VisitStatusResponse(w http.ResponseWriter) error
|
|
}
|
|
|
|
type Status200JSONResponse Status
|
|
|
|
func (response Status200JSONResponse) VisitStatusResponse(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
|
|
}
|
|
|
|
// StrictServerInterface represents all server handlers.
|
|
type StrictServerInterface interface {
|
|
|
|
// (GET /v1/health)
|
|
Health(ctx context.Context, request HealthRequestObject) (HealthResponseObject, error)
|
|
|
|
// (POST /v1/leases)
|
|
AcquireLease(ctx context.Context, request AcquireLeaseRequestObject) (AcquireLeaseResponseObject, error)
|
|
|
|
// (DELETE /v1/leases/{id})
|
|
ReleaseLease(ctx context.Context, request ReleaseLeaseRequestObject) (ReleaseLeaseResponseObject, error)
|
|
|
|
// (POST /v1/leases/{id}/renew)
|
|
RenewLease(ctx context.Context, request RenewLeaseRequestObject) (RenewLeaseResponseObject, error)
|
|
|
|
// (GET /v1/status)
|
|
Status(ctx context.Context, request StatusRequestObject) (StatusResponseObject, 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
|
|
}
|
|
|
|
// Health operation middleware
|
|
func (sh *strictHandler) Health(w http.ResponseWriter, r *http.Request) {
|
|
var request HealthRequestObject
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.Health(ctx, request.(HealthRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "Health")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(HealthResponseObject); ok {
|
|
if err := validResponse.VisitHealthResponse(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))
|
|
}
|
|
}
|
|
|
|
// AcquireLease operation middleware
|
|
func (sh *strictHandler) AcquireLease(w http.ResponseWriter, r *http.Request) {
|
|
var request AcquireLeaseRequestObject
|
|
|
|
var body AcquireLeaseJSONRequestBody
|
|
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.AcquireLease(ctx, request.(AcquireLeaseRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "AcquireLease")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(AcquireLeaseResponseObject); ok {
|
|
if err := validResponse.VisitAcquireLeaseResponse(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))
|
|
}
|
|
}
|
|
|
|
// ReleaseLease operation middleware
|
|
func (sh *strictHandler) ReleaseLease(w http.ResponseWriter, r *http.Request, id LeaseId) {
|
|
var request ReleaseLeaseRequestObject
|
|
|
|
request.Id = id
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.ReleaseLease(ctx, request.(ReleaseLeaseRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "ReleaseLease")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(ReleaseLeaseResponseObject); ok {
|
|
if err := validResponse.VisitReleaseLeaseResponse(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))
|
|
}
|
|
}
|
|
|
|
// RenewLease operation middleware
|
|
func (sh *strictHandler) RenewLease(w http.ResponseWriter, r *http.Request, id LeaseId) {
|
|
var request RenewLeaseRequestObject
|
|
|
|
request.Id = id
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.RenewLease(ctx, request.(RenewLeaseRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "RenewLease")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(RenewLeaseResponseObject); ok {
|
|
if err := validResponse.VisitRenewLeaseResponse(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))
|
|
}
|
|
}
|
|
|
|
// Status operation middleware
|
|
func (sh *strictHandler) Status(w http.ResponseWriter, r *http.Request) {
|
|
var request StatusRequestObject
|
|
|
|
handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, request interface{}) (interface{}, error) {
|
|
return sh.ssi.Status(ctx, request.(StatusRequestObject))
|
|
}
|
|
for _, middleware := range sh.middlewares {
|
|
handler = middleware(handler, "Status")
|
|
}
|
|
|
|
response, err := handler(r.Context(), w, r, request)
|
|
|
|
if err != nil {
|
|
sh.options.ResponseErrorHandlerFunc(w, r, err)
|
|
} else if validResponse, ok := response.(StatusResponseObject); ok {
|
|
if err := validResponse.VisitStatusResponse(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{
|
|
"vFj7b9u+Ef9XDtyAJYAiy022FS72Q1oM6YAWC7pmHdAEDi2dLTYUqfKoJEag/304UvIjltOkaL8/ReHj",
|
|
"Hp/73IN+ELmtamvQeBKTB1FLJyv06MJ/H1AS/qvgT2XERNTSlyIRRlYoJkIVIhEOvzfKYSEm3jWYCMpL",
|
|
"rCTf8MuaT5F3yixE27Z8mGprCIPwc2dnGiv+zK3xaDx/yrrWKpdeWTP6Rtbw2lrmnx3OxUT8abS2ehR3",
|
|
"adTLC5oKpNypmsWIifinc9algje60yzsrG7+46VvouPO1ui8irbNHeK0mm24oYzHBTrRJkKZAu+HtxwS",
|
|
"utv9V731Uu/dbQiLPZvtJtJfOxM25K0vbxmRrDy5SnqZdvYNc8/6zpw0ftf5Am9VjvyFpqlY3aJuRCLy",
|
|
"utkQ08c1EXhfK4c0lUHW3LqKv0QhPR55VaEYuMMSJw+PwnR2fgHBswSOxjC3DnyJ8O78IhXJDiKJ0CgJ",
|
|
"p6rYFXQ6IzQ+SHh3fgEL9pPSXTseodo5Hq0bAuw9Su3LXcRoRaMeMXvDeWKnJKtao7j6kepOwpDSmIRm",
|
|
"bnf15lp1afMrg7KLdAAQixcJi3HZWb51snomx7m8dB4mHQX721smbTm7F8FP+L1B8k+BuE2iL6UFRSDp",
|
|
"RplFApguUrBay0oe1c7eLxNYoHFIR4sGaYhdIWOmc6n1TOY3UcFcNtqLyVxqwtWFmbUapeEblbyf3knl",
|
|
"p7RrUAbWgQzUngAfAkmgrVnwX+XByxsMdlTKqIp5mA2lTe1wju6J7EMCb8G7JcyVI88SlceK9pS0uCKd",
|
|
"k8soXlmn/PLH5bo7x0W5diiLIYS2TfwolzBDoFqz87mzRHB2fkFw8O8QmLhDIKGyBWrwpfQw5xVjgZRZ",
|
|
"aIRcuuIwFUPgb3BzBeE4+RFPVxRdeb6WNMTG8w2A+nIxkz7nzso6nMy9usVQyKUO6TVUdTfa5zafkZvd",
|
|
"UAPeNjseGzJwX1Nc1HF1RYanwrturgMcCZX7+bLWFXBAlvd6uoeanCPs+nP1fJHKD6t5hF1AYuXGWlFv",
|
|
"zRCqK+EvqeI/lUzK5Pj8Ov38gvwU0Xu1u563YWKKfm9n83tpCgLbeM5hqLCybgnWwPIWtZcaDs4+/w/G",
|
|
"2d8y+Ec4kSUQV173K+NDIAvf7IygsOYvnOuL0oO9RQfKp5fm0pxCNJvrOIWJQEKIG9wpX4YB47+fTj9y",
|
|
"/TSIBaXwuUSYOXuDrhscQAZl4byztkq4Dn9vsEG6NCzAxdYCB33CwmWTZccIG+ncL4VMT2JlhdxW2H2G",
|
|
"ka0ISpQBCT3Ghyl8KdFcmut1a7iGWhIhJSBXuoN115sN55q7l7e64GreEPbDFChDHmWRQsgrgtg9L01j",
|
|
"NBKBQ4N3WMDBdSDzNSgTrsYR5fANOIwA+hIruCvRMPgY0P6gyKMhjuL41d/TLM3SMVijl2+4AsvGl2h8",
|
|
"N96nl0YkwiuvUUw4pY4i6swqdBQ5MmYZTFNbo5G1EhNxnGbpMbNQ+jLkz+h2PCpXk9kCQypxggU1/Hzp",
|
|
"B7dHL5BXWfbLXh+dhoHHxwafFEFTgzQFlJJC8HKmZiBgnBT5kcIi2Kd1lawtDQwob7XNbwga45XuOKoI",
|
|
"5g4xWcW6JwMEz5gy1sGaSR2RuB1uA3aah7wPDOleeUj+rS2WvwyxramsbdvHb8n2N0YrvnwGgnUWx0o4",
|
|
"CHgGtDooD1Om4UmW7ZO9Mnb9Ek3Eyfj4Ref/mr3k/COqjB5U0UaeaPS4mwafYub2Ud187H8dVro+Mup/",
|
|
"DGivdgJzskvOThUjqcnGMqE8lLIAqXnaW3Z1h4exQUdGoRBt0v+xMwbv/hhXQkHs4n/yM/FZPxAHy1M3",
|
|
"Kf1Gwncahhh/fkFJbIkUShPzPXS3GJc2EaE3dcg2TouJKL2vJ6PRqsZPXo+PM9Fetf8fAA==",
|
|
}
|
|
|
|
// 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()
|
|
}
|