From 11992d42d26b553c849084dcb7dd2005cec8a9cb Mon Sep 17 00:00:00 2001 From: tdakkota Date: Thu, 20 Apr 2023 03:56:16 +0300 Subject: [PATCH] chore: commit generated files --- examples/ex_2ch/oas_client_gen.go | 4 +- examples/ex_2ch/oas_handlers_gen.go | 2 +- examples/ex_2ch/oas_request_decoders_gen.go | 52 +- examples/ex_2ch/oas_request_encoders_gen.go | 32 +- examples/ex_2ch/oas_schemas_gen.go | 56 +- examples/ex_2ch/oas_server_gen.go | 2 +- examples/ex_2ch/oas_unimplemented_gen.go | 2 +- examples/ex_openai/oas_client_gen.go | 20 +- examples/ex_openai/oas_defaults_gen.go | 72 +- examples/ex_openai/oas_handlers_gen.go | 10 +- .../ex_openai/oas_request_decoders_gen.go | 36 +- .../ex_openai/oas_request_encoders_gen.go | 10 +- examples/ex_openai/oas_schemas_gen.go | 699 +++++------------- examples/ex_openai/oas_server_gen.go | 10 +- examples/ex_openai/oas_unimplemented_gen.go | 10 +- examples/ex_openai/oas_validators_gen.go | 206 +----- .../integration/test_allof/oas_client_gen.go | 8 +- .../integration/test_allof/oas_faker_gen.go | 36 - .../integration/test_allof/oas_json_gen.go | 152 ---- .../test_allof/oas_request_decoders_gen.go | 316 ++++---- .../test_allof/oas_request_encoders_gen.go | 8 +- .../integration/test_allof/oas_schemas_gen.go | 93 ++- .../test_allof/oas_test_examples_gen_test.go | 48 -- .../test_allof/oas_validators_gen.go | 55 +- .../integration/test_form/oas_client_gen.go | 156 +++- .../integration/test_form/oas_handlers_gen.go | 206 +++++- .../test_form/oas_request_decoders_gen.go | 236 +++++- .../test_form/oas_request_encoders_gen.go | 90 ++- .../test_form/oas_response_decoders_gen.go | 18 + .../test_form/oas_response_encoders_gen.go | 14 + .../integration/test_form/oas_router_gen.go | 102 +++ .../integration/test_form/oas_schemas_gen.go | 370 ++++++--- .../integration/test_form/oas_server_gen.go | 14 +- .../test_form/oas_unimplemented_gen.go | 20 +- internal/integration/test_form/oas_uri_gen.go | 234 ++++++ .../test_form/oas_validators_gen.go | 26 - .../test_http_requests/oas_client_gen.go | 4 +- .../test_http_requests/oas_json_gen.go | 76 -- .../oas_request_decoders_gen.go | 188 +++-- .../oas_request_encoders_gen.go | 4 +- .../test_http_requests/oas_schemas_gen.go | 37 +- 41 files changed, 2024 insertions(+), 1710 deletions(-) diff --git a/examples/ex_2ch/oas_client_gen.go b/examples/ex_2ch/oas_client_gen.go index 8bd61a568..7bac8d02d 100644 --- a/examples/ex_2ch/oas_client_gen.go +++ b/examples/ex_2ch/oas_client_gen.go @@ -1417,13 +1417,13 @@ func (c *Client) sendUserPassloginPost(ctx context.Context, request OptUserPassl // Создание нового поста или треда. // // POST /user/posting -func (c *Client) UserPostingPost(ctx context.Context, request OptUserPostingPostReqForm) (UserPostingPostOK, error) { +func (c *Client) UserPostingPost(ctx context.Context, request OptUserPostingPostReq) (UserPostingPostOK, error) { res, err := c.sendUserPostingPost(ctx, request) _ = res return res, err } -func (c *Client) sendUserPostingPost(ctx context.Context, request OptUserPostingPostReqForm) (res UserPostingPostOK, err error) { +func (c *Client) sendUserPostingPost(ctx context.Context, request OptUserPostingPostReq) (res UserPostingPostOK, err error) { var otelAttrs []attribute.KeyValue // Validate request before sending. if err := func() error { diff --git a/examples/ex_2ch/oas_handlers_gen.go b/examples/ex_2ch/oas_handlers_gen.go index 77a19d548..266f50232 100644 --- a/examples/ex_2ch/oas_handlers_gen.go +++ b/examples/ex_2ch/oas_handlers_gen.go @@ -1444,7 +1444,7 @@ func (s *Server) handleUserPostingPostRequest(args [0]string, argsEscaped bool, } type ( - Request = OptUserPostingPostReqForm + Request = OptUserPostingPostReq Params = struct{} Response = UserPostingPostOK ) diff --git a/examples/ex_2ch/oas_request_decoders_gen.go b/examples/ex_2ch/oas_request_decoders_gen.go index 7488b67d6..17846ca87 100644 --- a/examples/ex_2ch/oas_request_decoders_gen.go +++ b/examples/ex_2ch/oas_request_decoders_gen.go @@ -11,6 +11,7 @@ import ( "go.uber.org/multierr" "github.com/ogen-go/ogen/conv" + ht "github.com/ogen-go/ogen/http" "github.com/ogen-go/ogen/uri" "github.com/ogen-go/ogen/validate" ) @@ -102,7 +103,7 @@ func (s *Server) decodeUserPassloginPostRequest(r *http.Request) ( } func (s *Server) decodeUserPostingPostRequest(r *http.Request) ( - req OptUserPostingPostReqForm, + req OptUserPostingPostReq, close func() error, rerr error, ) { @@ -145,7 +146,7 @@ func (s *Server) decodeUserPostingPostRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request OptUserPostingPostReqForm + var request OptUserPostingPostReq { var optForm UserPostingPostReq q := uri.NewQueryDecoder(form) @@ -468,40 +469,29 @@ func (s *Server) decodeUserPostingPostRequest(r *http.Request) ( } } { - cfg := uri.QueryParameterDecodingConfig{ - Name: "file[]", - Style: uri.QueryStyleForm, - Explode: true, - } - 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 optFormDotFileVal string - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToString(val) - if err != nil { - return err - } + if err := func() error { + files, ok := r.MultipartForm.File["file[]"] + _ = ok + request.Files = make([]ht.MultipartFile, 0, len(files)) + for _, fh := range files { + f, err := fh.Open() + if err != nil { + return errors.Wrap(err, "open") + } + closers = append(closers, f.Close) - optFormDotFileVal = c - return nil - }(); err != nil { - return err - } - optForm.File = append(optForm.File, optFormDotFileVal) - return nil + optForm.File = append(optForm.File, ht.MultipartFile{ + Name: fh.Filename, + File: f, + Header: fh.Header, }) - }); err != nil { - return req, close, errors.Wrap(err, "decode \"file[]\"") } + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "decode \"file[]\"") } } - request = OptUserPostingPostReqForm{ + request = OptUserPostingPostReq{ Value: optForm, Set: true, } diff --git a/examples/ex_2ch/oas_request_encoders_gen.go b/examples/ex_2ch/oas_request_encoders_gen.go index 21ad19bd9..e8e082340 100644 --- a/examples/ex_2ch/oas_request_encoders_gen.go +++ b/examples/ex_2ch/oas_request_encoders_gen.go @@ -50,7 +50,7 @@ func encodeUserPassloginPostRequest( } func encodeUserPostingPostRequest( - req OptUserPostingPostReqForm, + req OptUserPostingPostReq, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -215,29 +215,17 @@ func encodeUserPostingPostRequest( return errors.Wrap(err, "encode query") } } - { - // Encode "file[]" form field. - cfg := uri.QueryParameterEncodingConfig{ - Name: "file[]", - Style: uri.QueryStyleForm, - Explode: true, - } - if err := q.EncodeParam(cfg, func(e uri.Encoder) error { - return e.EncodeArray(func(e uri.Encoder) error { - for i, item := range request.File { - if err := func() error { - return e.EncodeValue(conv.StringToString(item)) - }(); err != nil { - return errors.Wrapf(err, "[%d]", i) - } + body, boundary := ht.CreateMultipartBody(func(w *multipart.Writer) error { + if err := func() error { + for idx, val := range request.File { + if err := val.WriteMultipart("file[]", w); err != nil { + return errors.Wrapf(err, "file [%d]", idx) } - return nil - }) - }); err != nil { - return errors.Wrap(err, "encode query") + } + return nil + }(); err != nil { + return errors.Wrap(err, "write \"file[]\"") } - } - body, boundary := ht.CreateMultipartBody(func(w *multipart.Writer) error { if err := q.WriteMultipart(w); err != nil { return errors.Wrap(err, "write multipart") } diff --git a/examples/ex_2ch/oas_schemas_gen.go b/examples/ex_2ch/oas_schemas_gen.go index 327040037..65c7122eb 100644 --- a/examples/ex_2ch/oas_schemas_gen.go +++ b/examples/ex_2ch/oas_schemas_gen.go @@ -4,6 +4,8 @@ package api import ( "github.com/go-faster/errors" + + ht "github.com/ogen-go/ogen/http" ) // APICaptcha2chcaptchaShowGetNotFound is response for APICaptcha2chcaptchaShowGet operation. @@ -1474,52 +1476,6 @@ func (o OptUserPostingPostReq) Or(d UserPostingPostReq) UserPostingPostReq { return d } -// NewOptUserPostingPostReqForm returns new OptUserPostingPostReqForm with value set to v. -func NewOptUserPostingPostReqForm(v UserPostingPostReq) OptUserPostingPostReqForm { - return OptUserPostingPostReqForm{ - Value: v, - Set: true, - } -} - -// OptUserPostingPostReqForm is optional UserPostingPostReq. -type OptUserPostingPostReqForm struct { - Value UserPostingPostReq - Set bool -} - -// IsSet returns true if OptUserPostingPostReqForm was set. -func (o OptUserPostingPostReqForm) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptUserPostingPostReqForm) Reset() { - var v UserPostingPostReq - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptUserPostingPostReqForm) SetTo(v UserPostingPostReq) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptUserPostingPostReqForm) Get() (v UserPostingPostReq, ok bool) { - if !o.Set { - return v, false - } - return o.Value, true -} - -// Or returns value if set, or given parameter if does not. -func (o OptUserPostingPostReqForm) Or(d UserPostingPostReq) UserPostingPostReq { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptUserReportPostReq returns new OptUserReportPostReq with value set to v. func NewOptUserReportPostReq(v UserReportPostReq) OptUserReportPostReq { return OptUserReportPostReq{ @@ -2089,8 +2045,8 @@ type UserPostingPostReq struct { Icon OptInt `json:"icon"` // Если не включено в настройках доски - поле будет // проигнорировано. - OpMark OptInt `json:"op_mark"` - File []string `json:"file[]"` + OpMark OptInt `json:"op_mark"` + File []ht.MultipartFile `json:"file[]"` } // GetCaptchaType returns the value of CaptchaType. @@ -2144,7 +2100,7 @@ func (s *UserPostingPostReq) GetOpMark() OptInt { } // GetFile returns the value of File. -func (s *UserPostingPostReq) GetFile() []string { +func (s *UserPostingPostReq) GetFile() []ht.MultipartFile { return s.File } @@ -2199,7 +2155,7 @@ func (s *UserPostingPostReq) SetOpMark(val OptInt) { } // SetFile sets the value of File. -func (s *UserPostingPostReq) SetFile(val []string) { +func (s *UserPostingPostReq) SetFile(val []ht.MultipartFile) { s.File = val } diff --git a/examples/ex_2ch/oas_server_gen.go b/examples/ex_2ch/oas_server_gen.go index 6f333580e..f7c249e48 100644 --- a/examples/ex_2ch/oas_server_gen.go +++ b/examples/ex_2ch/oas_server_gen.go @@ -103,7 +103,7 @@ type Handler interface { // Создание нового поста или треда. // // POST /user/posting - UserPostingPost(ctx context.Context, req OptUserPostingPostReqForm) (UserPostingPostOK, error) + UserPostingPost(ctx context.Context, req OptUserPostingPostReq) (UserPostingPostOK, error) // UserReportPost implements POST /user/report operation. // // Отправка жалобы. diff --git a/examples/ex_2ch/oas_unimplemented_gen.go b/examples/ex_2ch/oas_unimplemented_gen.go index 8af3374c0..e7bcf82c1 100644 --- a/examples/ex_2ch/oas_unimplemented_gen.go +++ b/examples/ex_2ch/oas_unimplemented_gen.go @@ -150,7 +150,7 @@ func (UnimplementedHandler) UserPassloginPost(ctx context.Context, req OptUserPa // Создание нового поста или треда. // // POST /user/posting -func (UnimplementedHandler) UserPostingPost(ctx context.Context, req OptUserPostingPostReqForm) (r UserPostingPostOK, _ error) { +func (UnimplementedHandler) UserPostingPost(ctx context.Context, req OptUserPostingPostReq) (r UserPostingPostOK, _ error) { return r, ht.ErrNotImplemented } diff --git a/examples/ex_openai/oas_client_gen.go b/examples/ex_openai/oas_client_gen.go index 56d1e0a08..594339acc 100644 --- a/examples/ex_openai/oas_client_gen.go +++ b/examples/ex_openai/oas_client_gen.go @@ -668,13 +668,13 @@ func (c *Client) sendCreateEmbedding(ctx context.Context, request *CreateEmbeddi // need to increase the storage limit. // // POST /files -func (c *Client) CreateFile(ctx context.Context, request *CreateFileRequestForm) (OpenAIFile, error) { +func (c *Client) CreateFile(ctx context.Context, request *CreateFileRequestMultipart) (OpenAIFile, error) { res, err := c.sendCreateFile(ctx, request) _ = res return res, err } -func (c *Client) sendCreateFile(ctx context.Context, request *CreateFileRequestForm) (res OpenAIFile, err error) { +func (c *Client) sendCreateFile(ctx context.Context, request *CreateFileRequestMultipart) (res OpenAIFile, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createFile"), } @@ -908,13 +908,13 @@ func (c *Client) sendCreateImage(ctx context.Context, request *CreateImageReques // Creates an edited or extended image given an original image and a prompt. // // POST /images/edits -func (c *Client) CreateImageEdit(ctx context.Context, request *CreateImageEditRequestForm) (ImagesResponse, error) { +func (c *Client) CreateImageEdit(ctx context.Context, request *CreateImageEditRequestMultipart) (ImagesResponse, error) { res, err := c.sendCreateImageEdit(ctx, request) _ = res return res, err } -func (c *Client) sendCreateImageEdit(ctx context.Context, request *CreateImageEditRequestForm) (res ImagesResponse, err error) { +func (c *Client) sendCreateImageEdit(ctx context.Context, request *CreateImageEditRequestMultipart) (res ImagesResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createImageEdit"), } @@ -990,13 +990,13 @@ func (c *Client) sendCreateImageEdit(ctx context.Context, request *CreateImageEd // Creates a variation of a given image. // // POST /images/variations -func (c *Client) CreateImageVariation(ctx context.Context, request *CreateImageVariationRequestForm) (ImagesResponse, error) { +func (c *Client) CreateImageVariation(ctx context.Context, request *CreateImageVariationRequestMultipart) (ImagesResponse, error) { res, err := c.sendCreateImageVariation(ctx, request) _ = res return res, err } -func (c *Client) sendCreateImageVariation(ctx context.Context, request *CreateImageVariationRequestForm) (res ImagesResponse, err error) { +func (c *Client) sendCreateImageVariation(ctx context.Context, request *CreateImageVariationRequestMultipart) (res ImagesResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createImageVariation"), } @@ -1264,13 +1264,13 @@ func (c *Client) sendCreateSearch(ctx context.Context, request *CreateSearchRequ // Transcribes audio into the input language. // // POST /audio/transcriptions -func (c *Client) CreateTranscription(ctx context.Context, request *CreateTranscriptionRequestForm) (*CreateTranscriptionResponse, error) { +func (c *Client) CreateTranscription(ctx context.Context, request *CreateTranscriptionRequestMultipart) (*CreateTranscriptionResponse, error) { res, err := c.sendCreateTranscription(ctx, request) _ = res return res, err } -func (c *Client) sendCreateTranscription(ctx context.Context, request *CreateTranscriptionRequestForm) (res *CreateTranscriptionResponse, err error) { +func (c *Client) sendCreateTranscription(ctx context.Context, request *CreateTranscriptionRequestMultipart) (res *CreateTranscriptionResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createTranscription"), } @@ -1346,13 +1346,13 @@ func (c *Client) sendCreateTranscription(ctx context.Context, request *CreateTra // Translates audio into into English. // // POST /audio/translations -func (c *Client) CreateTranslation(ctx context.Context, request *CreateTranslationRequestForm) (*CreateTranslationResponse, error) { +func (c *Client) CreateTranslation(ctx context.Context, request *CreateTranslationRequestMultipart) (*CreateTranslationResponse, error) { res, err := c.sendCreateTranslation(ctx, request) _ = res return res, err } -func (c *Client) sendCreateTranslation(ctx context.Context, request *CreateTranslationRequestForm) (res *CreateTranslationResponse, err error) { +func (c *Client) sendCreateTranslation(ctx context.Context, request *CreateTranslationRequestMultipart) (res *CreateTranslationResponse, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createTranslation"), } diff --git a/examples/ex_openai/oas_defaults_gen.go b/examples/ex_openai/oas_defaults_gen.go index 23b3e0c56..44982c778 100644 --- a/examples/ex_openai/oas_defaults_gen.go +++ b/examples/ex_openai/oas_defaults_gen.go @@ -194,33 +194,17 @@ func (s *CreateFineTuneRequest) setDefaults() { } // setDefaults set default value of fields. -func (s *CreateImageEditRequest) setDefaults() { +func (s *CreateImageEditRequestMultipart) setDefaults() { { val := int(1) s.N.SetTo(val) } { - val := CreateImageEditRequestSize("1024x1024") + val := CreateImageEditRequestMultipartSize("1024x1024") s.Size.SetTo(val) } { - val := CreateImageEditRequestResponseFormat("url") - s.ResponseFormat.SetTo(val) - } -} - -// setDefaults set default value of fields. -func (s *CreateImageEditRequestForm) setDefaults() { - { - val := int(1) - s.N.SetTo(val) - } - { - val := CreateImageEditRequestSize("1024x1024") - s.Size.SetTo(val) - } - { - val := CreateImageEditRequestResponseFormat("url") + val := CreateImageEditRequestMultipartResponseFormat("url") s.ResponseFormat.SetTo(val) } } @@ -242,33 +226,17 @@ func (s *CreateImageRequest) setDefaults() { } // setDefaults set default value of fields. -func (s *CreateImageVariationRequest) setDefaults() { - { - val := int(1) - s.N.SetTo(val) - } - { - val := CreateImageVariationRequestSize("1024x1024") - s.Size.SetTo(val) - } - { - val := CreateImageVariationRequestResponseFormat("url") - s.ResponseFormat.SetTo(val) - } -} - -// setDefaults set default value of fields. -func (s *CreateImageVariationRequestForm) setDefaults() { +func (s *CreateImageVariationRequestMultipart) setDefaults() { { val := int(1) s.N.SetTo(val) } { - val := CreateImageVariationRequestSize("1024x1024") + val := CreateImageVariationRequestMultipartSize("1024x1024") s.Size.SetTo(val) } { - val := CreateImageVariationRequestResponseFormat("url") + val := CreateImageVariationRequestMultipartResponseFormat("url") s.ResponseFormat.SetTo(val) } } @@ -294,31 +262,7 @@ func (s *CreateSearchRequest) setDefaults() { } // setDefaults set default value of fields. -func (s *CreateTranscriptionRequest) setDefaults() { - { - val := string("json") - s.ResponseFormat.SetTo(val) - } - { - val := float64(0) - s.Temperature.SetTo(val) - } -} - -// setDefaults set default value of fields. -func (s *CreateTranscriptionRequestForm) setDefaults() { - { - val := string("json") - s.ResponseFormat.SetTo(val) - } - { - val := float64(0) - s.Temperature.SetTo(val) - } -} - -// setDefaults set default value of fields. -func (s *CreateTranslationRequest) setDefaults() { +func (s *CreateTranscriptionRequestMultipart) setDefaults() { { val := string("json") s.ResponseFormat.SetTo(val) @@ -330,7 +274,7 @@ func (s *CreateTranslationRequest) setDefaults() { } // setDefaults set default value of fields. -func (s *CreateTranslationRequestForm) setDefaults() { +func (s *CreateTranslationRequestMultipart) setDefaults() { { val := string("json") s.ResponseFormat.SetTo(val) diff --git a/examples/ex_openai/oas_handlers_gen.go b/examples/ex_openai/oas_handlers_gen.go index 104a54446..d3db57236 100644 --- a/examples/ex_openai/oas_handlers_gen.go +++ b/examples/ex_openai/oas_handlers_gen.go @@ -815,7 +815,7 @@ func (s *Server) handleCreateFileRequest(args [0]string, argsEscaped bool, w htt } type ( - Request = *CreateFileRequestForm + Request = *CreateFileRequestMultipart Params = struct{} Response = OpenAIFile ) @@ -1124,7 +1124,7 @@ func (s *Server) handleCreateImageEditRequest(args [0]string, argsEscaped bool, } type ( - Request = *CreateImageEditRequestForm + Request = *CreateImageEditRequestMultipart Params = struct{} Response = ImagesResponse ) @@ -1226,7 +1226,7 @@ func (s *Server) handleCreateImageVariationRequest(args [0]string, argsEscaped b } type ( - Request = *CreateImageVariationRequestForm + Request = *CreateImageVariationRequestMultipart Params = struct{} Response = ImagesResponse ) @@ -1556,7 +1556,7 @@ func (s *Server) handleCreateTranscriptionRequest(args [0]string, argsEscaped bo } type ( - Request = *CreateTranscriptionRequestForm + Request = *CreateTranscriptionRequestMultipart Params = struct{} Response = *CreateTranscriptionResponse ) @@ -1658,7 +1658,7 @@ func (s *Server) handleCreateTranslationRequest(args [0]string, argsEscaped bool } type ( - Request = *CreateTranslationRequestForm + Request = *CreateTranslationRequestMultipart Params = struct{} Response = *CreateTranslationResponse ) diff --git a/examples/ex_openai/oas_request_decoders_gen.go b/examples/ex_openai/oas_request_decoders_gen.go index c94f93c50..dd568ed04 100644 --- a/examples/ex_openai/oas_request_decoders_gen.go +++ b/examples/ex_openai/oas_request_decoders_gen.go @@ -446,7 +446,7 @@ func (s *Server) decodeCreateEmbeddingRequest(r *http.Request) ( } func (s *Server) decodeCreateFileRequest(r *http.Request) ( - req *CreateFileRequestForm, + req *CreateFileRequestMultipart, close func() error, rerr error, ) { @@ -486,7 +486,7 @@ func (s *Server) decodeCreateFileRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request CreateFileRequestForm + var request CreateFileRequestMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ @@ -687,7 +687,7 @@ func (s *Server) decodeCreateImageRequest(r *http.Request) ( } func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( - req *CreateImageEditRequestForm, + req *CreateImageEditRequestMultipart, close func() error, rerr error, ) { @@ -727,7 +727,7 @@ func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request CreateImageEditRequestForm + var request CreateImageEditRequestMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ @@ -820,7 +820,7 @@ func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( } if err := q.HasParam(cfg); err == nil { if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var requestDotSizeVal CreateImageEditRequestSize + var requestDotSizeVal CreateImageEditRequestMultipartSize if err := func() error { val, err := d.DecodeValue() if err != nil { @@ -832,7 +832,7 @@ func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( return err } - requestDotSizeVal = CreateImageEditRequestSize(c) + requestDotSizeVal = CreateImageEditRequestMultipartSize(c) return nil }(); err != nil { return err @@ -867,7 +867,7 @@ func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( } if err := q.HasParam(cfg); err == nil { if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var requestDotResponseFormatVal CreateImageEditRequestResponseFormat + var requestDotResponseFormatVal CreateImageEditRequestMultipartResponseFormat if err := func() error { val, err := d.DecodeValue() if err != nil { @@ -879,7 +879,7 @@ func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( return err } - requestDotResponseFormatVal = CreateImageEditRequestResponseFormat(c) + requestDotResponseFormatVal = CreateImageEditRequestMultipartResponseFormat(c) return nil }(); err != nil { return err @@ -991,7 +991,7 @@ func (s *Server) decodeCreateImageEditRequest(r *http.Request) ( } func (s *Server) decodeCreateImageVariationRequest(r *http.Request) ( - req *CreateImageVariationRequestForm, + req *CreateImageVariationRequestMultipart, close func() error, rerr error, ) { @@ -1031,7 +1031,7 @@ func (s *Server) decodeCreateImageVariationRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request CreateImageVariationRequestForm + var request CreateImageVariationRequestMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ @@ -1097,7 +1097,7 @@ func (s *Server) decodeCreateImageVariationRequest(r *http.Request) ( } if err := q.HasParam(cfg); err == nil { if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var requestDotSizeVal CreateImageVariationRequestSize + var requestDotSizeVal CreateImageVariationRequestMultipartSize if err := func() error { val, err := d.DecodeValue() if err != nil { @@ -1109,7 +1109,7 @@ func (s *Server) decodeCreateImageVariationRequest(r *http.Request) ( return err } - requestDotSizeVal = CreateImageVariationRequestSize(c) + requestDotSizeVal = CreateImageVariationRequestMultipartSize(c) return nil }(); err != nil { return err @@ -1144,7 +1144,7 @@ func (s *Server) decodeCreateImageVariationRequest(r *http.Request) ( } if err := q.HasParam(cfg); err == nil { if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var requestDotResponseFormatVal CreateImageVariationRequestResponseFormat + var requestDotResponseFormatVal CreateImageVariationRequestMultipartResponseFormat if err := func() error { val, err := d.DecodeValue() if err != nil { @@ -1156,7 +1156,7 @@ func (s *Server) decodeCreateImageVariationRequest(r *http.Request) ( return err } - requestDotResponseFormatVal = CreateImageVariationRequestResponseFormat(c) + requestDotResponseFormatVal = CreateImageVariationRequestMultipartResponseFormat(c) return nil }(); err != nil { return err @@ -1387,7 +1387,7 @@ func (s *Server) decodeCreateSearchRequest(r *http.Request) ( } func (s *Server) decodeCreateTranscriptionRequest(r *http.Request) ( - req *CreateTranscriptionRequestForm, + req *CreateTranscriptionRequestMultipart, close func() error, rerr error, ) { @@ -1427,7 +1427,7 @@ func (s *Server) decodeCreateTranscriptionRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request CreateTranscriptionRequestForm + var request CreateTranscriptionRequestMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ @@ -1629,7 +1629,7 @@ func (s *Server) decodeCreateTranscriptionRequest(r *http.Request) ( } func (s *Server) decodeCreateTranslationRequest(r *http.Request) ( - req *CreateTranslationRequestForm, + req *CreateTranslationRequestMultipart, close func() error, rerr error, ) { @@ -1669,7 +1669,7 @@ func (s *Server) decodeCreateTranslationRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request CreateTranslationRequestForm + var request CreateTranslationRequestMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ diff --git a/examples/ex_openai/oas_request_encoders_gen.go b/examples/ex_openai/oas_request_encoders_gen.go index c8e02f0a1..05bc42c04 100644 --- a/examples/ex_openai/oas_request_encoders_gen.go +++ b/examples/ex_openai/oas_request_encoders_gen.go @@ -101,7 +101,7 @@ func encodeCreateEmbeddingRequest( } func encodeCreateFileRequest( - req *CreateFileRequestForm, + req *CreateFileRequestMultipart, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -163,7 +163,7 @@ func encodeCreateImageRequest( } func encodeCreateImageEditRequest( - req *CreateImageEditRequestForm, + req *CreateImageEditRequestMultipart, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -266,7 +266,7 @@ func encodeCreateImageEditRequest( } func encodeCreateImageVariationRequest( - req *CreateImageVariationRequestForm, + req *CreateImageVariationRequestMultipart, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -379,7 +379,7 @@ func encodeCreateSearchRequest( } func encodeCreateTranscriptionRequest( - req *CreateTranscriptionRequestForm, + req *CreateTranscriptionRequestMultipart, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -477,7 +477,7 @@ func encodeCreateTranscriptionRequest( } func encodeCreateTranslationRequest( - req *CreateTranslationRequestForm, + req *CreateTranslationRequestMultipart, r *http.Request, ) error { const contentType = "multipart/form-data" diff --git a/examples/ex_openai/oas_schemas_gen.go b/examples/ex_openai/oas_schemas_gen.go index 79f6e32fc..11876f4cb 100644 --- a/examples/ex_openai/oas_schemas_gen.go +++ b/examples/ex_openai/oas_schemas_gen.go @@ -2406,39 +2406,7 @@ func (s *CreateEmbeddingResponseUsage) SetTotalTokens(val int) { } // Ref: #/components/schemas/CreateFileRequest -type CreateFileRequest struct { - // Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. - // If the `purpose` is set to "fine-tune", each line is a JSON record with "prompt" and "completion" - // fields representing your [training examples](/docs/guides/fine-tuning/prepare-training-data). - File string `json:"file"` - // The intended purpose of the uploaded documents. - // Use "fine-tune" for [Fine-tuning](/docs/api-reference/fine-tunes). This allows us to validate the - // format of the uploaded file. - Purpose string `json:"purpose"` -} - -// GetFile returns the value of File. -func (s *CreateFileRequest) GetFile() string { - return s.File -} - -// GetPurpose returns the value of Purpose. -func (s *CreateFileRequest) GetPurpose() string { - return s.Purpose -} - -// SetFile sets the value of File. -func (s *CreateFileRequest) SetFile(val string) { - s.File = val -} - -// SetPurpose sets the value of Purpose. -func (s *CreateFileRequest) SetPurpose(val string) { - s.Purpose = val -} - -// Ref: #/components/schemas/CreateFileRequest -type CreateFileRequestForm struct { +type CreateFileRequestMultipart struct { // Name of the [JSON Lines](https://jsonlines.readthedocs.io/en/latest/) file to be uploaded. // If the `purpose` is set to "fine-tune", each line is a JSON record with "prompt" and "completion" // fields representing your [training examples](/docs/guides/fine-tuning/prepare-training-data). @@ -2450,22 +2418,22 @@ type CreateFileRequestForm struct { } // GetFile returns the value of File. -func (s *CreateFileRequestForm) GetFile() ht.MultipartFile { +func (s *CreateFileRequestMultipart) GetFile() ht.MultipartFile { return s.File } // GetPurpose returns the value of Purpose. -func (s *CreateFileRequestForm) GetPurpose() string { +func (s *CreateFileRequestMultipart) GetPurpose() string { return s.Purpose } // SetFile sets the value of File. -func (s *CreateFileRequestForm) SetFile(val ht.MultipartFile) { +func (s *CreateFileRequestMultipart) SetFile(val ht.MultipartFile) { s.File = val } // SetPurpose sets the value of Purpose. -func (s *CreateFileRequestForm) SetPurpose(val string) { +func (s *CreateFileRequestMultipart) SetPurpose(val string) { s.Purpose = val } @@ -2671,99 +2639,7 @@ func (s *CreateFineTuneRequest) SetSuffix(val OptNilString) { } // Ref: #/components/schemas/CreateImageEditRequest -type CreateImageEditRequest struct { - // The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, - // image must have transparency, which will be used as the mask. - Image string `json:"image"` - // An additional image whose fully transparent areas (e.g. where alpha is zero) indicate where - // `image` should be edited. Must be a valid PNG file, less than 4MB, and have the same dimensions as - // `image`. - Mask OptString `json:"mask"` - // A text description of the desired image(s). The maximum length is 1000 characters. - Prompt string `json:"prompt"` - // The number of images to generate. Must be between 1 and 10. - N OptNilInt `json:"n"` - // The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - Size OptNilCreateImageEditRequestSize `json:"size"` - // The format in which the generated images are returned. Must be one of `url` or `b64_json`. - ResponseFormat OptNilCreateImageEditRequestResponseFormat `json:"response_format"` - // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. - // [Learn more](/docs/guides/safety-best-practices/end-user-ids). - User OptString `json:"user"` -} - -// GetImage returns the value of Image. -func (s *CreateImageEditRequest) GetImage() string { - return s.Image -} - -// GetMask returns the value of Mask. -func (s *CreateImageEditRequest) GetMask() OptString { - return s.Mask -} - -// GetPrompt returns the value of Prompt. -func (s *CreateImageEditRequest) GetPrompt() string { - return s.Prompt -} - -// GetN returns the value of N. -func (s *CreateImageEditRequest) GetN() OptNilInt { - return s.N -} - -// GetSize returns the value of Size. -func (s *CreateImageEditRequest) GetSize() OptNilCreateImageEditRequestSize { - return s.Size -} - -// GetResponseFormat returns the value of ResponseFormat. -func (s *CreateImageEditRequest) GetResponseFormat() OptNilCreateImageEditRequestResponseFormat { - return s.ResponseFormat -} - -// GetUser returns the value of User. -func (s *CreateImageEditRequest) GetUser() OptString { - return s.User -} - -// SetImage sets the value of Image. -func (s *CreateImageEditRequest) SetImage(val string) { - s.Image = val -} - -// SetMask sets the value of Mask. -func (s *CreateImageEditRequest) SetMask(val OptString) { - s.Mask = val -} - -// SetPrompt sets the value of Prompt. -func (s *CreateImageEditRequest) SetPrompt(val string) { - s.Prompt = val -} - -// SetN sets the value of N. -func (s *CreateImageEditRequest) SetN(val OptNilInt) { - s.N = val -} - -// SetSize sets the value of Size. -func (s *CreateImageEditRequest) SetSize(val OptNilCreateImageEditRequestSize) { - s.Size = val -} - -// SetResponseFormat sets the value of ResponseFormat. -func (s *CreateImageEditRequest) SetResponseFormat(val OptNilCreateImageEditRequestResponseFormat) { - s.ResponseFormat = val -} - -// SetUser sets the value of User. -func (s *CreateImageEditRequest) SetUser(val OptString) { - s.User = val -} - -// Ref: #/components/schemas/CreateImageEditRequest -type CreateImageEditRequestForm struct { +type CreateImageEditRequestMultipart struct { // The image to edit. Must be a valid PNG file, less than 4MB, and square. If mask is not provided, // image must have transparency, which will be used as the mask. Image ht.MultipartFile `json:"image"` @@ -2776,98 +2652,98 @@ type CreateImageEditRequestForm struct { // The number of images to generate. Must be between 1 and 10. N OptNilInt `json:"n"` // The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - Size OptNilCreateImageEditRequestSize `json:"size"` + Size OptNilCreateImageEditRequestMultipartSize `json:"size"` // The format in which the generated images are returned. Must be one of `url` or `b64_json`. - ResponseFormat OptNilCreateImageEditRequestResponseFormat `json:"response_format"` + ResponseFormat OptNilCreateImageEditRequestMultipartResponseFormat `json:"response_format"` // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. // [Learn more](/docs/guides/safety-best-practices/end-user-ids). User OptString `json:"user"` } // GetImage returns the value of Image. -func (s *CreateImageEditRequestForm) GetImage() ht.MultipartFile { +func (s *CreateImageEditRequestMultipart) GetImage() ht.MultipartFile { return s.Image } // GetMask returns the value of Mask. -func (s *CreateImageEditRequestForm) GetMask() OptMultipartFile { +func (s *CreateImageEditRequestMultipart) GetMask() OptMultipartFile { return s.Mask } // GetPrompt returns the value of Prompt. -func (s *CreateImageEditRequestForm) GetPrompt() string { +func (s *CreateImageEditRequestMultipart) GetPrompt() string { return s.Prompt } // GetN returns the value of N. -func (s *CreateImageEditRequestForm) GetN() OptNilInt { +func (s *CreateImageEditRequestMultipart) GetN() OptNilInt { return s.N } // GetSize returns the value of Size. -func (s *CreateImageEditRequestForm) GetSize() OptNilCreateImageEditRequestSize { +func (s *CreateImageEditRequestMultipart) GetSize() OptNilCreateImageEditRequestMultipartSize { return s.Size } // GetResponseFormat returns the value of ResponseFormat. -func (s *CreateImageEditRequestForm) GetResponseFormat() OptNilCreateImageEditRequestResponseFormat { +func (s *CreateImageEditRequestMultipart) GetResponseFormat() OptNilCreateImageEditRequestMultipartResponseFormat { return s.ResponseFormat } // GetUser returns the value of User. -func (s *CreateImageEditRequestForm) GetUser() OptString { +func (s *CreateImageEditRequestMultipart) GetUser() OptString { return s.User } // SetImage sets the value of Image. -func (s *CreateImageEditRequestForm) SetImage(val ht.MultipartFile) { +func (s *CreateImageEditRequestMultipart) SetImage(val ht.MultipartFile) { s.Image = val } // SetMask sets the value of Mask. -func (s *CreateImageEditRequestForm) SetMask(val OptMultipartFile) { +func (s *CreateImageEditRequestMultipart) SetMask(val OptMultipartFile) { s.Mask = val } // SetPrompt sets the value of Prompt. -func (s *CreateImageEditRequestForm) SetPrompt(val string) { +func (s *CreateImageEditRequestMultipart) SetPrompt(val string) { s.Prompt = val } // SetN sets the value of N. -func (s *CreateImageEditRequestForm) SetN(val OptNilInt) { +func (s *CreateImageEditRequestMultipart) SetN(val OptNilInt) { s.N = val } // SetSize sets the value of Size. -func (s *CreateImageEditRequestForm) SetSize(val OptNilCreateImageEditRequestSize) { +func (s *CreateImageEditRequestMultipart) SetSize(val OptNilCreateImageEditRequestMultipartSize) { s.Size = val } // SetResponseFormat sets the value of ResponseFormat. -func (s *CreateImageEditRequestForm) SetResponseFormat(val OptNilCreateImageEditRequestResponseFormat) { +func (s *CreateImageEditRequestMultipart) SetResponseFormat(val OptNilCreateImageEditRequestMultipartResponseFormat) { s.ResponseFormat = val } // SetUser sets the value of User. -func (s *CreateImageEditRequestForm) SetUser(val OptString) { +func (s *CreateImageEditRequestMultipart) SetUser(val OptString) { s.User = val } // The format in which the generated images are returned. Must be one of `url` or `b64_json`. -type CreateImageEditRequestResponseFormat string +type CreateImageEditRequestMultipartResponseFormat string const ( - CreateImageEditRequestResponseFormatURL CreateImageEditRequestResponseFormat = "url" - CreateImageEditRequestResponseFormatB64JSON CreateImageEditRequestResponseFormat = "b64_json" + CreateImageEditRequestMultipartResponseFormatURL CreateImageEditRequestMultipartResponseFormat = "url" + CreateImageEditRequestMultipartResponseFormatB64JSON CreateImageEditRequestMultipartResponseFormat = "b64_json" ) // MarshalText implements encoding.TextMarshaler. -func (s CreateImageEditRequestResponseFormat) MarshalText() ([]byte, error) { +func (s CreateImageEditRequestMultipartResponseFormat) MarshalText() ([]byte, error) { switch s { - case CreateImageEditRequestResponseFormatURL: + case CreateImageEditRequestMultipartResponseFormatURL: return []byte(s), nil - case CreateImageEditRequestResponseFormatB64JSON: + case CreateImageEditRequestMultipartResponseFormatB64JSON: return []byte(s), nil default: return nil, errors.Errorf("invalid value: %q", s) @@ -2875,13 +2751,13 @@ func (s CreateImageEditRequestResponseFormat) MarshalText() ([]byte, error) { } // UnmarshalText implements encoding.TextUnmarshaler. -func (s *CreateImageEditRequestResponseFormat) UnmarshalText(data []byte) error { - switch CreateImageEditRequestResponseFormat(data) { - case CreateImageEditRequestResponseFormatURL: - *s = CreateImageEditRequestResponseFormatURL +func (s *CreateImageEditRequestMultipartResponseFormat) UnmarshalText(data []byte) error { + switch CreateImageEditRequestMultipartResponseFormat(data) { + case CreateImageEditRequestMultipartResponseFormatURL: + *s = CreateImageEditRequestMultipartResponseFormatURL return nil - case CreateImageEditRequestResponseFormatB64JSON: - *s = CreateImageEditRequestResponseFormatB64JSON + case CreateImageEditRequestMultipartResponseFormatB64JSON: + *s = CreateImageEditRequestMultipartResponseFormatB64JSON return nil default: return errors.Errorf("invalid value: %q", data) @@ -2889,22 +2765,22 @@ func (s *CreateImageEditRequestResponseFormat) UnmarshalText(data []byte) error } // The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. -type CreateImageEditRequestSize string +type CreateImageEditRequestMultipartSize string const ( - CreateImageEditRequestSize256x256 CreateImageEditRequestSize = "256x256" - CreateImageEditRequestSize512x512 CreateImageEditRequestSize = "512x512" - CreateImageEditRequestSize1024x1024 CreateImageEditRequestSize = "1024x1024" + CreateImageEditRequestMultipartSize256x256 CreateImageEditRequestMultipartSize = "256x256" + CreateImageEditRequestMultipartSize512x512 CreateImageEditRequestMultipartSize = "512x512" + CreateImageEditRequestMultipartSize1024x1024 CreateImageEditRequestMultipartSize = "1024x1024" ) // MarshalText implements encoding.TextMarshaler. -func (s CreateImageEditRequestSize) MarshalText() ([]byte, error) { +func (s CreateImageEditRequestMultipartSize) MarshalText() ([]byte, error) { switch s { - case CreateImageEditRequestSize256x256: + case CreateImageEditRequestMultipartSize256x256: return []byte(s), nil - case CreateImageEditRequestSize512x512: + case CreateImageEditRequestMultipartSize512x512: return []byte(s), nil - case CreateImageEditRequestSize1024x1024: + case CreateImageEditRequestMultipartSize1024x1024: return []byte(s), nil default: return nil, errors.Errorf("invalid value: %q", s) @@ -2912,16 +2788,16 @@ func (s CreateImageEditRequestSize) MarshalText() ([]byte, error) { } // UnmarshalText implements encoding.TextUnmarshaler. -func (s *CreateImageEditRequestSize) UnmarshalText(data []byte) error { - switch CreateImageEditRequestSize(data) { - case CreateImageEditRequestSize256x256: - *s = CreateImageEditRequestSize256x256 +func (s *CreateImageEditRequestMultipartSize) UnmarshalText(data []byte) error { + switch CreateImageEditRequestMultipartSize(data) { + case CreateImageEditRequestMultipartSize256x256: + *s = CreateImageEditRequestMultipartSize256x256 return nil - case CreateImageEditRequestSize512x512: - *s = CreateImageEditRequestSize512x512 + case CreateImageEditRequestMultipartSize512x512: + *s = CreateImageEditRequestMultipartSize512x512 return nil - case CreateImageEditRequestSize1024x1024: - *s = CreateImageEditRequestSize1024x1024 + case CreateImageEditRequestMultipartSize1024x1024: + *s = CreateImageEditRequestMultipartSize1024x1024 return nil default: return errors.Errorf("invalid value: %q", data) @@ -3068,151 +2944,85 @@ func (s *CreateImageRequestSize) UnmarshalText(data []byte) error { } // Ref: #/components/schemas/CreateImageVariationRequest -type CreateImageVariationRequest struct { - // The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and - // square. - Image string `json:"image"` - // The number of images to generate. Must be between 1 and 10. - N OptNilInt `json:"n"` - // The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - Size OptNilCreateImageVariationRequestSize `json:"size"` - // The format in which the generated images are returned. Must be one of `url` or `b64_json`. - ResponseFormat OptNilCreateImageVariationRequestResponseFormat `json:"response_format"` - // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. - // [Learn more](/docs/guides/safety-best-practices/end-user-ids). - User OptString `json:"user"` -} - -// GetImage returns the value of Image. -func (s *CreateImageVariationRequest) GetImage() string { - return s.Image -} - -// GetN returns the value of N. -func (s *CreateImageVariationRequest) GetN() OptNilInt { - return s.N -} - -// GetSize returns the value of Size. -func (s *CreateImageVariationRequest) GetSize() OptNilCreateImageVariationRequestSize { - return s.Size -} - -// GetResponseFormat returns the value of ResponseFormat. -func (s *CreateImageVariationRequest) GetResponseFormat() OptNilCreateImageVariationRequestResponseFormat { - return s.ResponseFormat -} - -// GetUser returns the value of User. -func (s *CreateImageVariationRequest) GetUser() OptString { - return s.User -} - -// SetImage sets the value of Image. -func (s *CreateImageVariationRequest) SetImage(val string) { - s.Image = val -} - -// SetN sets the value of N. -func (s *CreateImageVariationRequest) SetN(val OptNilInt) { - s.N = val -} - -// SetSize sets the value of Size. -func (s *CreateImageVariationRequest) SetSize(val OptNilCreateImageVariationRequestSize) { - s.Size = val -} - -// SetResponseFormat sets the value of ResponseFormat. -func (s *CreateImageVariationRequest) SetResponseFormat(val OptNilCreateImageVariationRequestResponseFormat) { - s.ResponseFormat = val -} - -// SetUser sets the value of User. -func (s *CreateImageVariationRequest) SetUser(val OptString) { - s.User = val -} - -// Ref: #/components/schemas/CreateImageVariationRequest -type CreateImageVariationRequestForm struct { +type CreateImageVariationRequestMultipart struct { // The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and // square. Image ht.MultipartFile `json:"image"` // The number of images to generate. Must be between 1 and 10. N OptNilInt `json:"n"` // The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. - Size OptNilCreateImageVariationRequestSize `json:"size"` + Size OptNilCreateImageVariationRequestMultipartSize `json:"size"` // The format in which the generated images are returned. Must be one of `url` or `b64_json`. - ResponseFormat OptNilCreateImageVariationRequestResponseFormat `json:"response_format"` + ResponseFormat OptNilCreateImageVariationRequestMultipartResponseFormat `json:"response_format"` // A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse. // [Learn more](/docs/guides/safety-best-practices/end-user-ids). User OptString `json:"user"` } // GetImage returns the value of Image. -func (s *CreateImageVariationRequestForm) GetImage() ht.MultipartFile { +func (s *CreateImageVariationRequestMultipart) GetImage() ht.MultipartFile { return s.Image } // GetN returns the value of N. -func (s *CreateImageVariationRequestForm) GetN() OptNilInt { +func (s *CreateImageVariationRequestMultipart) GetN() OptNilInt { return s.N } // GetSize returns the value of Size. -func (s *CreateImageVariationRequestForm) GetSize() OptNilCreateImageVariationRequestSize { +func (s *CreateImageVariationRequestMultipart) GetSize() OptNilCreateImageVariationRequestMultipartSize { return s.Size } // GetResponseFormat returns the value of ResponseFormat. -func (s *CreateImageVariationRequestForm) GetResponseFormat() OptNilCreateImageVariationRequestResponseFormat { +func (s *CreateImageVariationRequestMultipart) GetResponseFormat() OptNilCreateImageVariationRequestMultipartResponseFormat { return s.ResponseFormat } // GetUser returns the value of User. -func (s *CreateImageVariationRequestForm) GetUser() OptString { +func (s *CreateImageVariationRequestMultipart) GetUser() OptString { return s.User } // SetImage sets the value of Image. -func (s *CreateImageVariationRequestForm) SetImage(val ht.MultipartFile) { +func (s *CreateImageVariationRequestMultipart) SetImage(val ht.MultipartFile) { s.Image = val } // SetN sets the value of N. -func (s *CreateImageVariationRequestForm) SetN(val OptNilInt) { +func (s *CreateImageVariationRequestMultipart) SetN(val OptNilInt) { s.N = val } // SetSize sets the value of Size. -func (s *CreateImageVariationRequestForm) SetSize(val OptNilCreateImageVariationRequestSize) { +func (s *CreateImageVariationRequestMultipart) SetSize(val OptNilCreateImageVariationRequestMultipartSize) { s.Size = val } // SetResponseFormat sets the value of ResponseFormat. -func (s *CreateImageVariationRequestForm) SetResponseFormat(val OptNilCreateImageVariationRequestResponseFormat) { +func (s *CreateImageVariationRequestMultipart) SetResponseFormat(val OptNilCreateImageVariationRequestMultipartResponseFormat) { s.ResponseFormat = val } // SetUser sets the value of User. -func (s *CreateImageVariationRequestForm) SetUser(val OptString) { +func (s *CreateImageVariationRequestMultipart) SetUser(val OptString) { s.User = val } // The format in which the generated images are returned. Must be one of `url` or `b64_json`. -type CreateImageVariationRequestResponseFormat string +type CreateImageVariationRequestMultipartResponseFormat string const ( - CreateImageVariationRequestResponseFormatURL CreateImageVariationRequestResponseFormat = "url" - CreateImageVariationRequestResponseFormatB64JSON CreateImageVariationRequestResponseFormat = "b64_json" + CreateImageVariationRequestMultipartResponseFormatURL CreateImageVariationRequestMultipartResponseFormat = "url" + CreateImageVariationRequestMultipartResponseFormatB64JSON CreateImageVariationRequestMultipartResponseFormat = "b64_json" ) // MarshalText implements encoding.TextMarshaler. -func (s CreateImageVariationRequestResponseFormat) MarshalText() ([]byte, error) { +func (s CreateImageVariationRequestMultipartResponseFormat) MarshalText() ([]byte, error) { switch s { - case CreateImageVariationRequestResponseFormatURL: + case CreateImageVariationRequestMultipartResponseFormatURL: return []byte(s), nil - case CreateImageVariationRequestResponseFormatB64JSON: + case CreateImageVariationRequestMultipartResponseFormatB64JSON: return []byte(s), nil default: return nil, errors.Errorf("invalid value: %q", s) @@ -3220,13 +3030,13 @@ func (s CreateImageVariationRequestResponseFormat) MarshalText() ([]byte, error) } // UnmarshalText implements encoding.TextUnmarshaler. -func (s *CreateImageVariationRequestResponseFormat) UnmarshalText(data []byte) error { - switch CreateImageVariationRequestResponseFormat(data) { - case CreateImageVariationRequestResponseFormatURL: - *s = CreateImageVariationRequestResponseFormatURL +func (s *CreateImageVariationRequestMultipartResponseFormat) UnmarshalText(data []byte) error { + switch CreateImageVariationRequestMultipartResponseFormat(data) { + case CreateImageVariationRequestMultipartResponseFormatURL: + *s = CreateImageVariationRequestMultipartResponseFormatURL return nil - case CreateImageVariationRequestResponseFormatB64JSON: - *s = CreateImageVariationRequestResponseFormatB64JSON + case CreateImageVariationRequestMultipartResponseFormatB64JSON: + *s = CreateImageVariationRequestMultipartResponseFormatB64JSON return nil default: return errors.Errorf("invalid value: %q", data) @@ -3234,22 +3044,22 @@ func (s *CreateImageVariationRequestResponseFormat) UnmarshalText(data []byte) e } // The size of the generated images. Must be one of `256x256`, `512x512`, or `1024x1024`. -type CreateImageVariationRequestSize string +type CreateImageVariationRequestMultipartSize string const ( - CreateImageVariationRequestSize256x256 CreateImageVariationRequestSize = "256x256" - CreateImageVariationRequestSize512x512 CreateImageVariationRequestSize = "512x512" - CreateImageVariationRequestSize1024x1024 CreateImageVariationRequestSize = "1024x1024" + CreateImageVariationRequestMultipartSize256x256 CreateImageVariationRequestMultipartSize = "256x256" + CreateImageVariationRequestMultipartSize512x512 CreateImageVariationRequestMultipartSize = "512x512" + CreateImageVariationRequestMultipartSize1024x1024 CreateImageVariationRequestMultipartSize = "1024x1024" ) // MarshalText implements encoding.TextMarshaler. -func (s CreateImageVariationRequestSize) MarshalText() ([]byte, error) { +func (s CreateImageVariationRequestMultipartSize) MarshalText() ([]byte, error) { switch s { - case CreateImageVariationRequestSize256x256: + case CreateImageVariationRequestMultipartSize256x256: return []byte(s), nil - case CreateImageVariationRequestSize512x512: + case CreateImageVariationRequestMultipartSize512x512: return []byte(s), nil - case CreateImageVariationRequestSize1024x1024: + case CreateImageVariationRequestMultipartSize1024x1024: return []byte(s), nil default: return nil, errors.Errorf("invalid value: %q", s) @@ -3257,16 +3067,16 @@ func (s CreateImageVariationRequestSize) MarshalText() ([]byte, error) { } // UnmarshalText implements encoding.TextUnmarshaler. -func (s *CreateImageVariationRequestSize) UnmarshalText(data []byte) error { - switch CreateImageVariationRequestSize(data) { - case CreateImageVariationRequestSize256x256: - *s = CreateImageVariationRequestSize256x256 +func (s *CreateImageVariationRequestMultipartSize) UnmarshalText(data []byte) error { + switch CreateImageVariationRequestMultipartSize(data) { + case CreateImageVariationRequestMultipartSize256x256: + *s = CreateImageVariationRequestMultipartSize256x256 return nil - case CreateImageVariationRequestSize512x512: - *s = CreateImageVariationRequestSize512x512 + case CreateImageVariationRequestMultipartSize512x512: + *s = CreateImageVariationRequestMultipartSize512x512 return nil - case CreateImageVariationRequestSize1024x1024: - *s = CreateImageVariationRequestSize1024x1024 + case CreateImageVariationRequestMultipartSize1024x1024: + *s = CreateImageVariationRequestMultipartSize1024x1024 return nil default: return errors.Errorf("invalid value: %q", data) @@ -3765,89 +3575,7 @@ func (s *CreateSearchResponseDataItem) SetScore(val OptFloat64) { } // Ref: #/components/schemas/CreateTranscriptionRequest -type CreateTranscriptionRequest struct { - // The audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. - File string `json:"file"` - // ID of the model to use. Only `whisper-1` is currently available. - Model string `json:"model"` - // An optional text to guide the model's style or continue a previous audio segment. The - // [prompt](/docs/guides/speech-to-text/prompting) should match the audio language. - Prompt OptString `json:"prompt"` - // The format of the transcript output, in one of these options: json, text, srt, verbose_json, or - // vtt. - ResponseFormat OptString `json:"response_format"` - // The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, - // while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model - // will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically - // increase the temperature until certain thresholds are hit. - Temperature OptFloat64 `json:"temperature"` - // The language of the input audio. Supplying the input language in [ISO-639-1](https://en.wikipedia. - // org/wiki/List_of_ISO_639-1_codes) format will improve accuracy and latency. - Language OptString `json:"language"` -} - -// GetFile returns the value of File. -func (s *CreateTranscriptionRequest) GetFile() string { - return s.File -} - -// GetModel returns the value of Model. -func (s *CreateTranscriptionRequest) GetModel() string { - return s.Model -} - -// GetPrompt returns the value of Prompt. -func (s *CreateTranscriptionRequest) GetPrompt() OptString { - return s.Prompt -} - -// GetResponseFormat returns the value of ResponseFormat. -func (s *CreateTranscriptionRequest) GetResponseFormat() OptString { - return s.ResponseFormat -} - -// GetTemperature returns the value of Temperature. -func (s *CreateTranscriptionRequest) GetTemperature() OptFloat64 { - return s.Temperature -} - -// GetLanguage returns the value of Language. -func (s *CreateTranscriptionRequest) GetLanguage() OptString { - return s.Language -} - -// SetFile sets the value of File. -func (s *CreateTranscriptionRequest) SetFile(val string) { - s.File = val -} - -// SetModel sets the value of Model. -func (s *CreateTranscriptionRequest) SetModel(val string) { - s.Model = val -} - -// SetPrompt sets the value of Prompt. -func (s *CreateTranscriptionRequest) SetPrompt(val OptString) { - s.Prompt = val -} - -// SetResponseFormat sets the value of ResponseFormat. -func (s *CreateTranscriptionRequest) SetResponseFormat(val OptString) { - s.ResponseFormat = val -} - -// SetTemperature sets the value of Temperature. -func (s *CreateTranscriptionRequest) SetTemperature(val OptFloat64) { - s.Temperature = val -} - -// SetLanguage sets the value of Language. -func (s *CreateTranscriptionRequest) SetLanguage(val OptString) { - s.Language = val -} - -// Ref: #/components/schemas/CreateTranscriptionRequest -type CreateTranscriptionRequestForm struct { +type CreateTranscriptionRequestMultipart struct { // The audio file to transcribe, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. File ht.MultipartFile `json:"file"` // ID of the model to use. Only `whisper-1` is currently available. @@ -3869,62 +3597,62 @@ type CreateTranscriptionRequestForm struct { } // GetFile returns the value of File. -func (s *CreateTranscriptionRequestForm) GetFile() ht.MultipartFile { +func (s *CreateTranscriptionRequestMultipart) GetFile() ht.MultipartFile { return s.File } // GetModel returns the value of Model. -func (s *CreateTranscriptionRequestForm) GetModel() string { +func (s *CreateTranscriptionRequestMultipart) GetModel() string { return s.Model } // GetPrompt returns the value of Prompt. -func (s *CreateTranscriptionRequestForm) GetPrompt() OptString { +func (s *CreateTranscriptionRequestMultipart) GetPrompt() OptString { return s.Prompt } // GetResponseFormat returns the value of ResponseFormat. -func (s *CreateTranscriptionRequestForm) GetResponseFormat() OptString { +func (s *CreateTranscriptionRequestMultipart) GetResponseFormat() OptString { return s.ResponseFormat } // GetTemperature returns the value of Temperature. -func (s *CreateTranscriptionRequestForm) GetTemperature() OptFloat64 { +func (s *CreateTranscriptionRequestMultipart) GetTemperature() OptFloat64 { return s.Temperature } // GetLanguage returns the value of Language. -func (s *CreateTranscriptionRequestForm) GetLanguage() OptString { +func (s *CreateTranscriptionRequestMultipart) GetLanguage() OptString { return s.Language } // SetFile sets the value of File. -func (s *CreateTranscriptionRequestForm) SetFile(val ht.MultipartFile) { +func (s *CreateTranscriptionRequestMultipart) SetFile(val ht.MultipartFile) { s.File = val } // SetModel sets the value of Model. -func (s *CreateTranscriptionRequestForm) SetModel(val string) { +func (s *CreateTranscriptionRequestMultipart) SetModel(val string) { s.Model = val } // SetPrompt sets the value of Prompt. -func (s *CreateTranscriptionRequestForm) SetPrompt(val OptString) { +func (s *CreateTranscriptionRequestMultipart) SetPrompt(val OptString) { s.Prompt = val } // SetResponseFormat sets the value of ResponseFormat. -func (s *CreateTranscriptionRequestForm) SetResponseFormat(val OptString) { +func (s *CreateTranscriptionRequestMultipart) SetResponseFormat(val OptString) { s.ResponseFormat = val } // SetTemperature sets the value of Temperature. -func (s *CreateTranscriptionRequestForm) SetTemperature(val OptFloat64) { +func (s *CreateTranscriptionRequestMultipart) SetTemperature(val OptFloat64) { s.Temperature = val } // SetLanguage sets the value of Language. -func (s *CreateTranscriptionRequestForm) SetLanguage(val OptString) { +func (s *CreateTranscriptionRequestMultipart) SetLanguage(val OptString) { s.Language = val } @@ -3944,76 +3672,7 @@ func (s *CreateTranscriptionResponse) SetText(val string) { } // Ref: #/components/schemas/CreateTranslationRequest -type CreateTranslationRequest struct { - // The audio file to translate, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. - File string `json:"file"` - // ID of the model to use. Only `whisper-1` is currently available. - Model string `json:"model"` - // An optional text to guide the model's style or continue a previous audio segment. The - // [prompt](/docs/guides/speech-to-text/prompting) should be in English. - Prompt OptString `json:"prompt"` - // The format of the transcript output, in one of these options: json, text, srt, verbose_json, or - // vtt. - ResponseFormat OptString `json:"response_format"` - // The sampling temperature, between 0 and 1. Higher values like 0.8 will make the output more random, - // while lower values like 0.2 will make it more focused and deterministic. If set to 0, the model - // will use [log probability](https://en.wikipedia.org/wiki/Log_probability) to automatically - // increase the temperature until certain thresholds are hit. - Temperature OptFloat64 `json:"temperature"` -} - -// GetFile returns the value of File. -func (s *CreateTranslationRequest) GetFile() string { - return s.File -} - -// GetModel returns the value of Model. -func (s *CreateTranslationRequest) GetModel() string { - return s.Model -} - -// GetPrompt returns the value of Prompt. -func (s *CreateTranslationRequest) GetPrompt() OptString { - return s.Prompt -} - -// GetResponseFormat returns the value of ResponseFormat. -func (s *CreateTranslationRequest) GetResponseFormat() OptString { - return s.ResponseFormat -} - -// GetTemperature returns the value of Temperature. -func (s *CreateTranslationRequest) GetTemperature() OptFloat64 { - return s.Temperature -} - -// SetFile sets the value of File. -func (s *CreateTranslationRequest) SetFile(val string) { - s.File = val -} - -// SetModel sets the value of Model. -func (s *CreateTranslationRequest) SetModel(val string) { - s.Model = val -} - -// SetPrompt sets the value of Prompt. -func (s *CreateTranslationRequest) SetPrompt(val OptString) { - s.Prompt = val -} - -// SetResponseFormat sets the value of ResponseFormat. -func (s *CreateTranslationRequest) SetResponseFormat(val OptString) { - s.ResponseFormat = val -} - -// SetTemperature sets the value of Temperature. -func (s *CreateTranslationRequest) SetTemperature(val OptFloat64) { - s.Temperature = val -} - -// Ref: #/components/schemas/CreateTranslationRequest -type CreateTranslationRequestForm struct { +type CreateTranslationRequestMultipart struct { // The audio file to translate, in one of these formats: mp3, mp4, mpeg, mpga, m4a, wav, or webm. File ht.MultipartFile `json:"file"` // ID of the model to use. Only `whisper-1` is currently available. @@ -4032,52 +3691,52 @@ type CreateTranslationRequestForm struct { } // GetFile returns the value of File. -func (s *CreateTranslationRequestForm) GetFile() ht.MultipartFile { +func (s *CreateTranslationRequestMultipart) GetFile() ht.MultipartFile { return s.File } // GetModel returns the value of Model. -func (s *CreateTranslationRequestForm) GetModel() string { +func (s *CreateTranslationRequestMultipart) GetModel() string { return s.Model } // GetPrompt returns the value of Prompt. -func (s *CreateTranslationRequestForm) GetPrompt() OptString { +func (s *CreateTranslationRequestMultipart) GetPrompt() OptString { return s.Prompt } // GetResponseFormat returns the value of ResponseFormat. -func (s *CreateTranslationRequestForm) GetResponseFormat() OptString { +func (s *CreateTranslationRequestMultipart) GetResponseFormat() OptString { return s.ResponseFormat } // GetTemperature returns the value of Temperature. -func (s *CreateTranslationRequestForm) GetTemperature() OptFloat64 { +func (s *CreateTranslationRequestMultipart) GetTemperature() OptFloat64 { return s.Temperature } // SetFile sets the value of File. -func (s *CreateTranslationRequestForm) SetFile(val ht.MultipartFile) { +func (s *CreateTranslationRequestMultipart) SetFile(val ht.MultipartFile) { s.File = val } // SetModel sets the value of Model. -func (s *CreateTranslationRequestForm) SetModel(val string) { +func (s *CreateTranslationRequestMultipart) SetModel(val string) { s.Model = val } // SetPrompt sets the value of Prompt. -func (s *CreateTranslationRequestForm) SetPrompt(val OptString) { +func (s *CreateTranslationRequestMultipart) SetPrompt(val OptString) { s.Prompt = val } // SetResponseFormat sets the value of ResponseFormat. -func (s *CreateTranslationRequestForm) SetResponseFormat(val OptString) { +func (s *CreateTranslationRequestMultipart) SetResponseFormat(val OptString) { s.ResponseFormat = val } // SetTemperature sets the value of Temperature. -func (s *CreateTranslationRequestForm) SetTemperature(val OptFloat64) { +func (s *CreateTranslationRequestMultipart) SetTemperature(val OptFloat64) { s.Temperature = val } @@ -5322,52 +4981,52 @@ func (o OptNilCreateEditResponseChoicesItemLogprobs) Or(d CreateEditResponseChoi return d } -// NewOptNilCreateImageEditRequestResponseFormat returns new OptNilCreateImageEditRequestResponseFormat with value set to v. -func NewOptNilCreateImageEditRequestResponseFormat(v CreateImageEditRequestResponseFormat) OptNilCreateImageEditRequestResponseFormat { - return OptNilCreateImageEditRequestResponseFormat{ +// NewOptNilCreateImageEditRequestMultipartResponseFormat returns new OptNilCreateImageEditRequestMultipartResponseFormat with value set to v. +func NewOptNilCreateImageEditRequestMultipartResponseFormat(v CreateImageEditRequestMultipartResponseFormat) OptNilCreateImageEditRequestMultipartResponseFormat { + return OptNilCreateImageEditRequestMultipartResponseFormat{ Value: v, Set: true, } } -// OptNilCreateImageEditRequestResponseFormat is optional nullable CreateImageEditRequestResponseFormat. -type OptNilCreateImageEditRequestResponseFormat struct { - Value CreateImageEditRequestResponseFormat +// OptNilCreateImageEditRequestMultipartResponseFormat is optional nullable CreateImageEditRequestMultipartResponseFormat. +type OptNilCreateImageEditRequestMultipartResponseFormat struct { + Value CreateImageEditRequestMultipartResponseFormat Set bool Null bool } -// IsSet returns true if OptNilCreateImageEditRequestResponseFormat was set. -func (o OptNilCreateImageEditRequestResponseFormat) IsSet() bool { return o.Set } +// IsSet returns true if OptNilCreateImageEditRequestMultipartResponseFormat was set. +func (o OptNilCreateImageEditRequestMultipartResponseFormat) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateImageEditRequestResponseFormat) Reset() { - var v CreateImageEditRequestResponseFormat +func (o *OptNilCreateImageEditRequestMultipartResponseFormat) Reset() { + var v CreateImageEditRequestMultipartResponseFormat o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateImageEditRequestResponseFormat) SetTo(v CreateImageEditRequestResponseFormat) { +func (o *OptNilCreateImageEditRequestMultipartResponseFormat) SetTo(v CreateImageEditRequestMultipartResponseFormat) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateImageEditRequestResponseFormat) IsNull() bool { return o.Null } +func (o OptNilCreateImageEditRequestMultipartResponseFormat) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateImageEditRequestResponseFormat) SetToNull() { +func (o *OptNilCreateImageEditRequestMultipartResponseFormat) SetToNull() { o.Set = true o.Null = true - var v CreateImageEditRequestResponseFormat + var v CreateImageEditRequestMultipartResponseFormat o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateImageEditRequestResponseFormat) Get() (v CreateImageEditRequestResponseFormat, ok bool) { +func (o OptNilCreateImageEditRequestMultipartResponseFormat) Get() (v CreateImageEditRequestMultipartResponseFormat, ok bool) { if o.Null { return v, false } @@ -5378,59 +5037,59 @@ func (o OptNilCreateImageEditRequestResponseFormat) Get() (v CreateImageEditRequ } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateImageEditRequestResponseFormat) Or(d CreateImageEditRequestResponseFormat) CreateImageEditRequestResponseFormat { +func (o OptNilCreateImageEditRequestMultipartResponseFormat) Or(d CreateImageEditRequestMultipartResponseFormat) CreateImageEditRequestMultipartResponseFormat { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateImageEditRequestSize returns new OptNilCreateImageEditRequestSize with value set to v. -func NewOptNilCreateImageEditRequestSize(v CreateImageEditRequestSize) OptNilCreateImageEditRequestSize { - return OptNilCreateImageEditRequestSize{ +// NewOptNilCreateImageEditRequestMultipartSize returns new OptNilCreateImageEditRequestMultipartSize with value set to v. +func NewOptNilCreateImageEditRequestMultipartSize(v CreateImageEditRequestMultipartSize) OptNilCreateImageEditRequestMultipartSize { + return OptNilCreateImageEditRequestMultipartSize{ Value: v, Set: true, } } -// OptNilCreateImageEditRequestSize is optional nullable CreateImageEditRequestSize. -type OptNilCreateImageEditRequestSize struct { - Value CreateImageEditRequestSize +// OptNilCreateImageEditRequestMultipartSize is optional nullable CreateImageEditRequestMultipartSize. +type OptNilCreateImageEditRequestMultipartSize struct { + Value CreateImageEditRequestMultipartSize Set bool Null bool } -// IsSet returns true if OptNilCreateImageEditRequestSize was set. -func (o OptNilCreateImageEditRequestSize) IsSet() bool { return o.Set } +// IsSet returns true if OptNilCreateImageEditRequestMultipartSize was set. +func (o OptNilCreateImageEditRequestMultipartSize) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateImageEditRequestSize) Reset() { - var v CreateImageEditRequestSize +func (o *OptNilCreateImageEditRequestMultipartSize) Reset() { + var v CreateImageEditRequestMultipartSize o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateImageEditRequestSize) SetTo(v CreateImageEditRequestSize) { +func (o *OptNilCreateImageEditRequestMultipartSize) SetTo(v CreateImageEditRequestMultipartSize) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateImageEditRequestSize) IsNull() bool { return o.Null } +func (o OptNilCreateImageEditRequestMultipartSize) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateImageEditRequestSize) SetToNull() { +func (o *OptNilCreateImageEditRequestMultipartSize) SetToNull() { o.Set = true o.Null = true - var v CreateImageEditRequestSize + var v CreateImageEditRequestMultipartSize o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateImageEditRequestSize) Get() (v CreateImageEditRequestSize, ok bool) { +func (o OptNilCreateImageEditRequestMultipartSize) Get() (v CreateImageEditRequestMultipartSize, ok bool) { if o.Null { return v, false } @@ -5441,7 +5100,7 @@ func (o OptNilCreateImageEditRequestSize) Get() (v CreateImageEditRequestSize, o } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateImageEditRequestSize) Or(d CreateImageEditRequestSize) CreateImageEditRequestSize { +func (o OptNilCreateImageEditRequestMultipartSize) Or(d CreateImageEditRequestMultipartSize) CreateImageEditRequestMultipartSize { if v, ok := o.Get(); ok { return v } @@ -5574,52 +5233,52 @@ func (o OptNilCreateImageRequestSize) Or(d CreateImageRequestSize) CreateImageRe return d } -// NewOptNilCreateImageVariationRequestResponseFormat returns new OptNilCreateImageVariationRequestResponseFormat with value set to v. -func NewOptNilCreateImageVariationRequestResponseFormat(v CreateImageVariationRequestResponseFormat) OptNilCreateImageVariationRequestResponseFormat { - return OptNilCreateImageVariationRequestResponseFormat{ +// NewOptNilCreateImageVariationRequestMultipartResponseFormat returns new OptNilCreateImageVariationRequestMultipartResponseFormat with value set to v. +func NewOptNilCreateImageVariationRequestMultipartResponseFormat(v CreateImageVariationRequestMultipartResponseFormat) OptNilCreateImageVariationRequestMultipartResponseFormat { + return OptNilCreateImageVariationRequestMultipartResponseFormat{ Value: v, Set: true, } } -// OptNilCreateImageVariationRequestResponseFormat is optional nullable CreateImageVariationRequestResponseFormat. -type OptNilCreateImageVariationRequestResponseFormat struct { - Value CreateImageVariationRequestResponseFormat +// OptNilCreateImageVariationRequestMultipartResponseFormat is optional nullable CreateImageVariationRequestMultipartResponseFormat. +type OptNilCreateImageVariationRequestMultipartResponseFormat struct { + Value CreateImageVariationRequestMultipartResponseFormat Set bool Null bool } -// IsSet returns true if OptNilCreateImageVariationRequestResponseFormat was set. -func (o OptNilCreateImageVariationRequestResponseFormat) IsSet() bool { return o.Set } +// IsSet returns true if OptNilCreateImageVariationRequestMultipartResponseFormat was set. +func (o OptNilCreateImageVariationRequestMultipartResponseFormat) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateImageVariationRequestResponseFormat) Reset() { - var v CreateImageVariationRequestResponseFormat +func (o *OptNilCreateImageVariationRequestMultipartResponseFormat) Reset() { + var v CreateImageVariationRequestMultipartResponseFormat o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateImageVariationRequestResponseFormat) SetTo(v CreateImageVariationRequestResponseFormat) { +func (o *OptNilCreateImageVariationRequestMultipartResponseFormat) SetTo(v CreateImageVariationRequestMultipartResponseFormat) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateImageVariationRequestResponseFormat) IsNull() bool { return o.Null } +func (o OptNilCreateImageVariationRequestMultipartResponseFormat) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateImageVariationRequestResponseFormat) SetToNull() { +func (o *OptNilCreateImageVariationRequestMultipartResponseFormat) SetToNull() { o.Set = true o.Null = true - var v CreateImageVariationRequestResponseFormat + var v CreateImageVariationRequestMultipartResponseFormat o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateImageVariationRequestResponseFormat) Get() (v CreateImageVariationRequestResponseFormat, ok bool) { +func (o OptNilCreateImageVariationRequestMultipartResponseFormat) Get() (v CreateImageVariationRequestMultipartResponseFormat, ok bool) { if o.Null { return v, false } @@ -5630,59 +5289,59 @@ func (o OptNilCreateImageVariationRequestResponseFormat) Get() (v CreateImageVar } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateImageVariationRequestResponseFormat) Or(d CreateImageVariationRequestResponseFormat) CreateImageVariationRequestResponseFormat { +func (o OptNilCreateImageVariationRequestMultipartResponseFormat) Or(d CreateImageVariationRequestMultipartResponseFormat) CreateImageVariationRequestMultipartResponseFormat { if v, ok := o.Get(); ok { return v } return d } -// NewOptNilCreateImageVariationRequestSize returns new OptNilCreateImageVariationRequestSize with value set to v. -func NewOptNilCreateImageVariationRequestSize(v CreateImageVariationRequestSize) OptNilCreateImageVariationRequestSize { - return OptNilCreateImageVariationRequestSize{ +// NewOptNilCreateImageVariationRequestMultipartSize returns new OptNilCreateImageVariationRequestMultipartSize with value set to v. +func NewOptNilCreateImageVariationRequestMultipartSize(v CreateImageVariationRequestMultipartSize) OptNilCreateImageVariationRequestMultipartSize { + return OptNilCreateImageVariationRequestMultipartSize{ Value: v, Set: true, } } -// OptNilCreateImageVariationRequestSize is optional nullable CreateImageVariationRequestSize. -type OptNilCreateImageVariationRequestSize struct { - Value CreateImageVariationRequestSize +// OptNilCreateImageVariationRequestMultipartSize is optional nullable CreateImageVariationRequestMultipartSize. +type OptNilCreateImageVariationRequestMultipartSize struct { + Value CreateImageVariationRequestMultipartSize Set bool Null bool } -// IsSet returns true if OptNilCreateImageVariationRequestSize was set. -func (o OptNilCreateImageVariationRequestSize) IsSet() bool { return o.Set } +// IsSet returns true if OptNilCreateImageVariationRequestMultipartSize was set. +func (o OptNilCreateImageVariationRequestMultipartSize) IsSet() bool { return o.Set } // Reset unsets value. -func (o *OptNilCreateImageVariationRequestSize) Reset() { - var v CreateImageVariationRequestSize +func (o *OptNilCreateImageVariationRequestMultipartSize) Reset() { + var v CreateImageVariationRequestMultipartSize o.Value = v o.Set = false o.Null = false } // SetTo sets value to v. -func (o *OptNilCreateImageVariationRequestSize) SetTo(v CreateImageVariationRequestSize) { +func (o *OptNilCreateImageVariationRequestMultipartSize) SetTo(v CreateImageVariationRequestMultipartSize) { o.Set = true o.Null = false o.Value = v } // IsSet returns true if value is Null. -func (o OptNilCreateImageVariationRequestSize) IsNull() bool { return o.Null } +func (o OptNilCreateImageVariationRequestMultipartSize) IsNull() bool { return o.Null } // SetNull sets value to null. -func (o *OptNilCreateImageVariationRequestSize) SetToNull() { +func (o *OptNilCreateImageVariationRequestMultipartSize) SetToNull() { o.Set = true o.Null = true - var v CreateImageVariationRequestSize + var v CreateImageVariationRequestMultipartSize o.Value = v } // Get returns value and boolean that denotes whether value was set. -func (o OptNilCreateImageVariationRequestSize) Get() (v CreateImageVariationRequestSize, ok bool) { +func (o OptNilCreateImageVariationRequestMultipartSize) Get() (v CreateImageVariationRequestMultipartSize, ok bool) { if o.Null { return v, false } @@ -5693,7 +5352,7 @@ func (o OptNilCreateImageVariationRequestSize) Get() (v CreateImageVariationRequ } // Or returns value if set, or given parameter if does not. -func (o OptNilCreateImageVariationRequestSize) Or(d CreateImageVariationRequestSize) CreateImageVariationRequestSize { +func (o OptNilCreateImageVariationRequestMultipartSize) Or(d CreateImageVariationRequestMultipartSize) CreateImageVariationRequestMultipartSize { if v, ok := o.Get(); ok { return v } diff --git a/examples/ex_openai/oas_server_gen.go b/examples/ex_openai/oas_server_gen.go index e08faefca..16fef1066 100644 --- a/examples/ex_openai/oas_server_gen.go +++ b/examples/ex_openai/oas_server_gen.go @@ -70,7 +70,7 @@ type Handler interface { // need to increase the storage limit. // // POST /files - CreateFile(ctx context.Context, req *CreateFileRequestForm) (OpenAIFile, error) + CreateFile(ctx context.Context, req *CreateFileRequestMultipart) (OpenAIFile, error) // CreateFineTune implements createFineTune operation. // // Creates a job that fine-tunes a specified model from a given dataset. @@ -91,13 +91,13 @@ type Handler interface { // Creates an edited or extended image given an original image and a prompt. // // POST /images/edits - CreateImageEdit(ctx context.Context, req *CreateImageEditRequestForm) (ImagesResponse, error) + CreateImageEdit(ctx context.Context, req *CreateImageEditRequestMultipart) (ImagesResponse, error) // CreateImageVariation implements createImageVariation operation. // // Creates a variation of a given image. // // POST /images/variations - CreateImageVariation(ctx context.Context, req *CreateImageVariationRequestForm) (ImagesResponse, error) + CreateImageVariation(ctx context.Context, req *CreateImageVariationRequestMultipart) (ImagesResponse, error) // CreateModeration implements createModeration operation. // // Classifies if text violates OpenAI's Content Policy. @@ -124,13 +124,13 @@ type Handler interface { // Transcribes audio into the input language. // // POST /audio/transcriptions - CreateTranscription(ctx context.Context, req *CreateTranscriptionRequestForm) (*CreateTranscriptionResponse, error) + CreateTranscription(ctx context.Context, req *CreateTranscriptionRequestMultipart) (*CreateTranscriptionResponse, error) // CreateTranslation implements createTranslation operation. // // Translates audio into into English. // // POST /audio/translations - CreateTranslation(ctx context.Context, req *CreateTranslationRequestForm) (*CreateTranslationResponse, error) + CreateTranslation(ctx context.Context, req *CreateTranslationRequestMultipart) (*CreateTranslationResponse, error) // DeleteFile implements deleteFile operation. // // Delete a file. diff --git a/examples/ex_openai/oas_unimplemented_gen.go b/examples/ex_openai/oas_unimplemented_gen.go index d31238bce..74b8e6f8b 100644 --- a/examples/ex_openai/oas_unimplemented_gen.go +++ b/examples/ex_openai/oas_unimplemented_gen.go @@ -96,7 +96,7 @@ func (UnimplementedHandler) CreateEmbedding(ctx context.Context, req *CreateEmbe // need to increase the storage limit. // // POST /files -func (UnimplementedHandler) CreateFile(ctx context.Context, req *CreateFileRequestForm) (r OpenAIFile, _ error) { +func (UnimplementedHandler) CreateFile(ctx context.Context, req *CreateFileRequestMultipart) (r OpenAIFile, _ error) { return r, ht.ErrNotImplemented } @@ -126,7 +126,7 @@ func (UnimplementedHandler) CreateImage(ctx context.Context, req *CreateImageReq // Creates an edited or extended image given an original image and a prompt. // // POST /images/edits -func (UnimplementedHandler) CreateImageEdit(ctx context.Context, req *CreateImageEditRequestForm) (r ImagesResponse, _ error) { +func (UnimplementedHandler) CreateImageEdit(ctx context.Context, req *CreateImageEditRequestMultipart) (r ImagesResponse, _ error) { return r, ht.ErrNotImplemented } @@ -135,7 +135,7 @@ func (UnimplementedHandler) CreateImageEdit(ctx context.Context, req *CreateImag // Creates a variation of a given image. // // POST /images/variations -func (UnimplementedHandler) CreateImageVariation(ctx context.Context, req *CreateImageVariationRequestForm) (r ImagesResponse, _ error) { +func (UnimplementedHandler) CreateImageVariation(ctx context.Context, req *CreateImageVariationRequestMultipart) (r ImagesResponse, _ error) { return r, ht.ErrNotImplemented } @@ -171,7 +171,7 @@ func (UnimplementedHandler) CreateSearch(ctx context.Context, req *CreateSearchR // Transcribes audio into the input language. // // POST /audio/transcriptions -func (UnimplementedHandler) CreateTranscription(ctx context.Context, req *CreateTranscriptionRequestForm) (r *CreateTranscriptionResponse, _ error) { +func (UnimplementedHandler) CreateTranscription(ctx context.Context, req *CreateTranscriptionRequestMultipart) (r *CreateTranscriptionResponse, _ error) { return r, ht.ErrNotImplemented } @@ -180,7 +180,7 @@ func (UnimplementedHandler) CreateTranscription(ctx context.Context, req *Create // Translates audio into into English. // // POST /audio/translations -func (UnimplementedHandler) CreateTranslation(ctx context.Context, req *CreateTranslationRequestForm) (r *CreateTranslationResponse, _ error) { +func (UnimplementedHandler) CreateTranslation(ctx context.Context, req *CreateTranslationRequestMultipart) (r *CreateTranslationResponse, _ error) { return r, ht.ErrNotImplemented } diff --git a/examples/ex_openai/oas_validators_gen.go b/examples/ex_openai/oas_validators_gen.go index ea8f26788..d96c645b3 100644 --- a/examples/ex_openai/oas_validators_gen.go +++ b/examples/ex_openai/oas_validators_gen.go @@ -1574,7 +1574,7 @@ func (s *CreateFineTuneRequest) Validate() error { } return nil } -func (s *CreateImageEditRequest) Validate() error { +func (s *CreateImageEditRequestMultipart) Validate() error { var failures []validate.FieldError if err := func() error { if s.N.Set { @@ -1644,77 +1644,7 @@ func (s *CreateImageEditRequest) Validate() error { } return nil } -func (s *CreateImageEditRequestForm) Validate() error { - var failures []validate.FieldError - if err := func() error { - if s.N.Set { - if err := func() error { - if err := (validate.Int{ - MinSet: true, - Min: 1, - MaxSet: true, - Max: 10, - MinExclusive: false, - MaxExclusive: false, - MultipleOfSet: false, - MultipleOf: 0, - }).Validate(int64(s.N.Value)); err != nil { - return errors.Wrap(err, "int") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "n", - Error: err, - }) - } - if err := func() error { - if s.Size.Set { - if err := func() error { - if err := s.Size.Value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "size", - Error: err, - }) - } - if err := func() error { - if s.ResponseFormat.Set { - if err := func() error { - if err := s.ResponseFormat.Value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "response_format", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s CreateImageEditRequestResponseFormat) Validate() error { +func (s CreateImageEditRequestMultipartResponseFormat) Validate() error { switch s { case "url": return nil @@ -1724,7 +1654,7 @@ func (s CreateImageEditRequestResponseFormat) Validate() error { return errors.Errorf("invalid value: %v", s) } } -func (s CreateImageEditRequestSize) Validate() error { +func (s CreateImageEditRequestMultipartSize) Validate() error { switch s { case "256x256": return nil @@ -1828,77 +1758,7 @@ func (s CreateImageRequestSize) Validate() error { return errors.Errorf("invalid value: %v", s) } } -func (s *CreateImageVariationRequest) Validate() error { - var failures []validate.FieldError - if err := func() error { - if s.N.Set { - if err := func() error { - if err := (validate.Int{ - MinSet: true, - Min: 1, - MaxSet: true, - Max: 10, - MinExclusive: false, - MaxExclusive: false, - MultipleOfSet: false, - MultipleOf: 0, - }).Validate(int64(s.N.Value)); err != nil { - return errors.Wrap(err, "int") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "n", - Error: err, - }) - } - if err := func() error { - if s.Size.Set { - if err := func() error { - if err := s.Size.Value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "size", - Error: err, - }) - } - if err := func() error { - if s.ResponseFormat.Set { - if err := func() error { - if err := s.ResponseFormat.Value.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "response_format", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *CreateImageVariationRequestForm) Validate() error { +func (s *CreateImageVariationRequestMultipart) Validate() error { var failures []validate.FieldError if err := func() error { if s.N.Set { @@ -1968,7 +1828,7 @@ func (s *CreateImageVariationRequestForm) Validate() error { } return nil } -func (s CreateImageVariationRequestResponseFormat) Validate() error { +func (s CreateImageVariationRequestMultipartResponseFormat) Validate() error { switch s { case "url": return nil @@ -1978,7 +1838,7 @@ func (s CreateImageVariationRequestResponseFormat) Validate() error { return errors.Errorf("invalid value: %v", s) } } -func (s CreateImageVariationRequestSize) Validate() error { +func (s CreateImageVariationRequestMultipartSize) Validate() error { switch s { case "256x256": return nil @@ -2295,57 +2155,7 @@ func (s *CreateSearchResponseDataItem) Validate() error { } return nil } -func (s *CreateTranscriptionRequest) Validate() error { - var failures []validate.FieldError - if err := func() error { - if s.Temperature.Set { - if err := func() error { - if err := (validate.Float{}).Validate(float64(s.Temperature.Value)); err != nil { - return errors.Wrap(err, "float") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "temperature", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *CreateTranscriptionRequestForm) Validate() error { - var failures []validate.FieldError - if err := func() error { - if s.Temperature.Set { - if err := func() error { - if err := (validate.Float{}).Validate(float64(s.Temperature.Value)); err != nil { - return errors.Wrap(err, "float") - } - return nil - }(); err != nil { - return err - } - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "temperature", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *CreateTranslationRequest) Validate() error { +func (s *CreateTranscriptionRequestMultipart) Validate() error { var failures []validate.FieldError if err := func() error { if s.Temperature.Set { @@ -2370,7 +2180,7 @@ func (s *CreateTranslationRequest) Validate() error { } return nil } -func (s *CreateTranslationRequestForm) Validate() error { +func (s *CreateTranslationRequestMultipart) Validate() error { var failures []validate.FieldError if err := func() error { if s.Temperature.Set { diff --git a/internal/integration/test_allof/oas_client_gen.go b/internal/integration/test_allof/oas_client_gen.go index 8346f2f20..224065e20 100644 --- a/internal/integration/test_allof/oas_client_gen.go +++ b/internal/integration/test_allof/oas_client_gen.go @@ -338,7 +338,7 @@ func (c *Client) sendReferencedAllof(ctx context.Context, request ReferencedAllo } // Validate request before sending. switch request := request.(type) { - case *ReferencedAllofApplicationJSON: + case *Robot: if err := func() error { if err := request.Validate(); err != nil { return err @@ -347,7 +347,7 @@ func (c *Client) sendReferencedAllof(ctx context.Context, request ReferencedAllo }(); err != nil { return res, errors.Wrap(err, "validate") } - case *ReferencedAllofMultipartFormData: + case *RobotMultipart: if err := func() error { if err := request.Validate(); err != nil { return err @@ -436,7 +436,7 @@ func (c *Client) sendReferencedAllofOptional(ctx context.Context, request Refere switch request := request.(type) { case *ReferencedAllofOptionalReqEmptyBody: // Validation is not needed for the empty body type. - case *ReferencedAllofOptionalApplicationJSON: + case *Robot: if err := func() error { if err := request.Validate(); err != nil { return err @@ -445,7 +445,7 @@ func (c *Client) sendReferencedAllofOptional(ctx context.Context, request Refere }(); err != nil { return res, errors.Wrap(err, "validate") } - case *ReferencedAllofOptionalMultipartFormData: + case *RobotMultipart: if err := func() error { if err := request.Validate(); err != nil { return err diff --git a/internal/integration/test_allof/oas_faker_gen.go b/internal/integration/test_allof/oas_faker_gen.go index 320fa6f26..30c0ba025 100644 --- a/internal/integration/test_allof/oas_faker_gen.go +++ b/internal/integration/test_allof/oas_faker_gen.go @@ -87,42 +87,6 @@ func (s *OptString) SetFake() { s.SetTo(elem) } -// SetFake set fake values. -func (s *ReferencedAllofApplicationJSON) SetFake() { - var unwrapped Robot - { - unwrapped.SetFake() - } - *s = ReferencedAllofApplicationJSON(unwrapped) -} - -// SetFake set fake values. -func (s *ReferencedAllofMultipartFormData) SetFake() { - var unwrapped Robot - { - unwrapped.SetFake() - } - *s = ReferencedAllofMultipartFormData(unwrapped) -} - -// SetFake set fake values. -func (s *ReferencedAllofOptionalApplicationJSON) SetFake() { - var unwrapped Robot - { - unwrapped.SetFake() - } - *s = ReferencedAllofOptionalApplicationJSON(unwrapped) -} - -// SetFake set fake values. -func (s *ReferencedAllofOptionalMultipartFormData) SetFake() { - var unwrapped Robot - { - unwrapped.SetFake() - } - *s = ReferencedAllofOptionalMultipartFormData(unwrapped) -} - // SetFake set fake values. func (s *Robot) SetFake() { { diff --git a/internal/integration/test_allof/oas_json_gen.go b/internal/integration/test_allof/oas_json_gen.go index 62e0e5b0c..4fc822652 100644 --- a/internal/integration/test_allof/oas_json_gen.go +++ b/internal/integration/test_allof/oas_json_gen.go @@ -515,158 +515,6 @@ func (s *OptString) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes ReferencedAllofApplicationJSON as json. -func (s *ReferencedAllofApplicationJSON) Encode(e *jx.Encoder) { - unwrapped := (*Robot)(s) - - unwrapped.Encode(e) -} - -// Decode decodes ReferencedAllofApplicationJSON from json. -func (s *ReferencedAllofApplicationJSON) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode ReferencedAllofApplicationJSON to nil") - } - var unwrapped Robot - if err := func() error { - if err := unwrapped.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = ReferencedAllofApplicationJSON(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *ReferencedAllofApplicationJSON) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *ReferencedAllofApplicationJSON) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ReferencedAllofMultipartFormData as json. -func (s *ReferencedAllofMultipartFormData) Encode(e *jx.Encoder) { - unwrapped := (*Robot)(s) - - unwrapped.Encode(e) -} - -// Decode decodes ReferencedAllofMultipartFormData from json. -func (s *ReferencedAllofMultipartFormData) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode ReferencedAllofMultipartFormData to nil") - } - var unwrapped Robot - if err := func() error { - if err := unwrapped.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = ReferencedAllofMultipartFormData(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *ReferencedAllofMultipartFormData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *ReferencedAllofMultipartFormData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ReferencedAllofOptionalApplicationJSON as json. -func (s *ReferencedAllofOptionalApplicationJSON) Encode(e *jx.Encoder) { - unwrapped := (*Robot)(s) - - unwrapped.Encode(e) -} - -// Decode decodes ReferencedAllofOptionalApplicationJSON from json. -func (s *ReferencedAllofOptionalApplicationJSON) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode ReferencedAllofOptionalApplicationJSON to nil") - } - var unwrapped Robot - if err := func() error { - if err := unwrapped.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = ReferencedAllofOptionalApplicationJSON(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *ReferencedAllofOptionalApplicationJSON) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *ReferencedAllofOptionalApplicationJSON) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ReferencedAllofOptionalMultipartFormData as json. -func (s *ReferencedAllofOptionalMultipartFormData) Encode(e *jx.Encoder) { - unwrapped := (*Robot)(s) - - unwrapped.Encode(e) -} - -// Decode decodes ReferencedAllofOptionalMultipartFormData from json. -func (s *ReferencedAllofOptionalMultipartFormData) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode ReferencedAllofOptionalMultipartFormData to nil") - } - var unwrapped Robot - if err := func() error { - if err := unwrapped.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = ReferencedAllofOptionalMultipartFormData(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *ReferencedAllofOptionalMultipartFormData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *ReferencedAllofOptionalMultipartFormData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode implements json.Marshaler. func (s *Robot) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/internal/integration/test_allof/oas_request_decoders_gen.go b/internal/integration/test_allof/oas_request_decoders_gen.go index 020d20610..34eab3e0f 100644 --- a/internal/integration/test_allof/oas_request_decoders_gen.go +++ b/internal/integration/test_allof/oas_request_decoders_gen.go @@ -279,7 +279,7 @@ func (s *Server) decodeReferencedAllofRequest(r *http.Request) ( d := jx.DecodeBytes(buf) - var request ReferencedAllofApplicationJSON + var request Robot if err := func() error { if err := request.Decode(d); err != nil { return err @@ -321,98 +321,94 @@ func (s *Server) decodeReferencedAllofRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request ReferencedAllofMultipartFormData + var request RobotMultipart + q := uri.NewQueryDecoder(form) { - var unwrapped Robot - q := uri.NewQueryDecoder(form) - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "state", - Style: uri.QueryStyleForm, - Explode: true, - } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToString(val) - if err != nil { - return err - } - - unwrapped.State = RobotState(c) - return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"state\"") + cfg := uri.QueryParameterDecodingConfig{ + Name: "state", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err } - if err := func() error { - if err := unwrapped.State.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return req, close, errors.Wrap(err, "validate") + + c, err := conv.ToString(val) + if err != nil { + return err } - } else { - return req, close, errors.Wrap(err, "query") + + request.State = RobotMultipartState(c) + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"state\"") } - } - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "id", - Style: uri.QueryStyleForm, - Explode: true, + if err := func() error { + if err := request.State.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "validate") } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToUUID(val) - if err != nil { - return err - } - - unwrapped.ID = c - return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"id\"") + } else { + return req, close, errors.Wrap(err, "query") + } + } + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "id", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err } - } else { - return req, close, errors.Wrap(err, "query") + + request.ID = c + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"id\"") } + } else { + return req, close, errors.Wrap(err, "query") } - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "location", - Style: uri.QueryStyleForm, - Explode: true, - Fields: []uri.QueryParameterObjectField{{"lat", true}, {"lon", true}}, + } + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "location", + Style: uri.QueryStyleForm, + Explode: true, + Fields: []uri.QueryParameterObjectField{{"lat", true}, {"lon", true}}, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + return request.Location.DecodeURI(d) + }); err != nil { + return req, close, errors.Wrap(err, "decode \"location\"") } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - return unwrapped.Location.DecodeURI(d) - }); err != nil { - return req, close, errors.Wrap(err, "decode \"location\"") - } - if err := func() error { - if err := unwrapped.Location.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return req, close, errors.Wrap(err, "validate") + if err := func() error { + if err := request.Location.Validate(); err != nil { + return err } - } else { - return req, close, errors.Wrap(err, "query") + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "validate") } + } else { + return req, close, errors.Wrap(err, "query") } - request = ReferencedAllofMultipartFormData(unwrapped) } return &request, close, nil default: @@ -464,7 +460,7 @@ func (s *Server) decodeReferencedAllofOptionalRequest(r *http.Request) ( d := jx.DecodeBytes(buf) - var request ReferencedAllofOptionalApplicationJSON + var request Robot if err := func() error { if err := request.Decode(d); err != nil { return err @@ -506,98 +502,94 @@ func (s *Server) decodeReferencedAllofOptionalRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request ReferencedAllofOptionalMultipartFormData + var request RobotMultipart + q := uri.NewQueryDecoder(form) { - var unwrapped Robot - q := uri.NewQueryDecoder(form) - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "state", - Style: uri.QueryStyleForm, - Explode: true, - } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToString(val) - if err != nil { - return err - } - - unwrapped.State = RobotState(c) - return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"state\"") + cfg := uri.QueryParameterDecodingConfig{ + Name: "state", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err } - if err := func() error { - if err := unwrapped.State.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return req, close, errors.Wrap(err, "validate") + + c, err := conv.ToString(val) + if err != nil { + return err } - } else { - return req, close, errors.Wrap(err, "query") + + request.State = RobotMultipartState(c) + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"state\"") } - } - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "id", - Style: uri.QueryStyleForm, - Explode: true, + if err := func() error { + if err := request.State.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "validate") } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToUUID(val) - if err != nil { - return err - } - - unwrapped.ID = c - return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"id\"") + } else { + return req, close, errors.Wrap(err, "query") + } + } + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "id", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToUUID(val) + if err != nil { + return err } - } else { - return req, close, errors.Wrap(err, "query") + + request.ID = c + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"id\"") } + } else { + return req, close, errors.Wrap(err, "query") } - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "location", - Style: uri.QueryStyleForm, - Explode: true, - Fields: []uri.QueryParameterObjectField{{"lat", true}, {"lon", true}}, + } + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "location", + Style: uri.QueryStyleForm, + Explode: true, + Fields: []uri.QueryParameterObjectField{{"lat", true}, {"lon", true}}, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + return request.Location.DecodeURI(d) + }); err != nil { + return req, close, errors.Wrap(err, "decode \"location\"") } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - return unwrapped.Location.DecodeURI(d) - }); err != nil { - return req, close, errors.Wrap(err, "decode \"location\"") - } - if err := func() error { - if err := unwrapped.Location.Validate(); err != nil { - return err - } - return nil - }(); err != nil { - return req, close, errors.Wrap(err, "validate") + if err := func() error { + if err := request.Location.Validate(); err != nil { + return err } - } else { - return req, close, errors.Wrap(err, "query") + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "validate") } + } else { + return req, close, errors.Wrap(err, "query") } - request = ReferencedAllofOptionalMultipartFormData(unwrapped) } return &request, close, nil default: diff --git a/internal/integration/test_allof/oas_request_encoders_gen.go b/internal/integration/test_allof/oas_request_encoders_gen.go index 64aec8d30..4df611088 100644 --- a/internal/integration/test_allof/oas_request_encoders_gen.go +++ b/internal/integration/test_allof/oas_request_encoders_gen.go @@ -63,7 +63,7 @@ func encodeReferencedAllofRequest( r *http.Request, ) error { switch req := req.(type) { - case *ReferencedAllofApplicationJSON: + case *Robot: const contentType = "application/json" e := jx.GetEncoder() { @@ -72,7 +72,7 @@ func encodeReferencedAllofRequest( encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) return nil - case *ReferencedAllofMultipartFormData: + case *RobotMultipart: const contentType = "multipart/form-data" request := req @@ -137,7 +137,7 @@ func encodeReferencedAllofOptionalRequest( case *ReferencedAllofOptionalReqEmptyBody: // Empty body case. return nil - case *ReferencedAllofOptionalApplicationJSON: + case *Robot: const contentType = "application/json" e := jx.GetEncoder() { @@ -146,7 +146,7 @@ func encodeReferencedAllofOptionalRequest( encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) return nil - case *ReferencedAllofOptionalMultipartFormData: + case *RobotMultipart: const contentType = "multipart/form-data" request := req diff --git a/internal/integration/test_allof/oas_schemas_gen.go b/internal/integration/test_allof/oas_schemas_gen.go index 52ea6efc3..48fbdd040 100644 --- a/internal/integration/test_allof/oas_schemas_gen.go +++ b/internal/integration/test_allof/oas_schemas_gen.go @@ -279,25 +279,9 @@ func (o OptString) Or(d string) string { return d } -type ReferencedAllofApplicationJSON Robot - -func (*ReferencedAllofApplicationJSON) referencedAllofReq() {} - -type ReferencedAllofMultipartFormData Robot - -func (*ReferencedAllofMultipartFormData) referencedAllofReq() {} - // ReferencedAllofOK is response for ReferencedAllof operation. type ReferencedAllofOK struct{} -type ReferencedAllofOptionalApplicationJSON Robot - -func (*ReferencedAllofOptionalApplicationJSON) referencedAllofOptionalReq() {} - -type ReferencedAllofOptionalMultipartFormData Robot - -func (*ReferencedAllofOptionalMultipartFormData) referencedAllofOptionalReq() {} - // ReferencedAllofOptionalOK is response for ReferencedAllofOptional operation. type ReferencedAllofOptionalOK struct{} @@ -343,6 +327,83 @@ func (s *Robot) SetLocation(val Location) { s.Location = val } +func (*Robot) referencedAllofOptionalReq() {} +func (*Robot) referencedAllofReq() {} + +// Merged schema. +// Ref: #/components/schemas/Robot +type RobotMultipart struct { + State RobotMultipartState `json:"state"` + ID uuid.UUID `json:"id"` + Location Location `json:"location"` +} + +// GetState returns the value of State. +func (s *RobotMultipart) GetState() RobotMultipartState { + return s.State +} + +// GetID returns the value of ID. +func (s *RobotMultipart) GetID() uuid.UUID { + return s.ID +} + +// GetLocation returns the value of Location. +func (s *RobotMultipart) GetLocation() Location { + return s.Location +} + +// SetState sets the value of State. +func (s *RobotMultipart) SetState(val RobotMultipartState) { + s.State = val +} + +// SetID sets the value of ID. +func (s *RobotMultipart) SetID(val uuid.UUID) { + s.ID = val +} + +// SetLocation sets the value of Location. +func (s *RobotMultipart) SetLocation(val Location) { + s.Location = val +} + +func (*RobotMultipart) referencedAllofOptionalReq() {} +func (*RobotMultipart) referencedAllofReq() {} + +type RobotMultipartState string + +const ( + RobotMultipartStateOn RobotMultipartState = "on" + RobotMultipartStateOff RobotMultipartState = "off" +) + +// MarshalText implements encoding.TextMarshaler. +func (s RobotMultipartState) MarshalText() ([]byte, error) { + switch s { + case RobotMultipartStateOn: + return []byte(s), nil + case RobotMultipartStateOff: + return []byte(s), nil + default: + return nil, errors.Errorf("invalid value: %q", s) + } +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (s *RobotMultipartState) UnmarshalText(data []byte) error { + switch RobotMultipartState(data) { + case RobotMultipartStateOn: + *s = RobotMultipartStateOn + return nil + case RobotMultipartStateOff: + *s = RobotMultipartStateOff + return nil + default: + return errors.Errorf("invalid value: %q", data) + } +} + type RobotState string const ( diff --git a/internal/integration/test_allof/oas_test_examples_gen_test.go b/internal/integration/test_allof/oas_test_examples_gen_test.go index bd6553409..bf82f479e 100644 --- a/internal/integration/test_allof/oas_test_examples_gen_test.go +++ b/internal/integration/test_allof/oas_test_examples_gen_test.go @@ -47,54 +47,6 @@ func TestObjectsWithConflictingPropertiesReq_EncodeDecode(t *testing.T) { var typ2 ObjectsWithConflictingPropertiesReq require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) } -func TestReferencedAllofApplicationJSON_EncodeDecode(t *testing.T) { - var typ ReferencedAllofApplicationJSON - typ.SetFake() - - e := jx.Encoder{} - typ.Encode(&e) - data := e.Bytes() - require.True(t, std.Valid(data), "Encoded: %s", data) - - var typ2 ReferencedAllofApplicationJSON - require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) -} -func TestReferencedAllofMultipartFormData_EncodeDecode(t *testing.T) { - var typ ReferencedAllofMultipartFormData - typ.SetFake() - - e := jx.Encoder{} - typ.Encode(&e) - data := e.Bytes() - require.True(t, std.Valid(data), "Encoded: %s", data) - - var typ2 ReferencedAllofMultipartFormData - require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) -} -func TestReferencedAllofOptionalApplicationJSON_EncodeDecode(t *testing.T) { - var typ ReferencedAllofOptionalApplicationJSON - typ.SetFake() - - e := jx.Encoder{} - typ.Encode(&e) - data := e.Bytes() - require.True(t, std.Valid(data), "Encoded: %s", data) - - var typ2 ReferencedAllofOptionalApplicationJSON - require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) -} -func TestReferencedAllofOptionalMultipartFormData_EncodeDecode(t *testing.T) { - var typ ReferencedAllofOptionalMultipartFormData - typ.SetFake() - - e := jx.Encoder{} - typ.Encode(&e) - data := e.Bytes() - require.True(t, std.Valid(data), "Encoded: %s", data) - - var typ2 ReferencedAllofOptionalMultipartFormData - require.NoError(t, typ2.Decode(jx.DecodeBytes(data))) -} func TestRobot_EncodeDecode(t *testing.T) { var typ Robot typ.SetFake() diff --git a/internal/integration/test_allof/oas_validators_gen.go b/internal/integration/test_allof/oas_validators_gen.go index 51500c469..4c0835ac3 100644 --- a/internal/integration/test_allof/oas_validators_gen.go +++ b/internal/integration/test_allof/oas_validators_gen.go @@ -138,31 +138,36 @@ func (s *ObjectsWithConflictingPropertiesReq) Validate() error { return nil } -func (s *ReferencedAllofApplicationJSON) Validate() error { - if err := s.Validate(); err != nil { - return err - } - return nil -} -func (s *ReferencedAllofMultipartFormData) Validate() error { - if err := s.Validate(); err != nil { - return err +func (s *Robot) Validate() error { + var failures []validate.FieldError + if err := func() error { + if err := s.State.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "state", + Error: err, + }) } - return nil -} -func (s *ReferencedAllofOptionalApplicationJSON) Validate() error { - if err := s.Validate(); err != nil { - return err + if err := func() error { + if err := s.Location.Validate(); err != nil { + return err + } + return nil + }(); err != nil { + failures = append(failures, validate.FieldError{ + Name: "location", + Error: err, + }) } - return nil -} -func (s *ReferencedAllofOptionalMultipartFormData) Validate() error { - if err := s.Validate(); err != nil { - return err + if len(failures) > 0 { + return &validate.Error{Fields: failures} } return nil } -func (s *Robot) Validate() error { +func (s *RobotMultipart) Validate() error { var failures []validate.FieldError if err := func() error { if err := s.State.Validate(); err != nil { @@ -191,6 +196,16 @@ func (s *Robot) Validate() error { } return nil } +func (s RobotMultipartState) Validate() error { + switch s { + case "on": + return nil + case "off": + return nil + default: + return errors.Errorf("invalid value: %v", s) + } +} func (s RobotState) Validate() error { switch s { case "on": diff --git a/internal/integration/test_form/oas_client_gen.go b/internal/integration/test_form/oas_client_gen.go index b272e663a..629e32397 100644 --- a/internal/integration/test_form/oas_client_gen.go +++ b/internal/integration/test_form/oas_client_gen.go @@ -140,13 +140,13 @@ func (c *Client) sendOnlyForm(ctx context.Context, request *OnlyFormReq) (res *O // OnlyMultipartFile invokes onlyMultipartFile operation. // // POST /onlyMultipartFile -func (c *Client) OnlyMultipartFile(ctx context.Context, request *OnlyMultipartFileReqForm) error { +func (c *Client) OnlyMultipartFile(ctx context.Context, request *OnlyMultipartFileReq) error { res, err := c.sendOnlyMultipartFile(ctx, request) _ = res return err } -func (c *Client) sendOnlyMultipartFile(ctx context.Context, request *OnlyMultipartFileReqForm) (res *OnlyMultipartFileOK, err error) { +func (c *Client) sendOnlyMultipartFile(ctx context.Context, request *OnlyMultipartFileReq) (res *OnlyMultipartFileOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("onlyMultipartFile"), } @@ -353,13 +353,13 @@ func (c *Client) sendTestFormURLEncoded(ctx context.Context, request *TestForm) // TestMultipart invokes testMultipart operation. // // POST /testMultipart -func (c *Client) TestMultipart(ctx context.Context, request *TestForm) error { +func (c *Client) TestMultipart(ctx context.Context, request *TestFormMultipart) error { res, err := c.sendTestMultipart(ctx, request) _ = res return err } -func (c *Client) sendTestMultipart(ctx context.Context, request *TestForm) (res *TestMultipartOK, err error) { +func (c *Client) sendTestMultipart(ctx context.Context, request *TestFormMultipart) (res *TestMultipartOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("testMultipart"), } @@ -424,13 +424,13 @@ func (c *Client) sendTestMultipart(ctx context.Context, request *TestForm) (res // TestMultipartUpload invokes testMultipartUpload operation. // // POST /testMultipartUpload -func (c *Client) TestMultipartUpload(ctx context.Context, request *TestMultipartUploadReqForm) (*TestMultipartUploadOK, error) { +func (c *Client) TestMultipartUpload(ctx context.Context, request *TestMultipartUploadReq) (*TestMultipartUploadOK, error) { res, err := c.sendTestMultipartUpload(ctx, request) _ = res return res, err } -func (c *Client) sendTestMultipartUpload(ctx context.Context, request *TestMultipartUploadReqForm) (res *TestMultipartUploadOK, err error) { +func (c *Client) sendTestMultipartUpload(ctx context.Context, request *TestMultipartUploadReq) (res *TestMultipartUploadOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("testMultipartUpload"), } @@ -501,6 +501,148 @@ func (c *Client) sendTestMultipartUpload(ctx context.Context, request *TestMulti return result, nil } +// TestReuseFormOptionalSchema invokes testReuseFormOptionalSchema operation. +// +// POST /testReuseFormOptionalSchema +func (c *Client) TestReuseFormOptionalSchema(ctx context.Context, request OptSharedRequestMultipart) error { + res, err := c.sendTestReuseFormOptionalSchema(ctx, request) + _ = res + return err +} + +func (c *Client) sendTestReuseFormOptionalSchema(ctx context.Context, request OptSharedRequestMultipart) (res *TestReuseFormOptionalSchemaOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testReuseFormOptionalSchema"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "TestReuseFormOptionalSchema", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [1]string + pathParts[0] = "/testReuseFormOptionalSchema" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "POST", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + if err := encodeTestReuseFormOptionalSchemaRequest(request, r); err != nil { + return res, errors.Wrap(err, "encode request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeTestReuseFormOptionalSchemaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + +// TestReuseFormSchema invokes testReuseFormSchema operation. +// +// POST /testReuseFormSchema +func (c *Client) TestReuseFormSchema(ctx context.Context, request *SharedRequestMultipart) error { + res, err := c.sendTestReuseFormSchema(ctx, request) + _ = res + return err +} + +func (c *Client) sendTestReuseFormSchema(ctx context.Context, request *SharedRequestMultipart) (res *TestReuseFormSchemaOK, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testReuseFormSchema"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, otelAttrs...) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, "TestReuseFormSchema", + trace.WithAttributes(otelAttrs...), + clientSpanKind, + ) + // Track stage for error reporting. + var stage string + defer func() { + if err != nil { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + c.errors.Add(ctx, 1, otelAttrs...) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [1]string + pathParts[0] = "/testReuseFormSchema" + uri.AddPathParts(u, pathParts[:]...) + + stage = "EncodeRequest" + r, err := ht.NewRequest(ctx, "POST", u) + if err != nil { + return res, errors.Wrap(err, "create request") + } + if err := encodeTestReuseFormSchemaRequest(request, r); err != nil { + return res, errors.Wrap(err, "encode request") + } + + stage = "SendRequest" + resp, err := c.cfg.Client.Do(r) + if err != nil { + return res, errors.Wrap(err, "do request") + } + defer resp.Body.Close() + + stage = "DecodeResponse" + result, err := decodeTestReuseFormSchemaResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // TestShareFormSchema invokes testShareFormSchema operation. // // POST /testShareFormSchema @@ -518,7 +660,7 @@ func (c *Client) sendTestShareFormSchema(ctx context.Context, request TestShareF switch request := request.(type) { case *SharedRequest: // Validation is not required for this type. - case *SharedRequestForm: + case *SharedRequestMultipart: // Validation is not required for this type. default: return res, errors.Errorf("unexpected request type: %T", request) diff --git a/internal/integration/test_form/oas_handlers_gen.go b/internal/integration/test_form/oas_handlers_gen.go index bdc8300a3..f4e49f532 100644 --- a/internal/integration/test_form/oas_handlers_gen.go +++ b/internal/integration/test_form/oas_handlers_gen.go @@ -184,7 +184,7 @@ func (s *Server) handleOnlyMultipartFileRequest(args [0]string, argsEscaped bool } type ( - Request = *OnlyMultipartFileReqForm + Request = *OnlyMultipartFileReq Params = struct{} Response = *OnlyMultipartFileOK ) @@ -484,7 +484,7 @@ func (s *Server) handleTestMultipartRequest(args [0]string, argsEscaped bool, w } type ( - Request = *TestForm + Request = *TestFormMultipart Params = struct{} Response = *TestMultipartOK ) @@ -584,7 +584,7 @@ func (s *Server) handleTestMultipartUploadRequest(args [0]string, argsEscaped bo } type ( - Request = *TestMultipartUploadReqForm + Request = *TestMultipartUploadReq Params = struct{} Response = *TestMultipartUploadOK ) @@ -617,6 +617,206 @@ func (s *Server) handleTestMultipartUploadRequest(args [0]string, argsEscaped bo } } +// handleTestReuseFormOptionalSchemaRequest handles testReuseFormOptionalSchema operation. +// +// POST /testReuseFormOptionalSchema +func (s *Server) handleTestReuseFormOptionalSchemaRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testReuseFormOptionalSchema"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/testReuseFormOptionalSchema"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "TestReuseFormOptionalSchema", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "TestReuseFormOptionalSchema", + ID: "testReuseFormOptionalSchema", + } + ) + request, close, err := s.decodeTestReuseFormOptionalSchemaRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response *TestReuseFormOptionalSchemaOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "TestReuseFormOptionalSchema", + OperationID: "testReuseFormOptionalSchema", + Body: request, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = OptSharedRequestMultipart + Params = struct{} + Response = *TestReuseFormOptionalSchemaOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.TestReuseFormOptionalSchema(ctx, request) + return response, err + }, + ) + } else { + err = s.h.TestReuseFormOptionalSchema(ctx, request) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeTestReuseFormOptionalSchemaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + +// handleTestReuseFormSchemaRequest handles testReuseFormSchema operation. +// +// POST /testReuseFormSchema +func (s *Server) handleTestReuseFormSchemaRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("testReuseFormSchema"), + semconv.HTTPMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/testReuseFormSchema"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), "TestReuseFormSchema", + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + s.duration.Record(ctx, elapsedDuration.Microseconds(), otelAttrs...) + }() + + // Increment request counter. + s.requests.Add(ctx, 1, otelAttrs...) + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + span.SetStatus(codes.Error, stage) + s.errors.Add(ctx, 1, otelAttrs...) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: "TestReuseFormSchema", + ID: "testReuseFormSchema", + } + ) + request, close, err := s.decodeTestReuseFormSchemaRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response *TestReuseFormSchemaOK + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: "TestReuseFormSchema", + OperationID: "testReuseFormSchema", + Body: request, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = *SharedRequestMultipart + Params = struct{} + Response = *TestReuseFormSchemaOK + ) + response, err = middleware.HookMiddleware[ + Request, + Params, + Response, + ]( + m, + mreq, + nil, + func(ctx context.Context, request Request, params Params) (response Response, err error) { + err = s.h.TestReuseFormSchema(ctx, request) + return response, err + }, + ) + } else { + err = s.h.TestReuseFormSchema(ctx, request) + } + if err != nil { + recordError("Internal", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + + if err := encodeTestReuseFormSchemaResponse(response, w, span); err != nil { + recordError("EncodeResponse", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } +} + // handleTestShareFormSchemaRequest handles testShareFormSchema operation. // // POST /testShareFormSchema diff --git a/internal/integration/test_form/oas_request_decoders_gen.go b/internal/integration/test_form/oas_request_decoders_gen.go index c9e03093f..d9fd5ebc4 100644 --- a/internal/integration/test_form/oas_request_decoders_gen.go +++ b/internal/integration/test_form/oas_request_decoders_gen.go @@ -105,7 +105,7 @@ func (s *Server) decodeOnlyFormRequest(r *http.Request) ( } func (s *Server) decodeOnlyMultipartFileRequest(r *http.Request) ( - req *OnlyMultipartFileReqForm, + req *OnlyMultipartFileReq, close func() error, rerr error, ) { @@ -145,7 +145,7 @@ func (s *Server) decodeOnlyMultipartFileRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request OnlyMultipartFileReqForm + var request OnlyMultipartFileReq defined := func(name string) bool { switch name { case "file": @@ -498,7 +498,7 @@ func (s *Server) decodeTestFormURLEncodedRequest(r *http.Request) ( } func (s *Server) decodeTestMultipartRequest(r *http.Request) ( - req *TestForm, + req *TestFormMultipart, close func() error, rerr error, ) { @@ -538,7 +538,7 @@ func (s *Server) decodeTestMultipartRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request TestForm + var request TestFormMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ @@ -674,7 +674,7 @@ func (s *Server) decodeTestMultipartRequest(r *http.Request) ( } if err := q.HasParam(cfg); err == nil { if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var requestDotObjectVal TestFormObject + var requestDotObjectVal TestFormMultipartObject if err := func() error { return requestDotObjectVal.DecodeURI(d) }(); err != nil { @@ -696,7 +696,7 @@ func (s *Server) decodeTestMultipartRequest(r *http.Request) ( } if err := q.HasParam(cfg); err == nil { if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var requestDotDeepObjectVal TestFormDeepObject + var requestDotDeepObjectVal TestFormMultipartDeepObject if err := func() error { return requestDotDeepObjectVal.DecodeURI(d) }(); err != nil { @@ -716,7 +716,7 @@ func (s *Server) decodeTestMultipartRequest(r *http.Request) ( } func (s *Server) decodeTestMultipartUploadRequest(r *http.Request) ( - req *TestMultipartUploadReqForm, + req *TestMultipartUploadReq, close func() error, rerr error, ) { @@ -756,7 +756,7 @@ func (s *Server) decodeTestMultipartUploadRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request TestMultipartUploadReqForm + var request TestMultipartUploadReq defined := func(name string) bool { switch name { case "orderId": @@ -942,6 +942,224 @@ func (s *Server) decodeTestMultipartUploadRequest(r *http.Request) ( } } +func (s *Server) decodeTestReuseFormOptionalSchemaRequest(r *http.Request) ( + req OptSharedRequestMultipart, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = multierr.Append(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = multierr.Append(rerr, close()) + } + }() + if _, ok := r.Header["Content-Type"]; !ok && r.ContentLength == 0 { + return req, close, nil + } + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "multipart/form-data": + if r.ContentLength == 0 { + return req, close, nil + } + if err := r.ParseMultipartForm(s.cfg.MaxMultipartMemory); err != nil { + return req, close, errors.Wrap(err, "parse multipart form") + } + // Remove all temporary files created by ParseMultipartForm when the request is done. + // + // Notice that the closers are called in reverse order, to match defer behavior, so + // any opened file will be closed before RemoveAll call. + closers = append(closers, r.MultipartForm.RemoveAll) + // Form values may be unused. + form := url.Values(r.MultipartForm.Value) + _ = form + + var request OptSharedRequestMultipart + { + var optForm SharedRequestMultipart + q := uri.NewQueryDecoder(form) + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "filename", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var optFormDotFilenameVal string + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + optFormDotFilenameVal = c + return nil + }(); err != nil { + return err + } + optForm.Filename.SetTo(optFormDotFilenameVal) + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"filename\"") + } + } + } + { + if err := func() error { + files, ok := r.MultipartForm.File["file"] + if !ok || len(files) < 1 { + return nil + } + fh := files[0] + + f, err := fh.Open() + if err != nil { + return errors.Wrap(err, "open") + } + closers = append(closers, f.Close) + optForm.File.SetTo(ht.MultipartFile{ + Name: fh.Filename, + File: f, + Header: fh.Header, + }) + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "decode \"file\"") + } + } + request = OptSharedRequestMultipart{ + Value: optForm, + Set: true, + } + } + return request, close, nil + default: + return req, close, validate.InvalidContentType(ct) + } +} + +func (s *Server) decodeTestReuseFormSchemaRequest(r *http.Request) ( + req *SharedRequestMultipart, + close func() error, + rerr error, +) { + var closers []func() error + close = func() error { + var merr error + // Close in reverse order, to match defer behavior. + for i := len(closers) - 1; i >= 0; i-- { + c := closers[i] + merr = multierr.Append(merr, c()) + } + return merr + } + defer func() { + if rerr != nil { + rerr = multierr.Append(rerr, close()) + } + }() + ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type")) + if err != nil { + return req, close, errors.Wrap(err, "parse media type") + } + switch { + case ct == "multipart/form-data": + if r.ContentLength == 0 { + return req, close, validate.ErrBodyRequired + } + if err := r.ParseMultipartForm(s.cfg.MaxMultipartMemory); err != nil { + return req, close, errors.Wrap(err, "parse multipart form") + } + // Remove all temporary files created by ParseMultipartForm when the request is done. + // + // Notice that the closers are called in reverse order, to match defer behavior, so + // any opened file will be closed before RemoveAll call. + closers = append(closers, r.MultipartForm.RemoveAll) + // Form values may be unused. + form := url.Values(r.MultipartForm.Value) + _ = form + + var request SharedRequestMultipart + q := uri.NewQueryDecoder(form) + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "filename", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var requestDotFilenameVal string + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + requestDotFilenameVal = c + return nil + }(); err != nil { + return err + } + request.Filename.SetTo(requestDotFilenameVal) + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"filename\"") + } + } + } + { + if err := func() error { + files, ok := r.MultipartForm.File["file"] + if !ok || len(files) < 1 { + return nil + } + fh := files[0] + + f, err := fh.Open() + if err != nil { + return errors.Wrap(err, "open") + } + closers = append(closers, f.Close) + request.File.SetTo(ht.MultipartFile{ + Name: fh.Filename, + File: f, + Header: fh.Header, + }) + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "decode \"file\"") + } + } + return &request, close, nil + default: + return req, close, validate.InvalidContentType(ct) + } +} + func (s *Server) decodeTestShareFormSchemaRequest(r *http.Request) ( req TestShareFormSchemaReq, close func() error, @@ -1016,7 +1234,7 @@ func (s *Server) decodeTestShareFormSchemaRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request SharedRequestForm + var request SharedRequestMultipart q := uri.NewQueryDecoder(form) { cfg := uri.QueryParameterDecodingConfig{ diff --git a/internal/integration/test_form/oas_request_encoders_gen.go b/internal/integration/test_form/oas_request_encoders_gen.go index 458fa5856..1406e7f7e 100644 --- a/internal/integration/test_form/oas_request_encoders_gen.go +++ b/internal/integration/test_form/oas_request_encoders_gen.go @@ -44,7 +44,7 @@ func encodeOnlyFormRequest( } func encodeOnlyMultipartFileRequest( - req *OnlyMultipartFileReqForm, + req *OnlyMultipartFileReq, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -208,7 +208,7 @@ func encodeTestFormURLEncodedRequest( } func encodeTestMultipartRequest( - req *TestForm, + req *TestFormMultipart, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -325,7 +325,7 @@ func encodeTestMultipartRequest( } func encodeTestMultipartUploadRequest( - req *TestMultipartUploadReqForm, + req *TestMultipartUploadReq, r *http.Request, ) error { const contentType = "multipart/form-data" @@ -392,6 +392,88 @@ func encodeTestMultipartUploadRequest( return nil } +func encodeTestReuseFormOptionalSchemaRequest( + req OptSharedRequestMultipart, + r *http.Request, +) error { + const contentType = "multipart/form-data" + if !req.Set { + // Keep request with empty body if value is not set. + return nil + } + request := req.Value + + q := uri.NewQueryEncoder() + { + // Encode "filename" form field. + cfg := uri.QueryParameterEncodingConfig{ + Name: "filename", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := request.Filename.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode query") + } + } + body, boundary := ht.CreateMultipartBody(func(w *multipart.Writer) error { + if val, ok := request.File.Get(); ok { + if err := val.WriteMultipart("file", w); err != nil { + return errors.Wrap(err, "write \"file\"") + } + } + if err := q.WriteMultipart(w); err != nil { + return errors.Wrap(err, "write multipart") + } + return nil + }) + ht.SetCloserBody(r, body, mime.FormatMediaType(contentType, map[string]string{"boundary": boundary})) + return nil +} + +func encodeTestReuseFormSchemaRequest( + req *SharedRequestMultipart, + r *http.Request, +) error { + const contentType = "multipart/form-data" + request := req + + q := uri.NewQueryEncoder() + { + // Encode "filename" form field. + cfg := uri.QueryParameterEncodingConfig{ + Name: "filename", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := request.Filename.Get(); ok { + return e.EncodeValue(conv.StringToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode query") + } + } + body, boundary := ht.CreateMultipartBody(func(w *multipart.Writer) error { + if val, ok := request.File.Get(); ok { + if err := val.WriteMultipart("file", w); err != nil { + return errors.Wrap(err, "write \"file\"") + } + } + if err := q.WriteMultipart(w); err != nil { + return errors.Wrap(err, "write multipart") + } + return nil + }) + ht.SetCloserBody(r, body, mime.FormatMediaType(contentType, map[string]string{"boundary": boundary})) + return nil +} + func encodeTestShareFormSchemaRequest( req TestShareFormSchemaReq, r *http.Request, @@ -406,7 +488,7 @@ func encodeTestShareFormSchemaRequest( encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) return nil - case *SharedRequestForm: + case *SharedRequestMultipart: const contentType = "multipart/form-data" request := req diff --git a/internal/integration/test_form/oas_response_decoders_gen.go b/internal/integration/test_form/oas_response_decoders_gen.go index 9fc773cd4..15189e5b3 100644 --- a/internal/integration/test_form/oas_response_decoders_gen.go +++ b/internal/integration/test_form/oas_response_decoders_gen.go @@ -100,6 +100,24 @@ func decodeTestMultipartUploadResponse(resp *http.Response) (res *TestMultipartU return res, validate.UnexpectedStatusCode(resp.StatusCode) } +func decodeTestReuseFormOptionalSchemaResponse(resp *http.Response) (res *TestReuseFormOptionalSchemaOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &TestReuseFormOptionalSchemaOK{}, nil + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + +func decodeTestReuseFormSchemaResponse(resp *http.Response) (res *TestReuseFormSchemaOK, _ error) { + switch resp.StatusCode { + case 200: + // Code 200. + return &TestReuseFormSchemaOK{}, nil + } + return res, validate.UnexpectedStatusCode(resp.StatusCode) +} + func decodeTestShareFormSchemaResponse(resp *http.Response) (res *TestShareFormSchemaOK, _ error) { switch resp.StatusCode { case 200: diff --git a/internal/integration/test_form/oas_response_encoders_gen.go b/internal/integration/test_form/oas_response_encoders_gen.go index 98d713868..7a96463f4 100644 --- a/internal/integration/test_form/oas_response_encoders_gen.go +++ b/internal/integration/test_form/oas_response_encoders_gen.go @@ -59,6 +59,20 @@ func encodeTestMultipartUploadResponse(response *TestMultipartUploadOK, w http.R return nil } +func encodeTestReuseFormOptionalSchemaResponse(response *TestReuseFormOptionalSchemaOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + +func encodeTestReuseFormSchemaResponse(response *TestReuseFormSchemaOK, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(200) + span.SetStatus(codes.Ok, http.StatusText(200)) + + return nil +} + func encodeTestShareFormSchemaResponse(response *TestShareFormSchemaOK, w http.ResponseWriter, span trace.Span) error { w.WriteHeader(200) span.SetStatus(codes.Ok, http.StatusText(200)) diff --git a/internal/integration/test_form/oas_router_gen.go b/internal/integration/test_form/oas_router_gen.go index 5c86250e6..15f46e90f 100644 --- a/internal/integration/test_form/oas_router_gen.go +++ b/internal/integration/test_form/oas_router_gen.go @@ -195,6 +195,54 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { s.notAllowed(w, r, "POST") } + return + } + } + case 'R': // Prefix: "ReuseForm" + if l := len("ReuseForm"); len(elem) >= l && elem[0:l] == "ReuseForm" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'O': // Prefix: "OptionalSchema" + if l := len("OptionalSchema"); len(elem) >= l && elem[0:l] == "OptionalSchema" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleTestReuseFormOptionalSchemaRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + case 'S': // Prefix: "Schema" + if l := len("Schema"); len(elem) >= l && elem[0:l] == "Schema" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleTestReuseFormSchemaRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + return } } @@ -460,6 +508,60 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } } } + case 'R': // Prefix: "ReuseForm" + if l := len("ReuseForm"); len(elem) >= l && elem[0:l] == "ReuseForm" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'O': // Prefix: "OptionalSchema" + if l := len("OptionalSchema"); len(elem) >= l && elem[0:l] == "OptionalSchema" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "POST": + // Leaf: TestReuseFormOptionalSchema + r.name = "TestReuseFormOptionalSchema" + r.operationID = "testReuseFormOptionalSchema" + r.pathPattern = "/testReuseFormOptionalSchema" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + case 'S': // Prefix: "Schema" + if l := len("Schema"); len(elem) >= l && elem[0:l] == "Schema" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "POST": + // Leaf: TestReuseFormSchema + r.name = "TestReuseFormSchema" + r.operationID = "testReuseFormSchema" + r.pathPattern = "/testReuseFormSchema" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + } case 'S': // Prefix: "ShareFormSchema" if l := len("ShareFormSchema"); len(elem) >= l && elem[0:l] == "ShareFormSchema" { elem = elem[l:] diff --git a/internal/integration/test_form/oas_schemas_gen.go b/internal/integration/test_form/oas_schemas_gen.go index cd490b99d..5b97e6e55 100644 --- a/internal/integration/test_form/oas_schemas_gen.go +++ b/internal/integration/test_form/oas_schemas_gen.go @@ -29,30 +29,16 @@ func (s *OnlyFormReq) SetField(val int) { type OnlyMultipartFileOK struct{} type OnlyMultipartFileReq struct { - File string `json:"file"` -} - -// GetFile returns the value of File. -func (s *OnlyMultipartFileReq) GetFile() string { - return s.File -} - -// SetFile sets the value of File. -func (s *OnlyMultipartFileReq) SetFile(val string) { - s.File = val -} - -type OnlyMultipartFileReqForm struct { File ht.MultipartFile `json:"file"` } // GetFile returns the value of File. -func (s *OnlyMultipartFileReqForm) GetFile() ht.MultipartFile { +func (s *OnlyMultipartFileReq) GetFile() ht.MultipartFile { return s.File } // SetFile sets the value of File. -func (s *OnlyMultipartFileReqForm) SetFile(val ht.MultipartFile) { +func (s *OnlyMultipartFileReq) SetFile(val ht.MultipartFile) { s.File = val } @@ -165,6 +151,52 @@ func (o OptMultipartFile) Or(d ht.MultipartFile) ht.MultipartFile { return d } +// NewOptSharedRequestMultipart returns new OptSharedRequestMultipart with value set to v. +func NewOptSharedRequestMultipart(v SharedRequestMultipart) OptSharedRequestMultipart { + return OptSharedRequestMultipart{ + Value: v, + Set: true, + } +} + +// OptSharedRequestMultipart is optional SharedRequestMultipart. +type OptSharedRequestMultipart struct { + Value SharedRequestMultipart + Set bool +} + +// IsSet returns true if OptSharedRequestMultipart was set. +func (o OptSharedRequestMultipart) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptSharedRequestMultipart) Reset() { + var v SharedRequestMultipart + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptSharedRequestMultipart) SetTo(v SharedRequestMultipart) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptSharedRequestMultipart) Get() (v SharedRequestMultipart, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptSharedRequestMultipart) Or(d SharedRequestMultipart) SharedRequestMultipart { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptString returns new OptString with value set to v. func NewOptString(v string) OptString { return OptString{ @@ -257,6 +289,98 @@ func (o OptTestFormDeepObject) Or(d TestFormDeepObject) TestFormDeepObject { return d } +// NewOptTestFormMultipartDeepObject returns new OptTestFormMultipartDeepObject with value set to v. +func NewOptTestFormMultipartDeepObject(v TestFormMultipartDeepObject) OptTestFormMultipartDeepObject { + return OptTestFormMultipartDeepObject{ + Value: v, + Set: true, + } +} + +// OptTestFormMultipartDeepObject is optional TestFormMultipartDeepObject. +type OptTestFormMultipartDeepObject struct { + Value TestFormMultipartDeepObject + Set bool +} + +// IsSet returns true if OptTestFormMultipartDeepObject was set. +func (o OptTestFormMultipartDeepObject) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptTestFormMultipartDeepObject) Reset() { + var v TestFormMultipartDeepObject + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptTestFormMultipartDeepObject) SetTo(v TestFormMultipartDeepObject) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptTestFormMultipartDeepObject) Get() (v TestFormMultipartDeepObject, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptTestFormMultipartDeepObject) Or(d TestFormMultipartDeepObject) TestFormMultipartDeepObject { + if v, ok := o.Get(); ok { + return v + } + return d +} + +// NewOptTestFormMultipartObject returns new OptTestFormMultipartObject with value set to v. +func NewOptTestFormMultipartObject(v TestFormMultipartObject) OptTestFormMultipartObject { + return OptTestFormMultipartObject{ + Value: v, + Set: true, + } +} + +// OptTestFormMultipartObject is optional TestFormMultipartObject. +type OptTestFormMultipartObject struct { + Value TestFormMultipartObject + Set bool +} + +// IsSet returns true if OptTestFormMultipartObject was set. +func (o OptTestFormMultipartObject) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptTestFormMultipartObject) Reset() { + var v TestFormMultipartObject + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptTestFormMultipartObject) SetTo(v TestFormMultipartObject) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptTestFormMultipartObject) Get() (v TestFormMultipartObject, ok bool) { + if !o.Set { + return v, false + } + return o.Value, true +} + +// Or returns value if set, or given parameter if does not. +func (o OptTestFormMultipartObject) Or(d TestFormMultipartObject) TestFormMultipartObject { + if v, ok := o.Get(); ok { + return v + } + return d +} + // NewOptTestFormObject returns new OptTestFormObject with value set to v. func NewOptTestFormObject(v TestFormObject) OptTestFormObject { return OptTestFormObject{ @@ -378,32 +502,32 @@ func (s *SharedRequest) SetFile(val OptString) { func (*SharedRequest) testShareFormSchemaReq() {} // Ref: #/components/schemas/SharedRequest -type SharedRequestForm struct { +type SharedRequestMultipart struct { Filename OptString `json:"filename"` File OptMultipartFile `json:"file"` } // GetFilename returns the value of Filename. -func (s *SharedRequestForm) GetFilename() OptString { +func (s *SharedRequestMultipart) GetFilename() OptString { return s.Filename } // GetFile returns the value of File. -func (s *SharedRequestForm) GetFile() OptMultipartFile { +func (s *SharedRequestMultipart) GetFile() OptMultipartFile { return s.File } // SetFilename sets the value of Filename. -func (s *SharedRequestForm) SetFilename(val OptString) { +func (s *SharedRequestMultipart) SetFilename(val OptString) { s.Filename = val } // SetFile sets the value of File. -func (s *SharedRequestForm) SetFile(val OptMultipartFile) { +func (s *SharedRequestMultipart) SetFile(val OptMultipartFile) { s.File = val } -func (*SharedRequestForm) testShareFormSchemaReq() {} +func (*SharedRequestMultipart) testShareFormSchemaReq() {} // Ref: #/components/schemas/TestForm type TestForm struct { @@ -500,6 +624,126 @@ func (s *TestFormDeepObject) SetMax(val int) { s.Max = val } +// Ref: #/components/schemas/TestForm +type TestFormMultipart struct { + ID OptInt `json:"id"` + UUID OptUUID `json:"uuid"` + Description string `json:"description"` + Array []string `json:"array"` + Object OptTestFormMultipartObject `json:"object"` + DeepObject OptTestFormMultipartDeepObject `json:"deepObject"` +} + +// GetID returns the value of ID. +func (s *TestFormMultipart) GetID() OptInt { + return s.ID +} + +// GetUUID returns the value of UUID. +func (s *TestFormMultipart) GetUUID() OptUUID { + return s.UUID +} + +// GetDescription returns the value of Description. +func (s *TestFormMultipart) GetDescription() string { + return s.Description +} + +// GetArray returns the value of Array. +func (s *TestFormMultipart) GetArray() []string { + return s.Array +} + +// GetObject returns the value of Object. +func (s *TestFormMultipart) GetObject() OptTestFormMultipartObject { + return s.Object +} + +// GetDeepObject returns the value of DeepObject. +func (s *TestFormMultipart) GetDeepObject() OptTestFormMultipartDeepObject { + return s.DeepObject +} + +// SetID sets the value of ID. +func (s *TestFormMultipart) SetID(val OptInt) { + s.ID = val +} + +// SetUUID sets the value of UUID. +func (s *TestFormMultipart) SetUUID(val OptUUID) { + s.UUID = val +} + +// SetDescription sets the value of Description. +func (s *TestFormMultipart) SetDescription(val string) { + s.Description = val +} + +// SetArray sets the value of Array. +func (s *TestFormMultipart) SetArray(val []string) { + s.Array = val +} + +// SetObject sets the value of Object. +func (s *TestFormMultipart) SetObject(val OptTestFormMultipartObject) { + s.Object = val +} + +// SetDeepObject sets the value of DeepObject. +func (s *TestFormMultipart) SetDeepObject(val OptTestFormMultipartDeepObject) { + s.DeepObject = val +} + +type TestFormMultipartDeepObject struct { + Min OptInt `json:"min"` + Max int `json:"max"` +} + +// GetMin returns the value of Min. +func (s *TestFormMultipartDeepObject) GetMin() OptInt { + return s.Min +} + +// GetMax returns the value of Max. +func (s *TestFormMultipartDeepObject) GetMax() int { + return s.Max +} + +// SetMin sets the value of Min. +func (s *TestFormMultipartDeepObject) SetMin(val OptInt) { + s.Min = val +} + +// SetMax sets the value of Max. +func (s *TestFormMultipartDeepObject) SetMax(val int) { + s.Max = val +} + +type TestFormMultipartObject struct { + Min OptInt `json:"min"` + Max int `json:"max"` +} + +// GetMin returns the value of Min. +func (s *TestFormMultipartObject) GetMin() OptInt { + return s.Min +} + +// GetMax returns the value of Max. +func (s *TestFormMultipartObject) GetMax() int { + return s.Max +} + +// SetMin sets the value of Min. +func (s *TestFormMultipartObject) SetMin(val OptInt) { + s.Min = val +} + +// SetMax sets the value of Max. +func (s *TestFormMultipartObject) SetMax(val int) { + s.Max = val +} + type TestFormObject struct { Min OptInt `json:"min"` Max int `json:"max"` @@ -568,11 +812,11 @@ func (s *TestMultipartUploadOK) SetFiles(val []string) { } type TestMultipartUploadReq struct { - OrderId OptInt `json:"orderId"` - UserId OptInt `json:"userId"` - File string `json:"file"` - OptionalFile OptString `json:"optional_file"` - Files []string `json:"files"` + OrderId OptInt `json:"orderId"` + UserId OptInt `json:"userId"` + File ht.MultipartFile `json:"file"` + OptionalFile OptMultipartFile `json:"optional_file"` + Files []ht.MultipartFile `json:"files"` } // GetOrderId returns the value of OrderId. @@ -586,17 +830,17 @@ func (s *TestMultipartUploadReq) GetUserId() OptInt { } // GetFile returns the value of File. -func (s *TestMultipartUploadReq) GetFile() string { +func (s *TestMultipartUploadReq) GetFile() ht.MultipartFile { return s.File } // GetOptionalFile returns the value of OptionalFile. -func (s *TestMultipartUploadReq) GetOptionalFile() OptString { +func (s *TestMultipartUploadReq) GetOptionalFile() OptMultipartFile { return s.OptionalFile } // GetFiles returns the value of Files. -func (s *TestMultipartUploadReq) GetFiles() []string { +func (s *TestMultipartUploadReq) GetFiles() []ht.MultipartFile { return s.Files } @@ -611,77 +855,25 @@ func (s *TestMultipartUploadReq) SetUserId(val OptInt) { } // SetFile sets the value of File. -func (s *TestMultipartUploadReq) SetFile(val string) { +func (s *TestMultipartUploadReq) SetFile(val ht.MultipartFile) { s.File = val } // SetOptionalFile sets the value of OptionalFile. -func (s *TestMultipartUploadReq) SetOptionalFile(val OptString) { +func (s *TestMultipartUploadReq) SetOptionalFile(val OptMultipartFile) { s.OptionalFile = val } // SetFiles sets the value of Files. -func (s *TestMultipartUploadReq) SetFiles(val []string) { +func (s *TestMultipartUploadReq) SetFiles(val []ht.MultipartFile) { s.Files = val } -type TestMultipartUploadReqForm struct { - OrderId OptInt `json:"orderId"` - UserId OptInt `json:"userId"` - File ht.MultipartFile `json:"file"` - OptionalFile OptMultipartFile `json:"optional_file"` - Files []ht.MultipartFile `json:"files"` -} - -// GetOrderId returns the value of OrderId. -func (s *TestMultipartUploadReqForm) GetOrderId() OptInt { - return s.OrderId -} - -// GetUserId returns the value of UserId. -func (s *TestMultipartUploadReqForm) GetUserId() OptInt { - return s.UserId -} +// TestReuseFormOptionalSchemaOK is response for TestReuseFormOptionalSchema operation. +type TestReuseFormOptionalSchemaOK struct{} -// GetFile returns the value of File. -func (s *TestMultipartUploadReqForm) GetFile() ht.MultipartFile { - return s.File -} - -// GetOptionalFile returns the value of OptionalFile. -func (s *TestMultipartUploadReqForm) GetOptionalFile() OptMultipartFile { - return s.OptionalFile -} - -// GetFiles returns the value of Files. -func (s *TestMultipartUploadReqForm) GetFiles() []ht.MultipartFile { - return s.Files -} - -// SetOrderId sets the value of OrderId. -func (s *TestMultipartUploadReqForm) SetOrderId(val OptInt) { - s.OrderId = val -} - -// SetUserId sets the value of UserId. -func (s *TestMultipartUploadReqForm) SetUserId(val OptInt) { - s.UserId = val -} - -// SetFile sets the value of File. -func (s *TestMultipartUploadReqForm) SetFile(val ht.MultipartFile) { - s.File = val -} - -// SetOptionalFile sets the value of OptionalFile. -func (s *TestMultipartUploadReqForm) SetOptionalFile(val OptMultipartFile) { - s.OptionalFile = val -} - -// SetFiles sets the value of Files. -func (s *TestMultipartUploadReqForm) SetFiles(val []ht.MultipartFile) { - s.Files = val -} +// TestReuseFormSchemaOK is response for TestReuseFormSchema operation. +type TestReuseFormSchemaOK struct{} // TestShareFormSchemaOK is response for TestShareFormSchema operation. type TestShareFormSchemaOK struct{} diff --git a/internal/integration/test_form/oas_server_gen.go b/internal/integration/test_form/oas_server_gen.go index 952eadd61..eb4afd625 100644 --- a/internal/integration/test_form/oas_server_gen.go +++ b/internal/integration/test_form/oas_server_gen.go @@ -15,7 +15,7 @@ type Handler interface { // OnlyMultipartFile implements onlyMultipartFile operation. // // POST /onlyMultipartFile - OnlyMultipartFile(ctx context.Context, req *OnlyMultipartFileReqForm) error + OnlyMultipartFile(ctx context.Context, req *OnlyMultipartFileReq) error // OnlyMultipartForm implements onlyMultipartForm operation. // // POST /onlyMultipartForm @@ -27,11 +27,19 @@ type Handler interface { // TestMultipart implements testMultipart operation. // // POST /testMultipart - TestMultipart(ctx context.Context, req *TestForm) error + TestMultipart(ctx context.Context, req *TestFormMultipart) error // TestMultipartUpload implements testMultipartUpload operation. // // POST /testMultipartUpload - TestMultipartUpload(ctx context.Context, req *TestMultipartUploadReqForm) (*TestMultipartUploadOK, error) + TestMultipartUpload(ctx context.Context, req *TestMultipartUploadReq) (*TestMultipartUploadOK, error) + // TestReuseFormOptionalSchema implements testReuseFormOptionalSchema operation. + // + // POST /testReuseFormOptionalSchema + TestReuseFormOptionalSchema(ctx context.Context, req OptSharedRequestMultipart) error + // TestReuseFormSchema implements testReuseFormSchema operation. + // + // POST /testReuseFormSchema + TestReuseFormSchema(ctx context.Context, req *SharedRequestMultipart) error // TestShareFormSchema implements testShareFormSchema operation. // // POST /testShareFormSchema diff --git a/internal/integration/test_form/oas_unimplemented_gen.go b/internal/integration/test_form/oas_unimplemented_gen.go index 55503a55a..d78e98ff1 100644 --- a/internal/integration/test_form/oas_unimplemented_gen.go +++ b/internal/integration/test_form/oas_unimplemented_gen.go @@ -23,7 +23,7 @@ func (UnimplementedHandler) OnlyForm(ctx context.Context, req *OnlyFormReq) erro // OnlyMultipartFile implements onlyMultipartFile operation. // // POST /onlyMultipartFile -func (UnimplementedHandler) OnlyMultipartFile(ctx context.Context, req *OnlyMultipartFileReqForm) error { +func (UnimplementedHandler) OnlyMultipartFile(ctx context.Context, req *OnlyMultipartFileReq) error { return ht.ErrNotImplemented } @@ -44,17 +44,31 @@ func (UnimplementedHandler) TestFormURLEncoded(ctx context.Context, req *TestFor // TestMultipart implements testMultipart operation. // // POST /testMultipart -func (UnimplementedHandler) TestMultipart(ctx context.Context, req *TestForm) error { +func (UnimplementedHandler) TestMultipart(ctx context.Context, req *TestFormMultipart) error { return ht.ErrNotImplemented } // TestMultipartUpload implements testMultipartUpload operation. // // POST /testMultipartUpload -func (UnimplementedHandler) TestMultipartUpload(ctx context.Context, req *TestMultipartUploadReqForm) (r *TestMultipartUploadOK, _ error) { +func (UnimplementedHandler) TestMultipartUpload(ctx context.Context, req *TestMultipartUploadReq) (r *TestMultipartUploadOK, _ error) { return r, ht.ErrNotImplemented } +// TestReuseFormOptionalSchema implements testReuseFormOptionalSchema operation. +// +// POST /testReuseFormOptionalSchema +func (UnimplementedHandler) TestReuseFormOptionalSchema(ctx context.Context, req OptSharedRequestMultipart) error { + return ht.ErrNotImplemented +} + +// TestReuseFormSchema implements testReuseFormSchema operation. +// +// POST /testReuseFormSchema +func (UnimplementedHandler) TestReuseFormSchema(ctx context.Context, req *SharedRequestMultipart) error { + return ht.ErrNotImplemented +} + // TestShareFormSchema implements testShareFormSchema operation. // // POST /testShareFormSchema diff --git a/internal/integration/test_form/oas_uri_gen.go b/internal/integration/test_form/oas_uri_gen.go index 42cbe8376..844aa2a30 100644 --- a/internal/integration/test_form/oas_uri_gen.go +++ b/internal/integration/test_form/oas_uri_gen.go @@ -130,6 +130,240 @@ func (s *TestFormDeepObject) DecodeURI(d uri.Decoder) error { return nil } +// EncodeURI encodes TestFormMultipartDeepObject as URI form. +func (s *TestFormMultipartDeepObject) EncodeURI(e uri.Encoder) error { + if err := e.EncodeField("min", func(e uri.Encoder) error { + if val, ok := s.Min.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode field \"min\"") + } + if err := e.EncodeField("max", func(e uri.Encoder) error { + return e.EncodeValue(conv.IntToString(s.Max)) + }); err != nil { + return errors.Wrap(err, "encode field \"max\"") + } + return nil +} + +var uriFieldsNameOfTestFormMultipartDeepObject = [2]string{ + 0: "min", + 1: "max", +} + +// DecodeURI decodes TestFormMultipartDeepObject from URI form. +func (s *TestFormMultipartDeepObject) DecodeURI(d uri.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode TestFormMultipartDeepObject to nil") + } + var requiredBitSet [1]uint8 + + if err := d.DecodeFields(func(k string, d uri.Decoder) error { + switch k { + case "min": + if err := func() error { + var sDotMinVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + sDotMinVal = c + return nil + }(); err != nil { + return err + } + s.Min.SetTo(sDotMinVal) + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"min\"") + } + case "max": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + s.Max = c + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"max\"") + } + default: + return nil + } + return nil + }); err != nil { + return errors.Wrap(err, "decode TestFormMultipartDeepObject") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000010, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(uriFieldsNameOfTestFormMultipartDeepObject) { + name = uriFieldsNameOfTestFormMultipartDeepObject[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + +// EncodeURI encodes TestFormMultipartObject as URI form. +func (s *TestFormMultipartObject) EncodeURI(e uri.Encoder) error { + if err := e.EncodeField("min", func(e uri.Encoder) error { + if val, ok := s.Min.Get(); ok { + return e.EncodeValue(conv.IntToString(val)) + } + return nil + }); err != nil { + return errors.Wrap(err, "encode field \"min\"") + } + if err := e.EncodeField("max", func(e uri.Encoder) error { + return e.EncodeValue(conv.IntToString(s.Max)) + }); err != nil { + return errors.Wrap(err, "encode field \"max\"") + } + return nil +} + +var uriFieldsNameOfTestFormMultipartObject = [2]string{ + 0: "min", + 1: "max", +} + +// DecodeURI decodes TestFormMultipartObject from URI form. +func (s *TestFormMultipartObject) DecodeURI(d uri.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode TestFormMultipartObject to nil") + } + var requiredBitSet [1]uint8 + + if err := d.DecodeFields(func(k string, d uri.Decoder) error { + switch k { + case "min": + if err := func() error { + var sDotMinVal int + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + sDotMinVal = c + return nil + }(); err != nil { + return err + } + s.Min.SetTo(sDotMinVal) + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"min\"") + } + case "max": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt(val) + if err != nil { + return err + } + + s.Max = c + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"max\"") + } + default: + return nil + } + return nil + }); err != nil { + return errors.Wrap(err, "decode TestFormMultipartObject") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000010, + } { + if result := (requiredBitSet[i] & mask) ^ mask; result != 0 { + // Mask only required fields and check equality to mask using XOR. + // + // If XOR result is not zero, result is not equal to expected, so some fields are missed. + // Bits of fields which would be set are actually bits of missed fields. + missed := bits.OnesCount8(result) + for bitN := 0; bitN < missed; bitN++ { + bitIdx := bits.TrailingZeros8(result) + fieldIdx := i*8 + bitIdx + var name string + if fieldIdx < len(uriFieldsNameOfTestFormMultipartObject) { + name = uriFieldsNameOfTestFormMultipartObject[fieldIdx] + } else { + name = strconv.Itoa(fieldIdx) + } + failures = append(failures, validate.FieldError{ + Name: name, + Error: validate.ErrFieldRequired, + }) + // Reset bit. + result &^= 1 << bitIdx + } + } + } + if len(failures) > 0 { + return &validate.Error{Fields: failures} + } + + return nil +} + // EncodeURI encodes TestFormObject as URI form. func (s *TestFormObject) EncodeURI(e uri.Encoder) error { if err := e.EncodeField("min", func(e uri.Encoder) error { diff --git a/internal/integration/test_form/oas_validators_gen.go b/internal/integration/test_form/oas_validators_gen.go index c1b62ecf9..4b9c4150f 100644 --- a/internal/integration/test_form/oas_validators_gen.go +++ b/internal/integration/test_form/oas_validators_gen.go @@ -35,32 +35,6 @@ func (s *TestMultipartUploadOK) Validate() error { return nil } func (s *TestMultipartUploadReq) Validate() error { - var failures []validate.FieldError - if err := func() error { - if s.Files == nil { - return errors.New("nil is invalid value") - } - if err := (validate.Array{ - MinLength: 0, - MinLengthSet: false, - MaxLength: 5, - MaxLengthSet: true, - }).ValidateLength(len(s.Files)); err != nil { - return errors.Wrap(err, "array") - } - return nil - }(); err != nil { - failures = append(failures, validate.FieldError{ - Name: "files", - Error: err, - }) - } - if len(failures) > 0 { - return &validate.Error{Fields: failures} - } - return nil -} -func (s *TestMultipartUploadReqForm) Validate() error { var failures []validate.FieldError if err := func() error { if err := (validate.Array{ diff --git a/internal/integration/test_http_requests/oas_client_gen.go b/internal/integration/test_http_requests/oas_client_gen.go index 8871aa155..34e0e257f 100644 --- a/internal/integration/test_http_requests/oas_client_gen.go +++ b/internal/integration/test_http_requests/oas_client_gen.go @@ -89,7 +89,7 @@ func (c *Client) sendAllRequestBodies(ctx context.Context, request AllRequestBod // Validation is not required for this type. case *AllRequestBodiesApplicationXWwwFormUrlencoded: // Validation is not required for this type. - case *AllRequestBodiesMultipartFormData: + case *SimpleObjectMultipart: // Validation is not required for this type. case *AllRequestBodiesReqTextPlain: // Validation is not required for this type. @@ -177,7 +177,7 @@ func (c *Client) sendAllRequestBodiesOptional(ctx context.Context, request AllRe // Validation is not required for this type. case *AllRequestBodiesOptionalApplicationXWwwFormUrlencoded: // Validation is not required for this type. - case *AllRequestBodiesOptionalMultipartFormData: + case *SimpleObjectMultipart: // Validation is not required for this type. case *AllRequestBodiesOptionalReqTextPlain: // Validation is not required for this type. diff --git a/internal/integration/test_http_requests/oas_json_gen.go b/internal/integration/test_http_requests/oas_json_gen.go index e8654d72f..3c681ba98 100644 --- a/internal/integration/test_http_requests/oas_json_gen.go +++ b/internal/integration/test_http_requests/oas_json_gen.go @@ -88,44 +88,6 @@ func (s *AllRequestBodiesApplicationXWwwFormUrlencoded) UnmarshalJSON(data []byt return s.Decode(d) } -// Encode encodes AllRequestBodiesMultipartFormData as json. -func (s *AllRequestBodiesMultipartFormData) Encode(e *jx.Encoder) { - unwrapped := (*SimpleObject)(s) - - unwrapped.Encode(e) -} - -// Decode decodes AllRequestBodiesMultipartFormData from json. -func (s *AllRequestBodiesMultipartFormData) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode AllRequestBodiesMultipartFormData to nil") - } - var unwrapped SimpleObject - if err := func() error { - if err := unwrapped.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = AllRequestBodiesMultipartFormData(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *AllRequestBodiesMultipartFormData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *AllRequestBodiesMultipartFormData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes AllRequestBodiesOptionalApplicationJSON as json. func (s *AllRequestBodiesOptionalApplicationJSON) Encode(e *jx.Encoder) { unwrapped := (*SimpleObject)(s) @@ -202,44 +164,6 @@ func (s *AllRequestBodiesOptionalApplicationXWwwFormUrlencoded) UnmarshalJSON(da return s.Decode(d) } -// Encode encodes AllRequestBodiesOptionalMultipartFormData as json. -func (s *AllRequestBodiesOptionalMultipartFormData) Encode(e *jx.Encoder) { - unwrapped := (*SimpleObject)(s) - - unwrapped.Encode(e) -} - -// Decode decodes AllRequestBodiesOptionalMultipartFormData from json. -func (s *AllRequestBodiesOptionalMultipartFormData) Decode(d *jx.Decoder) error { - if s == nil { - return errors.New("invalid: unable to decode AllRequestBodiesOptionalMultipartFormData to nil") - } - var unwrapped SimpleObject - if err := func() error { - if err := unwrapped.Decode(d); err != nil { - return err - } - return nil - }(); err != nil { - return errors.Wrap(err, "alias") - } - *s = AllRequestBodiesOptionalMultipartFormData(unwrapped) - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s *AllRequestBodiesOptionalMultipartFormData) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *AllRequestBodiesOptionalMultipartFormData) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode implements json.Marshaler. func (s *MaskResponse) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/internal/integration/test_http_requests/oas_request_decoders_gen.go b/internal/integration/test_http_requests/oas_request_decoders_gen.go index 36ecf3bf2..dc7654485 100644 --- a/internal/integration/test_http_requests/oas_request_decoders_gen.go +++ b/internal/integration/test_http_requests/oas_request_decoders_gen.go @@ -174,70 +174,66 @@ func (s *Server) decodeAllRequestBodiesRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request AllRequestBodiesMultipartFormData + var request SimpleObjectMultipart + q := uri.NewQueryDecoder(form) { - var unwrapped SimpleObject - q := uri.NewQueryDecoder(form) - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "name", - Style: uri.QueryStyleForm, - Explode: true, + cfg := uri.QueryParameterDecodingConfig{ + Name: "name", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + request.Name = c + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"name\"") } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + } else { + return req, close, errors.Wrap(err, "query") + } + } + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "age", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var requestDotAgeVal int + if err := func() error { val, err := d.DecodeValue() if err != nil { return err } - c, err := conv.ToString(val) + c, err := conv.ToInt(val) if err != nil { return err } - unwrapped.Name = c - return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"name\"") - } - } else { - return req, close, errors.Wrap(err, "query") - } - } - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "age", - Style: uri.QueryStyleForm, - Explode: true, - } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var unwrappedDotAgeVal int - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt(val) - if err != nil { - return err - } - - unwrappedDotAgeVal = c - return nil - }(); err != nil { - return err - } - unwrapped.Age.SetTo(unwrappedDotAgeVal) + requestDotAgeVal = c return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"age\"") + }(); err != nil { + return err } + request.Age.SetTo(requestDotAgeVal) + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"age\"") } } - request = AllRequestBodiesMultipartFormData(unwrapped) } return &request, close, nil case ct == "text/plain": @@ -406,70 +402,66 @@ func (s *Server) decodeAllRequestBodiesOptionalRequest(r *http.Request) ( form := url.Values(r.MultipartForm.Value) _ = form - var request AllRequestBodiesOptionalMultipartFormData + var request SimpleObjectMultipart + q := uri.NewQueryDecoder(form) { - var unwrapped SimpleObject - q := uri.NewQueryDecoder(form) - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "name", - Style: uri.QueryStyleForm, - Explode: true, + cfg := uri.QueryParameterDecodingConfig{ + Name: "name", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToString(val) + if err != nil { + return err + } + + request.Name = c + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"name\"") } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + } else { + return req, close, errors.Wrap(err, "query") + } + } + { + cfg := uri.QueryParameterDecodingConfig{ + Name: "age", + Style: uri.QueryStyleForm, + Explode: true, + } + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var requestDotAgeVal int + if err := func() error { val, err := d.DecodeValue() if err != nil { return err } - c, err := conv.ToString(val) + c, err := conv.ToInt(val) if err != nil { return err } - unwrapped.Name = c - return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"name\"") - } - } else { - return req, close, errors.Wrap(err, "query") - } - } - { - cfg := uri.QueryParameterDecodingConfig{ - Name: "age", - Style: uri.QueryStyleForm, - Explode: true, - } - if err := q.HasParam(cfg); err == nil { - if err := q.DecodeParam(cfg, func(d uri.Decoder) error { - var unwrappedDotAgeVal int - if err := func() error { - val, err := d.DecodeValue() - if err != nil { - return err - } - - c, err := conv.ToInt(val) - if err != nil { - return err - } - - unwrappedDotAgeVal = c - return nil - }(); err != nil { - return err - } - unwrapped.Age.SetTo(unwrappedDotAgeVal) + requestDotAgeVal = c return nil - }); err != nil { - return req, close, errors.Wrap(err, "decode \"age\"") + }(); err != nil { + return err } + request.Age.SetTo(requestDotAgeVal) + return nil + }); err != nil { + return req, close, errors.Wrap(err, "decode \"age\"") } } - request = AllRequestBodiesOptionalMultipartFormData(unwrapped) } return &request, close, nil case ct == "text/plain": diff --git a/internal/integration/test_http_requests/oas_request_encoders_gen.go b/internal/integration/test_http_requests/oas_request_encoders_gen.go index dfeb954db..0563dee3b 100644 --- a/internal/integration/test_http_requests/oas_request_encoders_gen.go +++ b/internal/integration/test_http_requests/oas_request_encoders_gen.go @@ -75,7 +75,7 @@ func encodeAllRequestBodiesRequest( encoded := q.Values().Encode() ht.SetBody(r, strings.NewReader(encoded), contentType) return nil - case *AllRequestBodiesMultipartFormData: + case *SimpleObjectMultipart: const contentType = "multipart/form-data" request := req @@ -186,7 +186,7 @@ func encodeAllRequestBodiesOptionalRequest( encoded := q.Values().Encode() ht.SetBody(r, strings.NewReader(encoded), contentType) return nil - case *AllRequestBodiesOptionalMultipartFormData: + case *SimpleObjectMultipart: const contentType = "multipart/form-data" request := req diff --git a/internal/integration/test_http_requests/oas_schemas_gen.go b/internal/integration/test_http_requests/oas_schemas_gen.go index eae0dad82..486713f49 100644 --- a/internal/integration/test_http_requests/oas_schemas_gen.go +++ b/internal/integration/test_http_requests/oas_schemas_gen.go @@ -14,10 +14,6 @@ type AllRequestBodiesApplicationXWwwFormUrlencoded SimpleObject func (*AllRequestBodiesApplicationXWwwFormUrlencoded) allRequestBodiesReq() {} -type AllRequestBodiesMultipartFormData SimpleObject - -func (*AllRequestBodiesMultipartFormData) allRequestBodiesReq() {} - type AllRequestBodiesOK struct { Data io.Reader } @@ -37,10 +33,6 @@ type AllRequestBodiesOptionalApplicationXWwwFormUrlencoded SimpleObject func (*AllRequestBodiesOptionalApplicationXWwwFormUrlencoded) allRequestBodiesOptionalReq() {} -type AllRequestBodiesOptionalMultipartFormData SimpleObject - -func (*AllRequestBodiesOptionalMultipartFormData) allRequestBodiesOptionalReq() {} - type AllRequestBodiesOptionalOK struct { Data io.Reader } @@ -301,3 +293,32 @@ func (s *SimpleObject) SetName(val string) { func (s *SimpleObject) SetAge(val OptInt) { s.Age = val } + +// Ref: #/components/schemas/SimpleObject +type SimpleObjectMultipart struct { + Name string `json:"name"` + Age OptInt `json:"age"` +} + +// GetName returns the value of Name. +func (s *SimpleObjectMultipart) GetName() string { + return s.Name +} + +// GetAge returns the value of Age. +func (s *SimpleObjectMultipart) GetAge() OptInt { + return s.Age +} + +// SetName sets the value of Name. +func (s *SimpleObjectMultipart) SetName(val string) { + s.Name = val +} + +// SetAge sets the value of Age. +func (s *SimpleObjectMultipart) SetAge(val OptInt) { + s.Age = val +} + +func (*SimpleObjectMultipart) allRequestBodiesOptionalReq() {} +func (*SimpleObjectMultipart) allRequestBodiesReq() {}