Files
webarchive/api/openapi/oas_parameters_gen.go

392 lines
7.7 KiB
Go

// Code generated by ogen, DO NOT EDIT.
package openapi
import (
"fmt"
"net/http"
"net/url"
"github.com/go-faster/errors"
"github.com/google/uuid"
"github.com/ogen-go/ogen/conv"
"github.com/ogen-go/ogen/middleware"
"github.com/ogen-go/ogen/ogenerrors"
"github.com/ogen-go/ogen/uri"
"github.com/ogen-go/ogen/validate"
)
// AddPageParams is parameters of addPage operation.
type AddPageParams struct {
URL OptString
Description OptString
Formats []Format
}
func unpackAddPageParams(packed middleware.Parameters) (params AddPageParams) {
{
key := middleware.ParameterKey{
Name: "url",
In: "query",
}
if v, ok := packed[key]; ok {
params.URL = v.(OptString)
}
}
{
key := middleware.ParameterKey{
Name: "description",
In: "query",
}
if v, ok := packed[key]; ok {
params.Description = v.(OptString)
}
}
{
key := middleware.ParameterKey{
Name: "formats",
In: "query",
}
if v, ok := packed[key]; ok {
params.Formats = v.([]Format)
}
}
return params
}
func decodeAddPageParams(args [0]string, argsEscaped bool, r *http.Request) (params AddPageParams, _ error) {
q := uri.NewQueryDecoder(r.URL.Query())
// Decode query: url.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "url",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotURLVal string
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
paramsDotURLVal = c
return nil
}(); err != nil {
return err
}
params.URL.SetTo(paramsDotURLVal)
return nil
}); err != nil {
return err
}
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "url",
In: "query",
Err: err,
}
}
// Decode query: description.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "description",
Style: uri.QueryStyleForm,
Explode: true,
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
var paramsDotDescriptionVal string
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
paramsDotDescriptionVal = c
return nil
}(); err != nil {
return err
}
params.Description.SetTo(paramsDotDescriptionVal)
return nil
}); err != nil {
return err
}
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "description",
In: "query",
Err: err,
}
}
// Decode query: formats.
if err := func() error {
cfg := uri.QueryParameterDecodingConfig{
Name: "formats",
Style: uri.QueryStyleForm,
Explode: false,
}
if err := q.HasParam(cfg); err == nil {
if err := q.DecodeParam(cfg, func(d uri.Decoder) error {
return d.DecodeArray(func(d uri.Decoder) error {
var paramsDotFormatsVal Format
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToString(val)
if err != nil {
return err
}
paramsDotFormatsVal = Format(c)
return nil
}(); err != nil {
return err
}
params.Formats = append(params.Formats, paramsDotFormatsVal)
return nil
})
}); err != nil {
return err
}
if err := func() error {
var failures []validate.FieldError
for i, elem := range params.Formats {
if err := func() error {
if err := elem.Validate(); err != nil {
return err
}
return nil
}(); err != nil {
failures = append(failures, validate.FieldError{
Name: fmt.Sprintf("[%d]", i),
Error: err,
})
}
}
if len(failures) > 0 {
return &validate.Error{Fields: failures}
}
return nil
}(); err != nil {
return err
}
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "formats",
In: "query",
Err: err,
}
}
return params, nil
}
// GetFileParams is parameters of getFile operation.
type GetFileParams struct {
ID uuid.UUID
FileID uuid.UUID
}
func unpackGetFileParams(packed middleware.Parameters) (params GetFileParams) {
{
key := middleware.ParameterKey{
Name: "id",
In: "path",
}
params.ID = packed[key].(uuid.UUID)
}
{
key := middleware.ParameterKey{
Name: "file_id",
In: "path",
}
params.FileID = packed[key].(uuid.UUID)
}
return params
}
func decodeGetFileParams(args [2]string, argsEscaped bool, r *http.Request) (params GetFileParams, _ error) {
// Decode path: id.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "id",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToUUID(val)
if err != nil {
return err
}
params.ID = c
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "id",
In: "path",
Err: err,
}
}
// Decode path: file_id.
if err := func() error {
param := args[1]
if argsEscaped {
unescaped, err := url.PathUnescape(args[1])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "file_id",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToUUID(val)
if err != nil {
return err
}
params.FileID = c
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "file_id",
In: "path",
Err: err,
}
}
return params, nil
}
// GetPageParams is parameters of getPage operation.
type GetPageParams struct {
ID uuid.UUID
}
func unpackGetPageParams(packed middleware.Parameters) (params GetPageParams) {
{
key := middleware.ParameterKey{
Name: "id",
In: "path",
}
params.ID = packed[key].(uuid.UUID)
}
return params
}
func decodeGetPageParams(args [1]string, argsEscaped bool, r *http.Request) (params GetPageParams, _ error) {
// Decode path: id.
if err := func() error {
param := args[0]
if argsEscaped {
unescaped, err := url.PathUnescape(args[0])
if err != nil {
return errors.Wrap(err, "unescape path")
}
param = unescaped
}
if len(param) > 0 {
d := uri.NewPathDecoder(uri.PathDecoderConfig{
Param: "id",
Value: param,
Style: uri.PathStyleSimple,
Explode: false,
})
if err := func() error {
val, err := d.DecodeValue()
if err != nil {
return err
}
c, err := conv.ToUUID(val)
if err != nil {
return err
}
params.ID = c
return nil
}(); err != nil {
return err
}
} else {
return validate.ErrFieldRequired
}
return nil
}(); err != nil {
return params, &ogenerrors.DecodeParamError{
Name: "id",
In: "path",
Err: err,
}
}
return params, nil
}