From 0c2ee16bdee124f2dc5a20e385e8678cf5e2b5f0 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 5 Dec 2024 18:48:26 -0800 Subject: [PATCH] openapi: not optional --- openapi.yaml | 5 + pkg/api/oas_client_gen.go | 30 ++-- pkg/api/oas_handlers_gen.go | 10 +- pkg/api/oas_json_gen.go | 165 -------------------- pkg/api/oas_request_decoders_gen.go | 70 +++------ pkg/api/oas_request_encoders_gen.go | 50 ++---- pkg/api/oas_schemas_gen.go | 230 ---------------------------- pkg/api/oas_server_gen.go | 10 +- pkg/api/oas_unimplemented_gen.go | 10 +- pkg/service/script_policy.go | 4 +- pkg/service/scripts.go | 4 +- pkg/service/submissions.go | 14 +- 12 files changed, 81 insertions(+), 521 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index 77aedf6..860c295 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -53,6 +53,7 @@ paths: tags: - Submissions requestBody: + required: true content: application/json: schema: @@ -335,6 +336,7 @@ paths: tags: - ScriptPolicy requestBody: + required: true content: application/json: schema: @@ -416,6 +418,7 @@ paths: type: integer format: int64 requestBody: + required: true content: application/json: schema: @@ -457,6 +460,7 @@ paths: tags: - Scripts requestBody: + required: true content: application/json: schema: @@ -513,6 +517,7 @@ paths: type: integer format: int64 requestBody: + required: true content: application/json: schema: diff --git a/pkg/api/oas_client_gen.go b/pkg/api/oas_client_gen.go index a9df2dd..e2aa484 100644 --- a/pkg/api/oas_client_gen.go +++ b/pkg/api/oas_client_gen.go @@ -77,19 +77,19 @@ type Invoker interface { // Create a new script. // // POST /scripts - CreateScript(ctx context.Context, request OptScriptCreate) (*ID, error) + CreateScript(ctx context.Context, request *ScriptCreate) (*ID, error) // CreateScriptPolicy invokes createScriptPolicy operation. // // Create a new script policy. // // POST /script-policy - CreateScriptPolicy(ctx context.Context, request OptScriptPolicyCreate) (*ID, error) + CreateScriptPolicy(ctx context.Context, request *ScriptPolicyCreate) (*ID, error) // CreateSubmission invokes createSubmission operation. // // Create new submission. // // POST /submissions - CreateSubmission(ctx context.Context, request OptSubmissionCreate) (*ID, error) + CreateSubmission(ctx context.Context, request *SubmissionCreate) (*ID, error) // DeleteScript invokes deleteScript operation. // // Delete the specified script by ID. @@ -149,13 +149,13 @@ type Invoker interface { // Update the specified script by ID. // // PATCH /scripts/{ScriptID} - UpdateScript(ctx context.Context, request OptScriptUpdate, params UpdateScriptParams) error + UpdateScript(ctx context.Context, request *ScriptUpdate, params UpdateScriptParams) error // UpdateScriptPolicy invokes updateScriptPolicy operation. // // Update the specified script policy by ID. // // PATCH /script-policy/id/{ScriptPolicyID} - UpdateScriptPolicy(ctx context.Context, request OptScriptPolicyUpdate, params UpdateScriptPolicyParams) error + UpdateScriptPolicy(ctx context.Context, request *ScriptPolicyUpdate, params UpdateScriptPolicyParams) error } // Client implements OAS client. @@ -1209,12 +1209,12 @@ func (c *Client) sendActionSubmissionValidate(ctx context.Context, params Action // Create a new script. // // POST /scripts -func (c *Client) CreateScript(ctx context.Context, request OptScriptCreate) (*ID, error) { +func (c *Client) CreateScript(ctx context.Context, request *ScriptCreate) (*ID, error) { res, err := c.sendCreateScript(ctx, request) return res, err } -func (c *Client) sendCreateScript(ctx context.Context, request OptScriptCreate) (res *ID, err error) { +func (c *Client) sendCreateScript(ctx context.Context, request *ScriptCreate) (res *ID, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createScript"), semconv.HTTPRequestMethodKey.String("POST"), @@ -1317,12 +1317,12 @@ func (c *Client) sendCreateScript(ctx context.Context, request OptScriptCreate) // Create a new script policy. // // POST /script-policy -func (c *Client) CreateScriptPolicy(ctx context.Context, request OptScriptPolicyCreate) (*ID, error) { +func (c *Client) CreateScriptPolicy(ctx context.Context, request *ScriptPolicyCreate) (*ID, error) { res, err := c.sendCreateScriptPolicy(ctx, request) return res, err } -func (c *Client) sendCreateScriptPolicy(ctx context.Context, request OptScriptPolicyCreate) (res *ID, err error) { +func (c *Client) sendCreateScriptPolicy(ctx context.Context, request *ScriptPolicyCreate) (res *ID, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createScriptPolicy"), semconv.HTTPRequestMethodKey.String("POST"), @@ -1425,12 +1425,12 @@ func (c *Client) sendCreateScriptPolicy(ctx context.Context, request OptScriptPo // Create new submission. // // POST /submissions -func (c *Client) CreateSubmission(ctx context.Context, request OptSubmissionCreate) (*ID, error) { +func (c *Client) CreateSubmission(ctx context.Context, request *SubmissionCreate) (*ID, error) { res, err := c.sendCreateSubmission(ctx, request) return res, err } -func (c *Client) sendCreateSubmission(ctx context.Context, request OptSubmissionCreate) (res *ID, err error) { +func (c *Client) sendCreateSubmission(ctx context.Context, request *SubmissionCreate) (res *ID, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("createSubmission"), semconv.HTTPRequestMethodKey.String("POST"), @@ -2691,12 +2691,12 @@ func (c *Client) sendPatchSubmissionModel(ctx context.Context, params PatchSubmi // Update the specified script by ID. // // PATCH /scripts/{ScriptID} -func (c *Client) UpdateScript(ctx context.Context, request OptScriptUpdate, params UpdateScriptParams) error { +func (c *Client) UpdateScript(ctx context.Context, request *ScriptUpdate, params UpdateScriptParams) error { _, err := c.sendUpdateScript(ctx, request, params) return err } -func (c *Client) sendUpdateScript(ctx context.Context, request OptScriptUpdate, params UpdateScriptParams) (res *UpdateScriptOK, err error) { +func (c *Client) sendUpdateScript(ctx context.Context, request *ScriptUpdate, params UpdateScriptParams) (res *UpdateScriptOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("updateScript"), semconv.HTTPRequestMethodKey.String("PATCH"), @@ -2817,12 +2817,12 @@ func (c *Client) sendUpdateScript(ctx context.Context, request OptScriptUpdate, // Update the specified script policy by ID. // // PATCH /script-policy/id/{ScriptPolicyID} -func (c *Client) UpdateScriptPolicy(ctx context.Context, request OptScriptPolicyUpdate, params UpdateScriptPolicyParams) error { +func (c *Client) UpdateScriptPolicy(ctx context.Context, request *ScriptPolicyUpdate, params UpdateScriptPolicyParams) error { _, err := c.sendUpdateScriptPolicy(ctx, request, params) return err } -func (c *Client) sendUpdateScriptPolicy(ctx context.Context, request OptScriptPolicyUpdate, params UpdateScriptPolicyParams) (res *UpdateScriptPolicyOK, err error) { +func (c *Client) sendUpdateScriptPolicy(ctx context.Context, request *ScriptPolicyUpdate, params UpdateScriptPolicyParams) (res *UpdateScriptPolicyOK, err error) { otelAttrs := []attribute.KeyValue{ otelogen.OperationID("updateScriptPolicy"), semconv.HTTPRequestMethodKey.String("PATCH"), diff --git a/pkg/api/oas_handlers_gen.go b/pkg/api/oas_handlers_gen.go index 760ced5..fa230ee 100644 --- a/pkg/api/oas_handlers_gen.go +++ b/pkg/api/oas_handlers_gen.go @@ -1739,7 +1739,7 @@ func (s *Server) handleCreateScriptRequest(args [0]string, argsEscaped bool, w h } type ( - Request = OptScriptCreate + Request = *ScriptCreate Params = struct{} Response = *ID ) @@ -1934,7 +1934,7 @@ func (s *Server) handleCreateScriptPolicyRequest(args [0]string, argsEscaped boo } type ( - Request = OptScriptPolicyCreate + Request = *ScriptPolicyCreate Params = struct{} Response = *ID ) @@ -2129,7 +2129,7 @@ func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool, } type ( - Request = OptSubmissionCreate + Request = *SubmissionCreate Params = struct{} Response = *ID ) @@ -4106,7 +4106,7 @@ func (s *Server) handleUpdateScriptRequest(args [1]string, argsEscaped bool, w h } type ( - Request = OptScriptUpdate + Request = *ScriptUpdate Params = UpdateScriptParams Response = *UpdateScriptOK ) @@ -4316,7 +4316,7 @@ func (s *Server) handleUpdateScriptPolicyRequest(args [1]string, argsEscaped boo } type ( - Request = OptScriptPolicyUpdate + Request = *ScriptPolicyUpdate Params = UpdateScriptPolicyParams Response = *UpdateScriptPolicyOK ) diff --git a/pkg/api/oas_json_gen.go b/pkg/api/oas_json_gen.go index 4b8cf80..b020d9d 100644 --- a/pkg/api/oas_json_gen.go +++ b/pkg/api/oas_json_gen.go @@ -291,138 +291,6 @@ func (s *OptInt64) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes ScriptCreate as json. -func (o OptScriptCreate) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes ScriptCreate from json. -func (o *OptScriptCreate) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptScriptCreate to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptScriptCreate) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptScriptCreate) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ScriptPolicyCreate as json. -func (o OptScriptPolicyCreate) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes ScriptPolicyCreate from json. -func (o *OptScriptPolicyCreate) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptScriptPolicyCreate to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptScriptPolicyCreate) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptScriptPolicyCreate) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ScriptPolicyUpdate as json. -func (o OptScriptPolicyUpdate) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes ScriptPolicyUpdate from json. -func (o *OptScriptPolicyUpdate) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptScriptPolicyUpdate to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptScriptPolicyUpdate) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptScriptPolicyUpdate) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - -// Encode encodes ScriptUpdate as json. -func (o OptScriptUpdate) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes ScriptUpdate from json. -func (o *OptScriptUpdate) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptScriptUpdate to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptScriptUpdate) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptScriptUpdate) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode encodes string as json. func (o OptString) Encode(e *jx.Encoder) { if !o.Set { @@ -458,39 +326,6 @@ func (s *OptString) UnmarshalJSON(data []byte) error { return s.Decode(d) } -// Encode encodes SubmissionCreate as json. -func (o OptSubmissionCreate) Encode(e *jx.Encoder) { - if !o.Set { - return - } - o.Value.Encode(e) -} - -// Decode decodes SubmissionCreate from json. -func (o *OptSubmissionCreate) Decode(d *jx.Decoder) error { - if o == nil { - return errors.New("invalid: unable to decode OptSubmissionCreate to nil") - } - o.Set = true - if err := o.Value.Decode(d); err != nil { - return err - } - return nil -} - -// MarshalJSON implements stdjson.Marshaler. -func (s OptSubmissionCreate) MarshalJSON() ([]byte, error) { - e := jx.Encoder{} - s.Encode(&e) - return e.Bytes(), nil -} - -// UnmarshalJSON implements stdjson.Unmarshaler. -func (s *OptSubmissionCreate) UnmarshalJSON(data []byte) error { - d := jx.DecodeBytes(data) - return s.Decode(d) -} - // Encode implements json.Marshaler. func (s *Script) Encode(e *jx.Encoder) { e.ObjStart() diff --git a/pkg/api/oas_request_decoders_gen.go b/pkg/api/oas_request_decoders_gen.go index e558b87..d2af233 100644 --- a/pkg/api/oas_request_decoders_gen.go +++ b/pkg/api/oas_request_decoders_gen.go @@ -16,7 +16,7 @@ import ( ) func (s *Server) decodeCreateScriptRequest(r *http.Request) ( - req OptScriptCreate, + req *ScriptCreate, close func() error, rerr error, ) { @@ -35,9 +35,6 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) ( 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") @@ -45,7 +42,7 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) ( switch { case ct == "application/json": if r.ContentLength == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } buf, err := io.ReadAll(r.Body) if err != nil { @@ -53,14 +50,13 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) ( } if len(buf) == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } d := jx.DecodeBytes(buf) - var request OptScriptCreate + var request ScriptCreate if err := func() error { - request.Reset() if err := request.Decode(d); err != nil { return err } @@ -76,14 +72,14 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) ( } return req, close, err } - return request, close, nil + return &request, close, nil default: return req, close, validate.InvalidContentType(ct) } } func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) ( - req OptScriptPolicyCreate, + req *ScriptPolicyCreate, close func() error, rerr error, ) { @@ -102,9 +98,6 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) ( 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") @@ -112,7 +105,7 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) ( switch { case ct == "application/json": if r.ContentLength == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } buf, err := io.ReadAll(r.Body) if err != nil { @@ -120,14 +113,13 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) ( } if len(buf) == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } d := jx.DecodeBytes(buf) - var request OptScriptPolicyCreate + var request ScriptPolicyCreate if err := func() error { - request.Reset() if err := request.Decode(d); err != nil { return err } @@ -143,14 +135,14 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) ( } return req, close, err } - return request, close, nil + return &request, close, nil default: return req, close, validate.InvalidContentType(ct) } } func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( - req OptSubmissionCreate, + req *SubmissionCreate, close func() error, rerr error, ) { @@ -169,9 +161,6 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( 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") @@ -179,7 +168,7 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( switch { case ct == "application/json": if r.ContentLength == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } buf, err := io.ReadAll(r.Body) if err != nil { @@ -187,14 +176,13 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( } if len(buf) == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } d := jx.DecodeBytes(buf) - var request OptSubmissionCreate + var request SubmissionCreate if err := func() error { - request.Reset() if err := request.Decode(d); err != nil { return err } @@ -210,14 +198,14 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( } return req, close, err } - return request, close, nil + return &request, close, nil default: return req, close, validate.InvalidContentType(ct) } } func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( - req OptScriptUpdate, + req *ScriptUpdate, close func() error, rerr error, ) { @@ -236,9 +224,6 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( 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") @@ -246,7 +231,7 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( switch { case ct == "application/json": if r.ContentLength == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } buf, err := io.ReadAll(r.Body) if err != nil { @@ -254,14 +239,13 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( } if len(buf) == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } d := jx.DecodeBytes(buf) - var request OptScriptUpdate + var request ScriptUpdate if err := func() error { - request.Reset() if err := request.Decode(d); err != nil { return err } @@ -277,14 +261,14 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( } return req, close, err } - return request, close, nil + return &request, close, nil default: return req, close, validate.InvalidContentType(ct) } } func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) ( - req OptScriptPolicyUpdate, + req *ScriptPolicyUpdate, close func() error, rerr error, ) { @@ -303,9 +287,6 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) ( 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") @@ -313,7 +294,7 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) ( switch { case ct == "application/json": if r.ContentLength == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } buf, err := io.ReadAll(r.Body) if err != nil { @@ -321,14 +302,13 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) ( } if len(buf) == 0 { - return req, close, nil + return req, close, validate.ErrBodyRequired } d := jx.DecodeBytes(buf) - var request OptScriptPolicyUpdate + var request ScriptPolicyUpdate if err := func() error { - request.Reset() if err := request.Decode(d); err != nil { return err } @@ -344,7 +324,7 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) ( } return req, close, err } - return request, close, nil + return &request, close, nil default: return req, close, validate.InvalidContentType(ct) } diff --git a/pkg/api/oas_request_encoders_gen.go b/pkg/api/oas_request_encoders_gen.go index 11b0fae..237b177 100644 --- a/pkg/api/oas_request_encoders_gen.go +++ b/pkg/api/oas_request_encoders_gen.go @@ -12,19 +12,13 @@ import ( ) func encodeCreateScriptRequest( - req OptScriptCreate, + req *ScriptCreate, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { - req.Encode(e) - } + req.Encode(e) } encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) @@ -32,19 +26,13 @@ func encodeCreateScriptRequest( } func encodeCreateScriptPolicyRequest( - req OptScriptPolicyCreate, + req *ScriptPolicyCreate, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { - req.Encode(e) - } + req.Encode(e) } encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) @@ -52,19 +40,13 @@ func encodeCreateScriptPolicyRequest( } func encodeCreateSubmissionRequest( - req OptSubmissionCreate, + req *SubmissionCreate, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { - req.Encode(e) - } + req.Encode(e) } encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) @@ -72,19 +54,13 @@ func encodeCreateSubmissionRequest( } func encodeUpdateScriptRequest( - req OptScriptUpdate, + req *ScriptUpdate, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { - req.Encode(e) - } + req.Encode(e) } encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) @@ -92,19 +68,13 @@ func encodeUpdateScriptRequest( } func encodeUpdateScriptPolicyRequest( - req OptScriptPolicyUpdate, + req *ScriptPolicyUpdate, r *http.Request, ) error { const contentType = "application/json" - if !req.Set { - // Keep request with empty body if value is not set. - return nil - } e := new(jx.Encoder) { - if req.Set { - req.Encode(e) - } + req.Encode(e) } encoded := e.Bytes() ht.SetBody(r, bytes.NewReader(encoded), contentType) diff --git a/pkg/api/oas_schemas_gen.go b/pkg/api/oas_schemas_gen.go index 9fe955c..17d2d0e 100644 --- a/pkg/api/oas_schemas_gen.go +++ b/pkg/api/oas_schemas_gen.go @@ -214,190 +214,6 @@ func (o OptInt64) Or(d int64) int64 { return d } -// NewOptScriptCreate returns new OptScriptCreate with value set to v. -func NewOptScriptCreate(v ScriptCreate) OptScriptCreate { - return OptScriptCreate{ - Value: v, - Set: true, - } -} - -// OptScriptCreate is optional ScriptCreate. -type OptScriptCreate struct { - Value ScriptCreate - Set bool -} - -// IsSet returns true if OptScriptCreate was set. -func (o OptScriptCreate) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptScriptCreate) Reset() { - var v ScriptCreate - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptScriptCreate) SetTo(v ScriptCreate) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptScriptCreate) Get() (v ScriptCreate, 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 OptScriptCreate) Or(d ScriptCreate) ScriptCreate { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptScriptPolicyCreate returns new OptScriptPolicyCreate with value set to v. -func NewOptScriptPolicyCreate(v ScriptPolicyCreate) OptScriptPolicyCreate { - return OptScriptPolicyCreate{ - Value: v, - Set: true, - } -} - -// OptScriptPolicyCreate is optional ScriptPolicyCreate. -type OptScriptPolicyCreate struct { - Value ScriptPolicyCreate - Set bool -} - -// IsSet returns true if OptScriptPolicyCreate was set. -func (o OptScriptPolicyCreate) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptScriptPolicyCreate) Reset() { - var v ScriptPolicyCreate - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptScriptPolicyCreate) SetTo(v ScriptPolicyCreate) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptScriptPolicyCreate) Get() (v ScriptPolicyCreate, 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 OptScriptPolicyCreate) Or(d ScriptPolicyCreate) ScriptPolicyCreate { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptScriptPolicyUpdate returns new OptScriptPolicyUpdate with value set to v. -func NewOptScriptPolicyUpdate(v ScriptPolicyUpdate) OptScriptPolicyUpdate { - return OptScriptPolicyUpdate{ - Value: v, - Set: true, - } -} - -// OptScriptPolicyUpdate is optional ScriptPolicyUpdate. -type OptScriptPolicyUpdate struct { - Value ScriptPolicyUpdate - Set bool -} - -// IsSet returns true if OptScriptPolicyUpdate was set. -func (o OptScriptPolicyUpdate) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptScriptPolicyUpdate) Reset() { - var v ScriptPolicyUpdate - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptScriptPolicyUpdate) SetTo(v ScriptPolicyUpdate) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptScriptPolicyUpdate) Get() (v ScriptPolicyUpdate, 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 OptScriptPolicyUpdate) Or(d ScriptPolicyUpdate) ScriptPolicyUpdate { - if v, ok := o.Get(); ok { - return v - } - return d -} - -// NewOptScriptUpdate returns new OptScriptUpdate with value set to v. -func NewOptScriptUpdate(v ScriptUpdate) OptScriptUpdate { - return OptScriptUpdate{ - Value: v, - Set: true, - } -} - -// OptScriptUpdate is optional ScriptUpdate. -type OptScriptUpdate struct { - Value ScriptUpdate - Set bool -} - -// IsSet returns true if OptScriptUpdate was set. -func (o OptScriptUpdate) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptScriptUpdate) Reset() { - var v ScriptUpdate - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptScriptUpdate) SetTo(v ScriptUpdate) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptScriptUpdate) Get() (v ScriptUpdate, 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 OptScriptUpdate) Or(d ScriptUpdate) ScriptUpdate { - 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{ @@ -444,52 +260,6 @@ func (o OptString) Or(d string) string { return d } -// NewOptSubmissionCreate returns new OptSubmissionCreate with value set to v. -func NewOptSubmissionCreate(v SubmissionCreate) OptSubmissionCreate { - return OptSubmissionCreate{ - Value: v, - Set: true, - } -} - -// OptSubmissionCreate is optional SubmissionCreate. -type OptSubmissionCreate struct { - Value SubmissionCreate - Set bool -} - -// IsSet returns true if OptSubmissionCreate was set. -func (o OptSubmissionCreate) IsSet() bool { return o.Set } - -// Reset unsets value. -func (o *OptSubmissionCreate) Reset() { - var v SubmissionCreate - o.Value = v - o.Set = false -} - -// SetTo sets value to v. -func (o *OptSubmissionCreate) SetTo(v SubmissionCreate) { - o.Set = true - o.Value = v -} - -// Get returns value and boolean that denotes whether value was set. -func (o OptSubmissionCreate) Get() (v SubmissionCreate, 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 OptSubmissionCreate) Or(d SubmissionCreate) SubmissionCreate { - if v, ok := o.Get(); ok { - return v - } - return d -} - // NewOptSubmissionFilter returns new OptSubmissionFilter with value set to v. func NewOptSubmissionFilter(v SubmissionFilter) OptSubmissionFilter { return OptSubmissionFilter{ diff --git a/pkg/api/oas_server_gen.go b/pkg/api/oas_server_gen.go index 1b5afa3..3059322 100644 --- a/pkg/api/oas_server_gen.go +++ b/pkg/api/oas_server_gen.go @@ -61,19 +61,19 @@ type Handler interface { // Create a new script. // // POST /scripts - CreateScript(ctx context.Context, req OptScriptCreate) (*ID, error) + CreateScript(ctx context.Context, req *ScriptCreate) (*ID, error) // CreateScriptPolicy implements createScriptPolicy operation. // // Create a new script policy. // // POST /script-policy - CreateScriptPolicy(ctx context.Context, req OptScriptPolicyCreate) (*ID, error) + CreateScriptPolicy(ctx context.Context, req *ScriptPolicyCreate) (*ID, error) // CreateSubmission implements createSubmission operation. // // Create new submission. // // POST /submissions - CreateSubmission(ctx context.Context, req OptSubmissionCreate) (*ID, error) + CreateSubmission(ctx context.Context, req *SubmissionCreate) (*ID, error) // DeleteScript implements deleteScript operation. // // Delete the specified script by ID. @@ -133,13 +133,13 @@ type Handler interface { // Update the specified script by ID. // // PATCH /scripts/{ScriptID} - UpdateScript(ctx context.Context, req OptScriptUpdate, params UpdateScriptParams) error + UpdateScript(ctx context.Context, req *ScriptUpdate, params UpdateScriptParams) error // UpdateScriptPolicy implements updateScriptPolicy operation. // // Update the specified script policy by ID. // // PATCH /script-policy/id/{ScriptPolicyID} - UpdateScriptPolicy(ctx context.Context, req OptScriptPolicyUpdate, params UpdateScriptPolicyParams) error + UpdateScriptPolicy(ctx context.Context, req *ScriptPolicyUpdate, params UpdateScriptPolicyParams) error // NewError creates *ErrorStatusCode from error returned by handler. // // Used for common default response. diff --git a/pkg/api/oas_unimplemented_gen.go b/pkg/api/oas_unimplemented_gen.go index 94afd3e..817408a 100644 --- a/pkg/api/oas_unimplemented_gen.go +++ b/pkg/api/oas_unimplemented_gen.go @@ -90,7 +90,7 @@ func (UnimplementedHandler) ActionSubmissionValidate(ctx context.Context, params // Create a new script. // // POST /scripts -func (UnimplementedHandler) CreateScript(ctx context.Context, req OptScriptCreate) (r *ID, _ error) { +func (UnimplementedHandler) CreateScript(ctx context.Context, req *ScriptCreate) (r *ID, _ error) { return r, ht.ErrNotImplemented } @@ -99,7 +99,7 @@ func (UnimplementedHandler) CreateScript(ctx context.Context, req OptScriptCreat // Create a new script policy. // // POST /script-policy -func (UnimplementedHandler) CreateScriptPolicy(ctx context.Context, req OptScriptPolicyCreate) (r *ID, _ error) { +func (UnimplementedHandler) CreateScriptPolicy(ctx context.Context, req *ScriptPolicyCreate) (r *ID, _ error) { return r, ht.ErrNotImplemented } @@ -108,7 +108,7 @@ func (UnimplementedHandler) CreateScriptPolicy(ctx context.Context, req OptScrip // Create new submission. // // POST /submissions -func (UnimplementedHandler) CreateSubmission(ctx context.Context, req OptSubmissionCreate) (r *ID, _ error) { +func (UnimplementedHandler) CreateSubmission(ctx context.Context, req *SubmissionCreate) (r *ID, _ error) { return r, ht.ErrNotImplemented } @@ -198,7 +198,7 @@ func (UnimplementedHandler) PatchSubmissionModel(ctx context.Context, params Pat // Update the specified script by ID. // // PATCH /scripts/{ScriptID} -func (UnimplementedHandler) UpdateScript(ctx context.Context, req OptScriptUpdate, params UpdateScriptParams) error { +func (UnimplementedHandler) UpdateScript(ctx context.Context, req *ScriptUpdate, params UpdateScriptParams) error { return ht.ErrNotImplemented } @@ -207,7 +207,7 @@ func (UnimplementedHandler) UpdateScript(ctx context.Context, req OptScriptUpdat // Update the specified script policy by ID. // // PATCH /script-policy/id/{ScriptPolicyID} -func (UnimplementedHandler) UpdateScriptPolicy(ctx context.Context, req OptScriptPolicyUpdate, params UpdateScriptPolicyParams) error { +func (UnimplementedHandler) UpdateScriptPolicy(ctx context.Context, req *ScriptPolicyUpdate, params UpdateScriptPolicyParams) error { return ht.ErrNotImplemented } diff --git a/pkg/service/script_policy.go b/pkg/service/script_policy.go index 5b3e4e5..8b7ad6a 100644 --- a/pkg/service/script_policy.go +++ b/pkg/service/script_policy.go @@ -13,7 +13,7 @@ var ( // Create a new script policy. // // POST /script-policy -func (svc *Service) CreateScriptPolicy(ctx context.Context, req api.OptScriptPolicyCreate) (*api.ID, error){ +func (svc *Service) CreateScriptPolicy(ctx context.Context, req *api.ScriptPolicyCreate) (*api.ID, error){ return nil,nil } // DeleteScriptPolicy implements deleteScriptPolicy operation. @@ -45,6 +45,6 @@ func (svc *Service) GetScriptPolicyFromHash(ctx context.Context, params api.GetS // Update the specified script policy by ID. // // PATCH /script-policy/id/{ScriptPolicyID} -func (svc *Service) UpdateScriptPolicy(ctx context.Context, req api.OptScriptPolicyUpdate, params api.UpdateScriptPolicyParams) error{ +func (svc *Service) UpdateScriptPolicy(ctx context.Context, req *api.ScriptPolicyUpdate, params api.UpdateScriptPolicyParams) error{ return nil } diff --git a/pkg/service/scripts.go b/pkg/service/scripts.go index 33df013..b353002 100644 --- a/pkg/service/scripts.go +++ b/pkg/service/scripts.go @@ -13,7 +13,7 @@ var ( // Create a new script. // // POST /scripts -func (svc *Service) CreateScript(ctx context.Context, req api.OptScriptCreate) (*api.ID, error){ +func (svc *Service) CreateScript(ctx context.Context, req *api.ScriptCreate) (*api.ID, error){ return nil,nil } // DeleteScript implements deleteScript operation. @@ -37,6 +37,6 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) ( // Update the specified script by ID. // // PATCH /scripts/{ScriptID} -func (svc *Service) UpdateScript(ctx context.Context, req api.OptScriptUpdate, params api.UpdateScriptParams) error{ +func (svc *Service) UpdateScript(ctx context.Context, req *api.ScriptUpdate, params api.UpdateScriptParams) error{ return nil } diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index 366f310..8e99f99 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -15,7 +15,7 @@ var ( ) // POST /submissions -func (svc *Service) CreateSubmission(ctx context.Context, request api.OptSubmissionCreate) (*api.ID, error) { +func (svc *Service) CreateSubmission(ctx context.Context, request *api.SubmissionCreate) (*api.ID, error) { userInfo, ok := ctx.Value("UserInfo").(*UserInfo) if !ok{ return nil, ErrUserInfo @@ -23,15 +23,15 @@ func (svc *Service) CreateSubmission(ctx context.Context, request api.OptSubmiss submission, err := svc.DB.Submissions().Create(ctx, model.Submission{ ID: 0, - DisplayName: request.Value.DisplayName, - Creator: request.Value.Creator, - GameID: request.Value.GameID, + DisplayName: request.DisplayName, + Creator: request.Creator, + GameID: request.GameID, Date: time.Now(), Submitter: int64(userInfo.UserID), - AssetID: request.Value.AssetID, - AssetVersion: request.Value.AssetVersion, + AssetID: request.AssetID, + AssetVersion: request.AssetVersion, Completed: false, - TargetAssetID: request.Value.TargetAssetID.Value, + TargetAssetID: request.TargetAssetID.Value, StatusID: model.StatusUnderConstruction, }) if err != nil{