openapi: not optional

This commit is contained in:
Quaternions 2024-12-05 18:48:26 -08:00
parent 005f2ddaee
commit 0c2ee16bde
12 changed files with 81 additions and 521 deletions

View File

@ -53,6 +53,7 @@ paths:
tags: tags:
- Submissions - Submissions
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:
@ -335,6 +336,7 @@ paths:
tags: tags:
- ScriptPolicy - ScriptPolicy
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:
@ -416,6 +418,7 @@ paths:
type: integer type: integer
format: int64 format: int64
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:
@ -457,6 +460,7 @@ paths:
tags: tags:
- Scripts - Scripts
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:
@ -513,6 +517,7 @@ paths:
type: integer type: integer
format: int64 format: int64
requestBody: requestBody:
required: true
content: content:
application/json: application/json:
schema: schema:

View File

@ -77,19 +77,19 @@ type Invoker interface {
// Create a new script. // Create a new script.
// //
// POST /scripts // POST /scripts
CreateScript(ctx context.Context, request OptScriptCreate) (*ID, error) CreateScript(ctx context.Context, request *ScriptCreate) (*ID, error)
// CreateScriptPolicy invokes createScriptPolicy operation. // CreateScriptPolicy invokes createScriptPolicy operation.
// //
// Create a new script policy. // Create a new script policy.
// //
// POST /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. // CreateSubmission invokes createSubmission operation.
// //
// Create new submission. // Create new submission.
// //
// POST /submissions // POST /submissions
CreateSubmission(ctx context.Context, request OptSubmissionCreate) (*ID, error) CreateSubmission(ctx context.Context, request *SubmissionCreate) (*ID, error)
// DeleteScript invokes deleteScript operation. // DeleteScript invokes deleteScript operation.
// //
// Delete the specified script by ID. // Delete the specified script by ID.
@ -149,13 +149,13 @@ type Invoker interface {
// Update the specified script by ID. // Update the specified script by ID.
// //
// PATCH /scripts/{ScriptID} // 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. // UpdateScriptPolicy invokes updateScriptPolicy operation.
// //
// Update the specified script policy by ID. // Update the specified script policy by ID.
// //
// PATCH /script-policy/id/{ScriptPolicyID} // 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. // Client implements OAS client.
@ -1209,12 +1209,12 @@ func (c *Client) sendActionSubmissionValidate(ctx context.Context, params Action
// Create a new script. // Create a new script.
// //
// POST /scripts // 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) res, err := c.sendCreateScript(ctx, request)
return res, err 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{ otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createScript"), otelogen.OperationID("createScript"),
semconv.HTTPRequestMethodKey.String("POST"), semconv.HTTPRequestMethodKey.String("POST"),
@ -1317,12 +1317,12 @@ func (c *Client) sendCreateScript(ctx context.Context, request OptScriptCreate)
// Create a new script policy. // Create a new script policy.
// //
// POST /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) res, err := c.sendCreateScriptPolicy(ctx, request)
return res, err 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{ otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createScriptPolicy"), otelogen.OperationID("createScriptPolicy"),
semconv.HTTPRequestMethodKey.String("POST"), semconv.HTTPRequestMethodKey.String("POST"),
@ -1425,12 +1425,12 @@ func (c *Client) sendCreateScriptPolicy(ctx context.Context, request OptScriptPo
// Create new submission. // Create new submission.
// //
// POST /submissions // 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) res, err := c.sendCreateSubmission(ctx, request)
return res, err 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{ otelAttrs := []attribute.KeyValue{
otelogen.OperationID("createSubmission"), otelogen.OperationID("createSubmission"),
semconv.HTTPRequestMethodKey.String("POST"), semconv.HTTPRequestMethodKey.String("POST"),
@ -2691,12 +2691,12 @@ func (c *Client) sendPatchSubmissionModel(ctx context.Context, params PatchSubmi
// Update the specified script by ID. // Update the specified script by ID.
// //
// PATCH /scripts/{ScriptID} // 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) _, err := c.sendUpdateScript(ctx, request, params)
return err 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{ otelAttrs := []attribute.KeyValue{
otelogen.OperationID("updateScript"), otelogen.OperationID("updateScript"),
semconv.HTTPRequestMethodKey.String("PATCH"), semconv.HTTPRequestMethodKey.String("PATCH"),
@ -2817,12 +2817,12 @@ func (c *Client) sendUpdateScript(ctx context.Context, request OptScriptUpdate,
// Update the specified script policy by ID. // Update the specified script policy by ID.
// //
// PATCH /script-policy/id/{ScriptPolicyID} // 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) _, err := c.sendUpdateScriptPolicy(ctx, request, params)
return err 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{ otelAttrs := []attribute.KeyValue{
otelogen.OperationID("updateScriptPolicy"), otelogen.OperationID("updateScriptPolicy"),
semconv.HTTPRequestMethodKey.String("PATCH"), semconv.HTTPRequestMethodKey.String("PATCH"),

View File

@ -1739,7 +1739,7 @@ func (s *Server) handleCreateScriptRequest(args [0]string, argsEscaped bool, w h
} }
type ( type (
Request = OptScriptCreate Request = *ScriptCreate
Params = struct{} Params = struct{}
Response = *ID Response = *ID
) )
@ -1934,7 +1934,7 @@ func (s *Server) handleCreateScriptPolicyRequest(args [0]string, argsEscaped boo
} }
type ( type (
Request = OptScriptPolicyCreate Request = *ScriptPolicyCreate
Params = struct{} Params = struct{}
Response = *ID Response = *ID
) )
@ -2129,7 +2129,7 @@ func (s *Server) handleCreateSubmissionRequest(args [0]string, argsEscaped bool,
} }
type ( type (
Request = OptSubmissionCreate Request = *SubmissionCreate
Params = struct{} Params = struct{}
Response = *ID Response = *ID
) )
@ -4106,7 +4106,7 @@ func (s *Server) handleUpdateScriptRequest(args [1]string, argsEscaped bool, w h
} }
type ( type (
Request = OptScriptUpdate Request = *ScriptUpdate
Params = UpdateScriptParams Params = UpdateScriptParams
Response = *UpdateScriptOK Response = *UpdateScriptOK
) )
@ -4316,7 +4316,7 @@ func (s *Server) handleUpdateScriptPolicyRequest(args [1]string, argsEscaped boo
} }
type ( type (
Request = OptScriptPolicyUpdate Request = *ScriptPolicyUpdate
Params = UpdateScriptPolicyParams Params = UpdateScriptPolicyParams
Response = *UpdateScriptPolicyOK Response = *UpdateScriptPolicyOK
) )

View File

@ -291,138 +291,6 @@ func (s *OptInt64) UnmarshalJSON(data []byte) error {
return s.Decode(d) 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. // Encode encodes string as json.
func (o OptString) Encode(e *jx.Encoder) { func (o OptString) Encode(e *jx.Encoder) {
if !o.Set { if !o.Set {
@ -458,39 +326,6 @@ func (s *OptString) UnmarshalJSON(data []byte) error {
return s.Decode(d) 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. // Encode implements json.Marshaler.
func (s *Script) Encode(e *jx.Encoder) { func (s *Script) Encode(e *jx.Encoder) {
e.ObjStart() e.ObjStart()

View File

@ -16,7 +16,7 @@ import (
) )
func (s *Server) decodeCreateScriptRequest(r *http.Request) ( func (s *Server) decodeCreateScriptRequest(r *http.Request) (
req OptScriptCreate, req *ScriptCreate,
close func() error, close func() error,
rerr error, rerr error,
) { ) {
@ -35,9 +35,6 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) (
rerr = multierr.Append(rerr, close()) 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")) ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil { if err != nil {
return req, close, errors.Wrap(err, "parse media type") return req, close, errors.Wrap(err, "parse media type")
@ -45,7 +42,7 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) (
switch { switch {
case ct == "application/json": case ct == "application/json":
if r.ContentLength == 0 { if r.ContentLength == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
buf, err := io.ReadAll(r.Body) buf, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
@ -53,14 +50,13 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) (
} }
if len(buf) == 0 { if len(buf) == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var request OptScriptCreate var request ScriptCreate
if err := func() error { if err := func() error {
request.Reset()
if err := request.Decode(d); err != nil { if err := request.Decode(d); err != nil {
return err return err
} }
@ -76,14 +72,14 @@ func (s *Server) decodeCreateScriptRequest(r *http.Request) (
} }
return req, close, err return req, close, err
} }
return request, close, nil return &request, close, nil
default: default:
return req, close, validate.InvalidContentType(ct) return req, close, validate.InvalidContentType(ct)
} }
} }
func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) ( func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
req OptScriptPolicyCreate, req *ScriptPolicyCreate,
close func() error, close func() error,
rerr error, rerr error,
) { ) {
@ -102,9 +98,6 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
rerr = multierr.Append(rerr, close()) 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")) ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil { if err != nil {
return req, close, errors.Wrap(err, "parse media type") return req, close, errors.Wrap(err, "parse media type")
@ -112,7 +105,7 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
switch { switch {
case ct == "application/json": case ct == "application/json":
if r.ContentLength == 0 { if r.ContentLength == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
buf, err := io.ReadAll(r.Body) buf, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
@ -120,14 +113,13 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
} }
if len(buf) == 0 { if len(buf) == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var request OptScriptPolicyCreate var request ScriptPolicyCreate
if err := func() error { if err := func() error {
request.Reset()
if err := request.Decode(d); err != nil { if err := request.Decode(d); err != nil {
return err return err
} }
@ -143,14 +135,14 @@ func (s *Server) decodeCreateScriptPolicyRequest(r *http.Request) (
} }
return req, close, err return req, close, err
} }
return request, close, nil return &request, close, nil
default: default:
return req, close, validate.InvalidContentType(ct) return req, close, validate.InvalidContentType(ct)
} }
} }
func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
req OptSubmissionCreate, req *SubmissionCreate,
close func() error, close func() error,
rerr error, rerr error,
) { ) {
@ -169,9 +161,6 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
rerr = multierr.Append(rerr, close()) 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")) ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil { if err != nil {
return req, close, errors.Wrap(err, "parse media type") return req, close, errors.Wrap(err, "parse media type")
@ -179,7 +168,7 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
switch { switch {
case ct == "application/json": case ct == "application/json":
if r.ContentLength == 0 { if r.ContentLength == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
buf, err := io.ReadAll(r.Body) buf, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
@ -187,14 +176,13 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
} }
if len(buf) == 0 { if len(buf) == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var request OptSubmissionCreate var request SubmissionCreate
if err := func() error { if err := func() error {
request.Reset()
if err := request.Decode(d); err != nil { if err := request.Decode(d); err != nil {
return err return err
} }
@ -210,14 +198,14 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) (
} }
return req, close, err return req, close, err
} }
return request, close, nil return &request, close, nil
default: default:
return req, close, validate.InvalidContentType(ct) return req, close, validate.InvalidContentType(ct)
} }
} }
func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( func (s *Server) decodeUpdateScriptRequest(r *http.Request) (
req OptScriptUpdate, req *ScriptUpdate,
close func() error, close func() error,
rerr error, rerr error,
) { ) {
@ -236,9 +224,6 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) (
rerr = multierr.Append(rerr, close()) 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")) ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil { if err != nil {
return req, close, errors.Wrap(err, "parse media type") return req, close, errors.Wrap(err, "parse media type")
@ -246,7 +231,7 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) (
switch { switch {
case ct == "application/json": case ct == "application/json":
if r.ContentLength == 0 { if r.ContentLength == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
buf, err := io.ReadAll(r.Body) buf, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
@ -254,14 +239,13 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) (
} }
if len(buf) == 0 { if len(buf) == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var request OptScriptUpdate var request ScriptUpdate
if err := func() error { if err := func() error {
request.Reset()
if err := request.Decode(d); err != nil { if err := request.Decode(d); err != nil {
return err return err
} }
@ -277,14 +261,14 @@ func (s *Server) decodeUpdateScriptRequest(r *http.Request) (
} }
return req, close, err return req, close, err
} }
return request, close, nil return &request, close, nil
default: default:
return req, close, validate.InvalidContentType(ct) return req, close, validate.InvalidContentType(ct)
} }
} }
func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) ( func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) (
req OptScriptPolicyUpdate, req *ScriptPolicyUpdate,
close func() error, close func() error,
rerr error, rerr error,
) { ) {
@ -303,9 +287,6 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) (
rerr = multierr.Append(rerr, close()) 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")) ct, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil { if err != nil {
return req, close, errors.Wrap(err, "parse media type") return req, close, errors.Wrap(err, "parse media type")
@ -313,7 +294,7 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) (
switch { switch {
case ct == "application/json": case ct == "application/json":
if r.ContentLength == 0 { if r.ContentLength == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
buf, err := io.ReadAll(r.Body) buf, err := io.ReadAll(r.Body)
if err != nil { if err != nil {
@ -321,14 +302,13 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) (
} }
if len(buf) == 0 { if len(buf) == 0 {
return req, close, nil return req, close, validate.ErrBodyRequired
} }
d := jx.DecodeBytes(buf) d := jx.DecodeBytes(buf)
var request OptScriptPolicyUpdate var request ScriptPolicyUpdate
if err := func() error { if err := func() error {
request.Reset()
if err := request.Decode(d); err != nil { if err := request.Decode(d); err != nil {
return err return err
} }
@ -344,7 +324,7 @@ func (s *Server) decodeUpdateScriptPolicyRequest(r *http.Request) (
} }
return req, close, err return req, close, err
} }
return request, close, nil return &request, close, nil
default: default:
return req, close, validate.InvalidContentType(ct) return req, close, validate.InvalidContentType(ct)
} }

View File

@ -12,100 +12,70 @@ import (
) )
func encodeCreateScriptRequest( func encodeCreateScriptRequest(
req OptScriptCreate, req *ScriptCreate,
r *http.Request, r *http.Request,
) error { ) error {
const contentType = "application/json" const contentType = "application/json"
if !req.Set {
// Keep request with empty body if value is not set.
return nil
}
e := new(jx.Encoder) e := new(jx.Encoder)
{ {
if req.Set {
req.Encode(e) req.Encode(e)
} }
}
encoded := e.Bytes() encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType) ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil return nil
} }
func encodeCreateScriptPolicyRequest( func encodeCreateScriptPolicyRequest(
req OptScriptPolicyCreate, req *ScriptPolicyCreate,
r *http.Request, r *http.Request,
) error { ) error {
const contentType = "application/json" const contentType = "application/json"
if !req.Set {
// Keep request with empty body if value is not set.
return nil
}
e := new(jx.Encoder) e := new(jx.Encoder)
{ {
if req.Set {
req.Encode(e) req.Encode(e)
} }
}
encoded := e.Bytes() encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType) ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil return nil
} }
func encodeCreateSubmissionRequest( func encodeCreateSubmissionRequest(
req OptSubmissionCreate, req *SubmissionCreate,
r *http.Request, r *http.Request,
) error { ) error {
const contentType = "application/json" const contentType = "application/json"
if !req.Set {
// Keep request with empty body if value is not set.
return nil
}
e := new(jx.Encoder) e := new(jx.Encoder)
{ {
if req.Set {
req.Encode(e) req.Encode(e)
} }
}
encoded := e.Bytes() encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType) ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil return nil
} }
func encodeUpdateScriptRequest( func encodeUpdateScriptRequest(
req OptScriptUpdate, req *ScriptUpdate,
r *http.Request, r *http.Request,
) error { ) error {
const contentType = "application/json" const contentType = "application/json"
if !req.Set {
// Keep request with empty body if value is not set.
return nil
}
e := new(jx.Encoder) e := new(jx.Encoder)
{ {
if req.Set {
req.Encode(e) req.Encode(e)
} }
}
encoded := e.Bytes() encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType) ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil return nil
} }
func encodeUpdateScriptPolicyRequest( func encodeUpdateScriptPolicyRequest(
req OptScriptPolicyUpdate, req *ScriptPolicyUpdate,
r *http.Request, r *http.Request,
) error { ) error {
const contentType = "application/json" const contentType = "application/json"
if !req.Set {
// Keep request with empty body if value is not set.
return nil
}
e := new(jx.Encoder) e := new(jx.Encoder)
{ {
if req.Set {
req.Encode(e) req.Encode(e)
} }
}
encoded := e.Bytes() encoded := e.Bytes()
ht.SetBody(r, bytes.NewReader(encoded), contentType) ht.SetBody(r, bytes.NewReader(encoded), contentType)
return nil return nil

View File

@ -214,190 +214,6 @@ func (o OptInt64) Or(d int64) int64 {
return d 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. // NewOptString returns new OptString with value set to v.
func NewOptString(v string) OptString { func NewOptString(v string) OptString {
return OptString{ return OptString{
@ -444,52 +260,6 @@ func (o OptString) Or(d string) string {
return d 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. // NewOptSubmissionFilter returns new OptSubmissionFilter with value set to v.
func NewOptSubmissionFilter(v SubmissionFilter) OptSubmissionFilter { func NewOptSubmissionFilter(v SubmissionFilter) OptSubmissionFilter {
return OptSubmissionFilter{ return OptSubmissionFilter{

View File

@ -61,19 +61,19 @@ type Handler interface {
// Create a new script. // Create a new script.
// //
// POST /scripts // POST /scripts
CreateScript(ctx context.Context, req OptScriptCreate) (*ID, error) CreateScript(ctx context.Context, req *ScriptCreate) (*ID, error)
// CreateScriptPolicy implements createScriptPolicy operation. // CreateScriptPolicy implements createScriptPolicy operation.
// //
// Create a new script policy. // Create a new script policy.
// //
// POST /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. // CreateSubmission implements createSubmission operation.
// //
// Create new submission. // Create new submission.
// //
// POST /submissions // POST /submissions
CreateSubmission(ctx context.Context, req OptSubmissionCreate) (*ID, error) CreateSubmission(ctx context.Context, req *SubmissionCreate) (*ID, error)
// DeleteScript implements deleteScript operation. // DeleteScript implements deleteScript operation.
// //
// Delete the specified script by ID. // Delete the specified script by ID.
@ -133,13 +133,13 @@ type Handler interface {
// Update the specified script by ID. // Update the specified script by ID.
// //
// PATCH /scripts/{ScriptID} // 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. // UpdateScriptPolicy implements updateScriptPolicy operation.
// //
// Update the specified script policy by ID. // Update the specified script policy by ID.
// //
// PATCH /script-policy/id/{ScriptPolicyID} // 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. // NewError creates *ErrorStatusCode from error returned by handler.
// //
// Used for common default response. // Used for common default response.

View File

@ -90,7 +90,7 @@ func (UnimplementedHandler) ActionSubmissionValidate(ctx context.Context, params
// Create a new script. // Create a new script.
// //
// POST /scripts // 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 return r, ht.ErrNotImplemented
} }
@ -99,7 +99,7 @@ func (UnimplementedHandler) CreateScript(ctx context.Context, req OptScriptCreat
// Create a new script policy. // Create a new script policy.
// //
// POST /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 return r, ht.ErrNotImplemented
} }
@ -108,7 +108,7 @@ func (UnimplementedHandler) CreateScriptPolicy(ctx context.Context, req OptScrip
// Create new submission. // Create new submission.
// //
// POST /submissions // 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 return r, ht.ErrNotImplemented
} }
@ -198,7 +198,7 @@ func (UnimplementedHandler) PatchSubmissionModel(ctx context.Context, params Pat
// Update the specified script by ID. // Update the specified script by ID.
// //
// PATCH /scripts/{ScriptID} // 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 return ht.ErrNotImplemented
} }
@ -207,7 +207,7 @@ func (UnimplementedHandler) UpdateScript(ctx context.Context, req OptScriptUpdat
// Update the specified script policy by ID. // Update the specified script policy by ID.
// //
// PATCH /script-policy/id/{ScriptPolicyID} // 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 return ht.ErrNotImplemented
} }

View File

@ -13,7 +13,7 @@ var (
// Create a new script policy. // Create a new script policy.
// //
// POST /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 return nil,nil
} }
// DeleteScriptPolicy implements deleteScriptPolicy operation. // 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. // Update the specified script policy by ID.
// //
// PATCH /script-policy/id/{ScriptPolicyID} // 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 return nil
} }

View File

@ -13,7 +13,7 @@ var (
// Create a new script. // Create a new script.
// //
// POST /scripts // 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 return nil,nil
} }
// DeleteScript implements deleteScript operation. // DeleteScript implements deleteScript operation.
@ -37,6 +37,6 @@ func (svc *Service) GetScript(ctx context.Context, params api.GetScriptParams) (
// Update the specified script by ID. // Update the specified script by ID.
// //
// PATCH /scripts/{ScriptID} // 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 return nil
} }

View File

@ -15,7 +15,7 @@ var (
) )
// POST /submissions // 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) userInfo, ok := ctx.Value("UserInfo").(*UserInfo)
if !ok{ if !ok{
return nil, ErrUserInfo 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{ submission, err := svc.DB.Submissions().Create(ctx, model.Submission{
ID: 0, ID: 0,
DisplayName: request.Value.DisplayName, DisplayName: request.DisplayName,
Creator: request.Value.Creator, Creator: request.Creator,
GameID: request.Value.GameID, GameID: request.GameID,
Date: time.Now(), Date: time.Now(),
Submitter: int64(userInfo.UserID), Submitter: int64(userInfo.UserID),
AssetID: request.Value.AssetID, AssetID: request.AssetID,
AssetVersion: request.Value.AssetVersion, AssetVersion: request.AssetVersion,
Completed: false, Completed: false,
TargetAssetID: request.Value.TargetAssetID.Value, TargetAssetID: request.TargetAssetID.Value,
StatusID: model.StatusUnderConstruction, StatusID: model.StatusUnderConstruction,
}) })
if err != nil{ if err != nil{