From 47c30ad2db5ef03bfb6121f0823827e7fd2f365d Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sun, 15 Dec 2024 00:09:19 -0800 Subject: [PATCH] openapi-internal: optionally change TargetAssetID on upload --- openapi-internal.yaml | 5 +++ pkg/internal/oas_client_gen.go | 21 ++++++++++++ pkg/internal/oas_handlers_gen.go | 4 +++ pkg/internal/oas_parameters_gen.go | 54 +++++++++++++++++++++++++++++- pkg/internal/oas_schemas_gen.go | 46 +++++++++++++++++++++++++ 5 files changed, 129 insertions(+), 1 deletion(-) diff --git a/openapi-internal.yaml b/openapi-internal.yaml index 86d3d29..2b3d45e 100644 --- a/openapi-internal.yaml +++ b/openapi-internal.yaml @@ -32,6 +32,11 @@ paths: - Submissions parameters: - $ref: '#/components/parameters/SubmissionID' + - name: TargetAssetID + in: query + schema: + type: integer + format: int64 responses: "204": description: Successful response diff --git a/pkg/internal/oas_client_gen.go b/pkg/internal/oas_client_gen.go index ee2c470..50ffab4 100644 --- a/pkg/internal/oas_client_gen.go +++ b/pkg/internal/oas_client_gen.go @@ -255,6 +255,27 @@ func (c *Client) sendActionSubmissionUploaded(ctx context.Context, params Action pathParts[2] = "/status/validator-uploaded" uri.AddPathParts(u, pathParts[:]...) + stage = "EncodeQueryParams" + q := uri.NewQueryEncoder() + { + // Encode "TargetAssetID" parameter. + cfg := uri.QueryParameterEncodingConfig{ + Name: "TargetAssetID", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.EncodeParam(cfg, func(e uri.Encoder) error { + if val, ok := params.TargetAssetID.Get(); ok { + return e.EncodeValue(conv.Int64ToString(val)) + } + return nil + }); err != nil { + return res, errors.Wrap(err, "encode query") + } + } + u.RawQuery = q.Values().Encode() + stage = "EncodeRequest" r, err := ht.NewRequest(ctx, "POST", u) if err != nil { diff --git a/pkg/internal/oas_handlers_gen.go b/pkg/internal/oas_handlers_gen.go index 514fb6c..375a08d 100644 --- a/pkg/internal/oas_handlers_gen.go +++ b/pkg/internal/oas_handlers_gen.go @@ -277,6 +277,10 @@ func (s *Server) handleActionSubmissionUploadedRequest(args [1]string, argsEscap Name: "SubmissionID", In: "path", }: params.SubmissionID, + { + Name: "TargetAssetID", + In: "query", + }: params.TargetAssetID, }, Raw: r, } diff --git a/pkg/internal/oas_parameters_gen.go b/pkg/internal/oas_parameters_gen.go index 52a65ca..b3aa388 100644 --- a/pkg/internal/oas_parameters_gen.go +++ b/pkg/internal/oas_parameters_gen.go @@ -84,7 +84,8 @@ func decodeActionSubmissionReleasedParams(args [1]string, argsEscaped bool, r *h // ActionSubmissionUploadedParams is parameters of actionSubmissionUploaded operation. type ActionSubmissionUploadedParams struct { // The unique identifier for a submission. - SubmissionID int64 + SubmissionID int64 + TargetAssetID OptInt64 } func unpackActionSubmissionUploadedParams(packed middleware.Parameters) (params ActionSubmissionUploadedParams) { @@ -95,10 +96,20 @@ func unpackActionSubmissionUploadedParams(packed middleware.Parameters) (params } params.SubmissionID = packed[key].(int64) } + { + key := middleware.ParameterKey{ + Name: "TargetAssetID", + In: "query", + } + if v, ok := packed[key]; ok { + params.TargetAssetID = v.(OptInt64) + } + } return params } func decodeActionSubmissionUploadedParams(args [1]string, argsEscaped bool, r *http.Request) (params ActionSubmissionUploadedParams, _ error) { + q := uri.NewQueryDecoder(r.URL.Query()) // Decode path: SubmissionID. if err := func() error { param := args[0] @@ -144,6 +155,47 @@ func decodeActionSubmissionUploadedParams(args [1]string, argsEscaped bool, r *h Err: err, } } + // Decode query: TargetAssetID. + if err := func() error { + cfg := uri.QueryParameterDecodingConfig{ + Name: "TargetAssetID", + Style: uri.QueryStyleForm, + Explode: true, + } + + if err := q.HasParam(cfg); err == nil { + if err := q.DecodeParam(cfg, func(d uri.Decoder) error { + var paramsDotTargetAssetIDVal int64 + if err := func() error { + val, err := d.DecodeValue() + if err != nil { + return err + } + + c, err := conv.ToInt64(val) + if err != nil { + return err + } + + paramsDotTargetAssetIDVal = c + return nil + }(); err != nil { + return err + } + params.TargetAssetID.SetTo(paramsDotTargetAssetIDVal) + return nil + }); err != nil { + return err + } + } + return nil + }(); err != nil { + return params, &ogenerrors.DecodeParamError{ + Name: "TargetAssetID", + In: "query", + Err: err, + } + } return params, nil } diff --git a/pkg/internal/oas_schemas_gen.go b/pkg/internal/oas_schemas_gen.go index e17044b..319dfb2 100644 --- a/pkg/internal/oas_schemas_gen.go +++ b/pkg/internal/oas_schemas_gen.go @@ -71,3 +71,49 @@ func (s *ErrorStatusCode) SetStatusCode(val int) { func (s *ErrorStatusCode) SetResponse(val Error) { s.Response = val } + +// NewOptInt64 returns new OptInt64 with value set to v. +func NewOptInt64(v int64) OptInt64 { + return OptInt64{ + Value: v, + Set: true, + } +} + +// OptInt64 is optional int64. +type OptInt64 struct { + Value int64 + Set bool +} + +// IsSet returns true if OptInt64 was set. +func (o OptInt64) IsSet() bool { return o.Set } + +// Reset unsets value. +func (o *OptInt64) Reset() { + var v int64 + o.Value = v + o.Set = false +} + +// SetTo sets value to v. +func (o *OptInt64) SetTo(v int64) { + o.Set = true + o.Value = v +} + +// Get returns value and boolean that denotes whether value was set. +func (o OptInt64) Get() (v int64, 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 OptInt64) Or(d int64) int64 { + if v, ok := o.Get(); ok { + return v + } + return d +}