From 0794e7ba467dc55dd7b0e0f5312270f95bc8a326 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 30 Dec 2024 19:15:16 -0800 Subject: [PATCH] openapi: generate --- pkg/api/oas_client_gen.go | 114 ++ pkg/api/oas_handlers_gen.go | 195 ++++ pkg/api/oas_json_gen.go | 114 ++ pkg/api/oas_operations_gen.go | 1 + pkg/api/oas_request_decoders_gen.go | 87 ++ pkg/api/oas_request_encoders_gen.go | 18 + pkg/api/oas_response_decoders_gen.go | 51 + pkg/api/oas_response_encoders_gen.go | 7 + pkg/api/oas_router_gen.go | 1444 ++++++++++++++------------ pkg/api/oas_schemas_gen.go | 30 + pkg/api/oas_server_gen.go | 6 + pkg/api/oas_unimplemented_gen.go | 9 + pkg/service/submissions.go | 9 + 13 files changed, 1401 insertions(+), 684 deletions(-) diff --git a/pkg/api/oas_client_gen.go b/pkg/api/oas_client_gen.go index 7df265d..b3cd9e6 100644 --- a/pkg/api/oas_client_gen.go +++ b/pkg/api/oas_client_gen.go @@ -126,6 +126,12 @@ type Invoker interface { // // GET /submissions ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error) + // ReleaseSubmissions invokes releaseSubmissions operation. + // + // Release a set of uploaded maps. + // + // POST /release-submissions + ReleaseSubmissions(ctx context.Context, request []ReleaseInfo) error // SetSubmissionCompleted invokes setSubmissionCompleted operation. // // Retrieve map with ID. @@ -2470,6 +2476,114 @@ func (c *Client) sendListSubmissions(ctx context.Context, params ListSubmissions return result, nil } +// ReleaseSubmissions invokes releaseSubmissions operation. +// +// Release a set of uploaded maps. +// +// POST /release-submissions +func (c *Client) ReleaseSubmissions(ctx context.Context, request []ReleaseInfo) error { + _, err := c.sendReleaseSubmissions(ctx, request) + return err +} + +func (c *Client) sendReleaseSubmissions(ctx context.Context, request []ReleaseInfo) (res *ReleaseSubmissionsCreated, err error) { + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("releaseSubmissions"), + semconv.HTTPRequestMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/release-submissions"), + } + + // Run stopwatch. + startTime := time.Now() + defer func() { + // Use floating point division here for higher precision (instead of Millisecond method). + elapsedDuration := time.Since(startTime) + c.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), metric.WithAttributes(otelAttrs...)) + }() + + // Increment request counter. + c.requests.Add(ctx, 1, metric.WithAttributes(otelAttrs...)) + + // Start a span for this request. + ctx, span := c.cfg.Tracer.Start(ctx, ReleaseSubmissionsOperation, + 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, metric.WithAttributes(otelAttrs...)) + } + span.End() + }() + + stage = "BuildURL" + u := uri.Clone(c.requestURL(ctx)) + var pathParts [1]string + pathParts[0] = "/release-submissions" + 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 := encodeReleaseSubmissionsRequest(request, r); err != nil { + return res, errors.Wrap(err, "encode request") + } + + { + type bitset = [1]uint8 + var satisfied bitset + { + stage = "Security:CookieAuth" + switch err := c.securityCookieAuth(ctx, ReleaseSubmissionsOperation, r); { + case err == nil: // if NO error + satisfied[0] |= 1 << 0 + case errors.Is(err, ogenerrors.ErrSkipClientSecurity): + // Skip this security. + default: + return res, errors.Wrap(err, "security \"CookieAuth\"") + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + return res, ogenerrors.ErrSecurityRequirementIsNotSatisfied + } + } + + 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 := decodeReleaseSubmissionsResponse(resp) + if err != nil { + return res, errors.Wrap(err, "decode response") + } + + return result, nil +} + // SetSubmissionCompleted invokes setSubmissionCompleted operation. // // Retrieve map with ID. diff --git a/pkg/api/oas_handlers_gen.go b/pkg/api/oas_handlers_gen.go index 7b89376..e8041f9 100644 --- a/pkg/api/oas_handlers_gen.go +++ b/pkg/api/oas_handlers_gen.go @@ -3397,6 +3397,201 @@ func (s *Server) handleListSubmissionsRequest(args [0]string, argsEscaped bool, } } +// handleReleaseSubmissionsRequest handles releaseSubmissions operation. +// +// Release a set of uploaded maps. +// +// POST /release-submissions +func (s *Server) handleReleaseSubmissionsRequest(args [0]string, argsEscaped bool, w http.ResponseWriter, r *http.Request) { + statusWriter := &codeRecorder{ResponseWriter: w} + w = statusWriter + otelAttrs := []attribute.KeyValue{ + otelogen.OperationID("releaseSubmissions"), + semconv.HTTPRequestMethodKey.String("POST"), + semconv.HTTPRouteKey.String("/release-submissions"), + } + + // Start a span for this request. + ctx, span := s.cfg.Tracer.Start(r.Context(), ReleaseSubmissionsOperation, + trace.WithAttributes(otelAttrs...), + serverSpanKind, + ) + defer span.End() + + // Add Labeler to context. + labeler := &Labeler{attrs: otelAttrs} + ctx = contextWithLabeler(ctx, labeler) + + // Run stopwatch. + startTime := time.Now() + defer func() { + elapsedDuration := time.Since(startTime) + + attrSet := labeler.AttributeSet() + attrs := attrSet.ToSlice() + code := statusWriter.status + if code != 0 { + codeAttr := semconv.HTTPResponseStatusCode(code) + attrs = append(attrs, codeAttr) + span.SetAttributes(codeAttr) + } + attrOpt := metric.WithAttributes(attrs...) + + // Increment request counter. + s.requests.Add(ctx, 1, attrOpt) + + // Use floating point division here for higher precision (instead of Millisecond method). + s.duration.Record(ctx, float64(elapsedDuration)/float64(time.Millisecond), attrOpt) + }() + + var ( + recordError = func(stage string, err error) { + span.RecordError(err) + + // https://opentelemetry.io/docs/specs/semconv/http/http-spans/#status + // Span Status MUST be left unset if HTTP status code was in the 1xx, 2xx or 3xx ranges, + // unless there was another error (e.g., network error receiving the response body; or 3xx codes with + // max redirects exceeded), in which case status MUST be set to Error. + code := statusWriter.status + if code >= 100 && code < 500 { + span.SetStatus(codes.Error, stage) + } + + attrSet := labeler.AttributeSet() + attrs := attrSet.ToSlice() + if code != 0 { + attrs = append(attrs, semconv.HTTPResponseStatusCode(code)) + } + + s.errors.Add(ctx, 1, metric.WithAttributes(attrs...)) + } + err error + opErrContext = ogenerrors.OperationContext{ + Name: ReleaseSubmissionsOperation, + ID: "releaseSubmissions", + } + ) + { + type bitset = [1]uint8 + var satisfied bitset + { + sctx, ok, err := s.securityCookieAuth(ctx, ReleaseSubmissionsOperation, r) + if err != nil { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Security: "CookieAuth", + Err: err, + } + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + defer recordError("Security:CookieAuth", err) + } + return + } + if ok { + satisfied[0] |= 1 << 0 + ctx = sctx + } + } + + if ok := func() bool { + nextRequirement: + for _, requirement := range []bitset{ + {0b00000001}, + } { + for i, mask := range requirement { + if satisfied[i]&mask != mask { + continue nextRequirement + } + } + return true + } + return false + }(); !ok { + err = &ogenerrors.SecurityError{ + OperationContext: opErrContext, + Err: ogenerrors.ErrSecurityRequirementIsNotSatisfied, + } + if encodeErr := encodeErrorResponse(s.h.NewError(ctx, err), w, span); encodeErr != nil { + defer recordError("Security", err) + } + return + } + } + request, close, err := s.decodeReleaseSubmissionsRequest(r) + if err != nil { + err = &ogenerrors.DecodeRequestError{ + OperationContext: opErrContext, + Err: err, + } + defer recordError("DecodeRequest", err) + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + defer func() { + if err := close(); err != nil { + recordError("CloseRequest", err) + } + }() + + var response *ReleaseSubmissionsCreated + if m := s.cfg.Middleware; m != nil { + mreq := middleware.Request{ + Context: ctx, + OperationName: ReleaseSubmissionsOperation, + OperationSummary: "Release a set of uploaded maps", + OperationID: "releaseSubmissions", + Body: request, + Params: middleware.Parameters{}, + Raw: r, + } + + type ( + Request = []ReleaseInfo + Params = struct{} + Response = *ReleaseSubmissionsCreated + ) + 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.ReleaseSubmissions(ctx, request) + return response, err + }, + ) + } else { + err = s.h.ReleaseSubmissions(ctx, request) + } + if err != nil { + if errRes, ok := errors.Into[*ErrorStatusCode](err); ok { + if err := encodeErrorResponse(errRes, w, span); err != nil { + defer recordError("Internal", err) + } + return + } + if errors.Is(err, ht.ErrNotImplemented) { + s.cfg.ErrorHandler(ctx, w, r, err) + return + } + if err := encodeErrorResponse(s.h.NewError(ctx, err), w, span); err != nil { + defer recordError("Internal", err) + } + return + } + + if err := encodeReleaseSubmissionsResponse(response, w, span); err != nil { + defer recordError("EncodeResponse", err) + if !errors.Is(err, ht.ErrInternalServerErrorResponse) { + s.cfg.ErrorHandler(ctx, w, r, err) + } + return + } +} + // handleSetSubmissionCompletedRequest handles setSubmissionCompleted operation. // // Retrieve map with ID. diff --git a/pkg/api/oas_json_gen.go b/pkg/api/oas_json_gen.go index e9330f4..4abaa1e 100644 --- a/pkg/api/oas_json_gen.go +++ b/pkg/api/oas_json_gen.go @@ -9,6 +9,7 @@ import ( "github.com/go-faster/errors" "github.com/go-faster/jx" + "github.com/ogen-go/ogen/json" "github.com/ogen-go/ogen/validate" ) @@ -326,6 +327,119 @@ func (s *OptString) UnmarshalJSON(data []byte) error { return s.Decode(d) } +// Encode implements json.Marshaler. +func (s *ReleaseInfo) Encode(e *jx.Encoder) { + e.ObjStart() + s.encodeFields(e) + e.ObjEnd() +} + +// encodeFields encodes fields. +func (s *ReleaseInfo) encodeFields(e *jx.Encoder) { + { + e.FieldStart("SubmissionID") + e.Int64(s.SubmissionID) + } + { + e.FieldStart("Date") + json.EncodeDateTime(e, s.Date) + } +} + +var jsonFieldsNameOfReleaseInfo = [2]string{ + 0: "SubmissionID", + 1: "Date", +} + +// Decode decodes ReleaseInfo from json. +func (s *ReleaseInfo) Decode(d *jx.Decoder) error { + if s == nil { + return errors.New("invalid: unable to decode ReleaseInfo to nil") + } + var requiredBitSet [1]uint8 + + if err := d.ObjBytes(func(d *jx.Decoder, k []byte) error { + switch string(k) { + case "SubmissionID": + requiredBitSet[0] |= 1 << 0 + if err := func() error { + v, err := d.Int64() + s.SubmissionID = int64(v) + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"SubmissionID\"") + } + case "Date": + requiredBitSet[0] |= 1 << 1 + if err := func() error { + v, err := json.DecodeDateTime(d) + s.Date = v + if err != nil { + return err + } + return nil + }(); err != nil { + return errors.Wrap(err, "decode field \"Date\"") + } + default: + return d.Skip() + } + return nil + }); err != nil { + return errors.Wrap(err, "decode ReleaseInfo") + } + // Validate required fields. + var failures []validate.FieldError + for i, mask := range [1]uint8{ + 0b00000011, + } { + 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(jsonFieldsNameOfReleaseInfo) { + name = jsonFieldsNameOfReleaseInfo[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 +} + +// MarshalJSON implements stdjson.Marshaler. +func (s *ReleaseInfo) MarshalJSON() ([]byte, error) { + e := jx.Encoder{} + s.Encode(&e) + return e.Bytes(), nil +} + +// UnmarshalJSON implements stdjson.Unmarshaler. +func (s *ReleaseInfo) 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_operations_gen.go b/pkg/api/oas_operations_gen.go index 4b63be0..cd2b6f6 100644 --- a/pkg/api/oas_operations_gen.go +++ b/pkg/api/oas_operations_gen.go @@ -23,6 +23,7 @@ const ( ListScriptPolicyOperation OperationName = "ListScriptPolicy" ListScriptsOperation OperationName = "ListScripts" ListSubmissionsOperation OperationName = "ListSubmissions" + ReleaseSubmissionsOperation OperationName = "ReleaseSubmissions" SetSubmissionCompletedOperation OperationName = "SetSubmissionCompleted" UpdateScriptOperation OperationName = "UpdateScript" UpdateScriptPolicyOperation OperationName = "UpdateScriptPolicy" diff --git a/pkg/api/oas_request_decoders_gen.go b/pkg/api/oas_request_decoders_gen.go index ab831ed..21dcbd8 100644 --- a/pkg/api/oas_request_decoders_gen.go +++ b/pkg/api/oas_request_decoders_gen.go @@ -220,6 +220,93 @@ func (s *Server) decodeCreateSubmissionRequest(r *http.Request) ( } } +func (s *Server) decodeReleaseSubmissionsRequest(r *http.Request) ( + req []ReleaseInfo, + 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 == "application/json": + if r.ContentLength == 0 { + return req, close, validate.ErrBodyRequired + } + buf, err := io.ReadAll(r.Body) + if err != nil { + return req, close, err + } + + if len(buf) == 0 { + return req, close, validate.ErrBodyRequired + } + + d := jx.DecodeBytes(buf) + + var request []ReleaseInfo + if err := func() error { + request = make([]ReleaseInfo, 0) + if err := d.Arr(func(d *jx.Decoder) error { + var elem ReleaseInfo + if err := elem.Decode(d); err != nil { + return err + } + request = append(request, elem) + return nil + }); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return req, close, err + } + if err := func() error { + if request == nil { + return errors.New("nil is invalid value") + } + if err := (validate.Array{ + MinLength: 1, + MinLengthSet: true, + MaxLength: 255, + MaxLengthSet: true, + }).ValidateLength(len(request)); err != nil { + return errors.Wrap(err, "array") + } + return nil + }(); err != nil { + return req, close, errors.Wrap(err, "validate") + } + return request, close, nil + default: + return req, close, validate.InvalidContentType(ct) + } +} + func (s *Server) decodeUpdateScriptRequest(r *http.Request) ( req *ScriptUpdate, close func() error, diff --git a/pkg/api/oas_request_encoders_gen.go b/pkg/api/oas_request_encoders_gen.go index 237b177..3a0ac47 100644 --- a/pkg/api/oas_request_encoders_gen.go +++ b/pkg/api/oas_request_encoders_gen.go @@ -53,6 +53,24 @@ func encodeCreateSubmissionRequest( return nil } +func encodeReleaseSubmissionsRequest( + req []ReleaseInfo, + r *http.Request, +) error { + const contentType = "application/json" + e := new(jx.Encoder) + { + e.ArrStart() + for _, elem := range req { + elem.Encode(e) + } + e.ArrEnd() + } + encoded := e.Bytes() + ht.SetBody(r, bytes.NewReader(encoded), contentType) + return nil +} + func encodeUpdateScriptRequest( req *ScriptUpdate, r *http.Request, diff --git a/pkg/api/oas_response_decoders_gen.go b/pkg/api/oas_response_decoders_gen.go index eb652d4..a14c1a6 100644 --- a/pkg/api/oas_response_decoders_gen.go +++ b/pkg/api/oas_response_decoders_gen.go @@ -1299,6 +1299,57 @@ func decodeListSubmissionsResponse(resp *http.Response) (res []Submission, _ err return res, errors.Wrap(defRes, "error") } +func decodeReleaseSubmissionsResponse(resp *http.Response) (res *ReleaseSubmissionsCreated, _ error) { + switch resp.StatusCode { + case 201: + // Code 201. + return &ReleaseSubmissionsCreated{}, nil + } + // Convenient error response. + defRes, err := func() (res *ErrorStatusCode, err error) { + ct, _, err := mime.ParseMediaType(resp.Header.Get("Content-Type")) + if err != nil { + return res, errors.Wrap(err, "parse media type") + } + switch { + case ct == "application/json": + buf, err := io.ReadAll(resp.Body) + if err != nil { + return res, err + } + d := jx.DecodeBytes(buf) + + var response Error + if err := func() error { + if err := response.Decode(d); err != nil { + return err + } + if err := d.Skip(); err != io.EOF { + return errors.New("unexpected trailing data") + } + return nil + }(); err != nil { + err = &ogenerrors.DecodeBodyError{ + ContentType: ct, + Body: buf, + Err: err, + } + return res, err + } + return &ErrorStatusCode{ + StatusCode: resp.StatusCode, + Response: response, + }, nil + default: + return res, validate.InvalidContentType(ct) + } + }() + if err != nil { + return res, errors.Wrapf(err, "default (code %d)", resp.StatusCode) + } + return res, errors.Wrap(defRes, "error") +} + func decodeSetSubmissionCompletedResponse(resp *http.Response) (res *SetSubmissionCompletedNoContent, _ error) { switch resp.StatusCode { case 204: diff --git a/pkg/api/oas_response_encoders_gen.go b/pkg/api/oas_response_encoders_gen.go index 29fa98a..084067e 100644 --- a/pkg/api/oas_response_encoders_gen.go +++ b/pkg/api/oas_response_encoders_gen.go @@ -207,6 +207,13 @@ func encodeListSubmissionsResponse(response []Submission, w http.ResponseWriter, return nil } +func encodeReleaseSubmissionsResponse(response *ReleaseSubmissionsCreated, w http.ResponseWriter, span trace.Span) error { + w.WriteHeader(201) + span.SetStatus(codes.Ok, http.StatusText(201)) + + return nil +} + func encodeSetSubmissionCompletedResponse(response *SetSubmissionCompletedNoContent, w http.ResponseWriter, span trace.Span) error { w.WriteHeader(204) span.SetStatus(codes.Ok, http.StatusText(204)) diff --git a/pkg/api/oas_router_gen.go b/pkg/api/oas_router_gen.go index ac26a08..53dbce3 100644 --- a/pkg/api/oas_router_gen.go +++ b/pkg/api/oas_router_gen.go @@ -49,9 +49,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { break } switch elem[0] { - case '/': // Prefix: "/s" + case '/': // Prefix: "/" origElem := elem - if l := len("/s"); len(elem) >= l && elem[0:l] == "/s" { + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { elem = elem[l:] } else { break @@ -61,187 +61,190 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { break } switch elem[0] { - case 'c': // Prefix: "cript" + case 'r': // Prefix: "release-submissions" origElem := elem - if l := len("cript"); len(elem) >= l && elem[0:l] == "cript" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - break - } - switch elem[0] { - case '-': // Prefix: "-policy" - origElem := elem - if l := len("-policy"); len(elem) >= l && elem[0:l] == "-policy" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - switch r.Method { - case "GET": - s.handleListScriptPolicyRequest([0]string{}, elemIsEscaped, w, r) - case "POST": - s.handleCreateScriptPolicyRequest([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET,POST") - } - - return - } - switch elem[0] { - case '/': // Prefix: "/" - origElem := elem - if l := len("/"); len(elem) >= l && elem[0:l] == "/" { - elem = elem[l:] - } else { - break - } - - // Param: "ScriptPolicyID" - // Leaf parameter - args[0] = elem - elem = "" - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "DELETE": - s.handleDeleteScriptPolicyRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - case "GET": - s.handleGetScriptPolicyRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - case "POST": - s.handleUpdateScriptPolicyRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "DELETE,GET,POST") - } - - return - } - - elem = origElem - } - - elem = origElem - case 's': // Prefix: "s" - origElem := elem - if l := len("s"); len(elem) >= l && elem[0:l] == "s" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - switch r.Method { - case "GET": - s.handleListScriptsRequest([0]string{}, elemIsEscaped, w, r) - case "POST": - s.handleCreateScriptRequest([0]string{}, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "GET,POST") - } - - return - } - switch elem[0] { - case '/': // Prefix: "/" - origElem := elem - if l := len("/"); len(elem) >= l && elem[0:l] == "/" { - elem = elem[l:] - } else { - break - } - - // Param: "ScriptID" - // Leaf parameter - args[0] = elem - elem = "" - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "DELETE": - s.handleDeleteScriptRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - case "GET": - s.handleGetScriptRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - case "POST": - s.handleUpdateScriptRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "DELETE,GET,POST") - } - - return - } - - elem = origElem - } - - elem = origElem - } - - elem = origElem - case 'u': // Prefix: "ubmissions" - origElem := elem - if l := len("ubmissions"); len(elem) >= l && elem[0:l] == "ubmissions" { + if l := len("release-submissions"); len(elem) >= l && elem[0:l] == "release-submissions" { elem = elem[l:] } else { break } if len(elem) == 0 { + // Leaf node. switch r.Method { - case "GET": - s.handleListSubmissionsRequest([0]string{}, elemIsEscaped, w, r) case "POST": - s.handleCreateSubmissionRequest([0]string{}, elemIsEscaped, w, r) + s.handleReleaseSubmissionsRequest([0]string{}, elemIsEscaped, w, r) default: - s.notAllowed(w, r, "GET,POST") + s.notAllowed(w, r, "POST") } return } + + elem = origElem + case 's': // Prefix: "s" + origElem := elem + if l := len("s"); len(elem) >= l && elem[0:l] == "s" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } switch elem[0] { - case '/': // Prefix: "/" + case 'c': // Prefix: "cript" origElem := elem - if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + if l := len("cript"); len(elem) >= l && elem[0:l] == "cript" { elem = elem[l:] } else { break } - // Param: "SubmissionID" - // Match until "/" - idx := strings.IndexByte(elem, '/') - if idx < 0 { - idx = len(elem) + if len(elem) == 0 { + break + } + switch elem[0] { + case '-': // Prefix: "-policy" + origElem := elem + if l := len("-policy"); len(elem) >= l && elem[0:l] == "-policy" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch r.Method { + case "GET": + s.handleListScriptPolicyRequest([0]string{}, elemIsEscaped, w, r) + case "POST": + s.handleCreateScriptPolicyRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET,POST") + } + + return + } + switch elem[0] { + case '/': // Prefix: "/" + origElem := elem + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "ScriptPolicyID" + // Leaf parameter + args[0] = elem + elem = "" + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "DELETE": + s.handleDeleteScriptPolicyRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + case "GET": + s.handleGetScriptPolicyRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + case "POST": + s.handleUpdateScriptPolicyRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "DELETE,GET,POST") + } + + return + } + + elem = origElem + } + + elem = origElem + case 's': // Prefix: "s" + origElem := elem + if l := len("s"); len(elem) >= l && elem[0:l] == "s" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch r.Method { + case "GET": + s.handleListScriptsRequest([0]string{}, elemIsEscaped, w, r) + case "POST": + s.handleCreateScriptRequest([0]string{}, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET,POST") + } + + return + } + switch elem[0] { + case '/': // Prefix: "/" + origElem := elem + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "ScriptID" + // Leaf parameter + args[0] = elem + elem = "" + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "DELETE": + s.handleDeleteScriptRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + case "GET": + s.handleGetScriptRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + case "POST": + s.handleUpdateScriptRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "DELETE,GET,POST") + } + + return + } + + elem = origElem + } + + elem = origElem + } + + elem = origElem + case 'u': // Prefix: "ubmissions" + origElem := elem + if l := len("ubmissions"); len(elem) >= l && elem[0:l] == "ubmissions" { + elem = elem[l:] + } else { + break } - args[0] = elem[:idx] - elem = elem[idx:] if len(elem) == 0 { switch r.Method { case "GET": - s.handleGetSubmissionRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) + s.handleListSubmissionsRequest([0]string{}, elemIsEscaped, w, r) + case "POST": + s.handleCreateSubmissionRequest([0]string{}, elemIsEscaped, w, r) default: - s.notAllowed(w, r, "GET") + s.notAllowed(w, r, "GET,POST") } return @@ -255,59 +258,31 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { break } + // Param: "SubmissionID" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + if len(elem) == 0 { - break + switch r.Method { + case "GET": + s.handleGetSubmissionRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "GET") + } + + return } switch elem[0] { - case 'c': // Prefix: "completed" + case '/': // Prefix: "/" origElem := elem - if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "POST": - s.handleSetSubmissionCompletedRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "POST") - } - - return - } - - elem = origElem - case 'm': // Prefix: "model" - origElem := elem - if l := len("model"); len(elem) >= l && elem[0:l] == "model" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "POST": - s.handleUpdateSubmissionModelRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "POST") - } - - return - } - - elem = origElem - case 's': // Prefix: "status/" - origElem := elem - if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" { + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { elem = elem[l:] } else { break @@ -317,93 +292,9 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { break } switch elem[0] { - case 'r': // Prefix: "re" + case 'c': // Prefix: "completed" origElem := elem - if l := len("re"); len(elem) >= l && elem[0:l] == "re" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - break - } - switch elem[0] { - case 'j': // Prefix: "ject" - origElem := elem - if l := len("ject"); len(elem) >= l && elem[0:l] == "ject" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "POST": - s.handleActionSubmissionRejectRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "POST") - } - - return - } - - elem = origElem - case 'q': // Prefix: "quest-changes" - origElem := elem - if l := len("quest-changes"); len(elem) >= l && elem[0:l] == "quest-changes" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "POST": - s.handleActionSubmissionRequestChangesRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "POST") - } - - return - } - - elem = origElem - case 'v': // Prefix: "voke" - origElem := elem - if l := len("voke"); len(elem) >= l && elem[0:l] == "voke" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "POST": - s.handleActionSubmissionRevokeRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "POST") - } - - return - } - - elem = origElem - } - - elem = origElem - case 's': // Prefix: "submit" - origElem := elem - if l := len("submit"); len(elem) >= l && elem[0:l] == "submit" { + if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" { elem = elem[l:] } else { break @@ -413,7 +304,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Leaf node. switch r.Method { case "POST": - s.handleActionSubmissionSubmitRequest([1]string{ + s.handleSetSubmissionCompletedRequest([1]string{ args[0], }, elemIsEscaped, w, r) default: @@ -424,9 +315,32 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 't': // Prefix: "trigger-" + case 'm': // Prefix: "model" origElem := elem - if l := len("trigger-"); len(elem) >= l && elem[0:l] == "trigger-" { + if l := len("model"); len(elem) >= l && elem[0:l] == "model" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleUpdateSubmissionModelRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + + elem = origElem + case 's': // Prefix: "status/" + origElem := elem + if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" { elem = elem[l:] } else { break @@ -436,9 +350,93 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { break } switch elem[0] { - case 'u': // Prefix: "upload" + case 'r': // Prefix: "re" origElem := elem - if l := len("upload"); len(elem) >= l && elem[0:l] == "upload" { + if l := len("re"); len(elem) >= l && elem[0:l] == "re" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'j': // Prefix: "ject" + origElem := elem + if l := len("ject"); len(elem) >= l && elem[0:l] == "ject" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleActionSubmissionRejectRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + + elem = origElem + case 'q': // Prefix: "quest-changes" + origElem := elem + if l := len("quest-changes"); len(elem) >= l && elem[0:l] == "quest-changes" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleActionSubmissionRequestChangesRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + + elem = origElem + case 'v': // Prefix: "voke" + origElem := elem + if l := len("voke"); len(elem) >= l && elem[0:l] == "voke" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleActionSubmissionRevokeRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + + elem = origElem + } + + elem = origElem + case 's': // Prefix: "submit" + origElem := elem + if l := len("submit"); len(elem) >= l && elem[0:l] == "submit" { elem = elem[l:] } else { break @@ -448,7 +446,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Leaf node. switch r.Method { case "POST": - s.handleActionSubmissionTriggerUploadRequest([1]string{ + s.handleActionSubmissionSubmitRequest([1]string{ args[0], }, elemIsEscaped, w, r) default: @@ -459,26 +457,64 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { } elem = origElem - case 'v': // Prefix: "validate" + case 't': // Prefix: "trigger-" origElem := elem - if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + if l := len("trigger-"); len(elem) >= l && elem[0:l] == "trigger-" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch r.Method { - case "POST": - s.handleActionSubmissionTriggerValidateRequest([1]string{ - args[0], - }, elemIsEscaped, w, r) - default: - s.notAllowed(w, r, "POST") + break + } + switch elem[0] { + case 'u': // Prefix: "upload" + origElem := elem + if l := len("upload"); len(elem) >= l && elem[0:l] == "upload" { + elem = elem[l:] + } else { + break } - return + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleActionSubmissionTriggerUploadRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + + elem = origElem + case 'v': // Prefix: "validate" + origElem := elem + if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch r.Method { + case "POST": + s.handleActionSubmissionTriggerValidateRequest([1]string{ + args[0], + }, elemIsEscaped, w, r) + default: + s.notAllowed(w, r, "POST") + } + + return + } + + elem = origElem } elem = origElem @@ -580,9 +616,9 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { break } switch elem[0] { - case '/': // Prefix: "/s" + case '/': // Prefix: "/" origElem := elem - if l := len("/s"); len(elem) >= l && elem[0:l] == "/s" { + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { elem = elem[l:] } else { break @@ -592,204 +628,22 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { break } switch elem[0] { - case 'c': // Prefix: "cript" + case 'r': // Prefix: "release-submissions" origElem := elem - if l := len("cript"); len(elem) >= l && elem[0:l] == "cript" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - break - } - switch elem[0] { - case '-': // Prefix: "-policy" - origElem := elem - if l := len("-policy"); len(elem) >= l && elem[0:l] == "-policy" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - switch method { - case "GET": - r.name = ListScriptPolicyOperation - r.summary = "Get list of script policies" - r.operationID = "listScriptPolicy" - r.pathPattern = "/script-policy" - r.args = args - r.count = 0 - return r, true - case "POST": - r.name = CreateScriptPolicyOperation - r.summary = "Create a new script policy" - r.operationID = "createScriptPolicy" - r.pathPattern = "/script-policy" - r.args = args - r.count = 0 - return r, true - default: - return - } - } - switch elem[0] { - case '/': // Prefix: "/" - origElem := elem - if l := len("/"); len(elem) >= l && elem[0:l] == "/" { - elem = elem[l:] - } else { - break - } - - // Param: "ScriptPolicyID" - // Leaf parameter - args[0] = elem - elem = "" - - if len(elem) == 0 { - // Leaf node. - switch method { - case "DELETE": - r.name = DeleteScriptPolicyOperation - r.summary = "Delete the specified script policy by ID" - r.operationID = "deleteScriptPolicy" - r.pathPattern = "/script-policy/{ScriptPolicyID}" - r.args = args - r.count = 1 - return r, true - case "GET": - r.name = GetScriptPolicyOperation - r.summary = "Get the specified script policy by ID" - r.operationID = "getScriptPolicy" - r.pathPattern = "/script-policy/{ScriptPolicyID}" - r.args = args - r.count = 1 - return r, true - case "POST": - r.name = UpdateScriptPolicyOperation - r.summary = "Update the specified script policy by ID" - r.operationID = "updateScriptPolicy" - r.pathPattern = "/script-policy/{ScriptPolicyID}" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - } - - elem = origElem - case 's': // Prefix: "s" - origElem := elem - if l := len("s"); len(elem) >= l && elem[0:l] == "s" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - switch method { - case "GET": - r.name = ListScriptsOperation - r.summary = "Get list of scripts" - r.operationID = "listScripts" - r.pathPattern = "/scripts" - r.args = args - r.count = 0 - return r, true - case "POST": - r.name = CreateScriptOperation - r.summary = "Create a new script" - r.operationID = "createScript" - r.pathPattern = "/scripts" - r.args = args - r.count = 0 - return r, true - default: - return - } - } - switch elem[0] { - case '/': // Prefix: "/" - origElem := elem - if l := len("/"); len(elem) >= l && elem[0:l] == "/" { - elem = elem[l:] - } else { - break - } - - // Param: "ScriptID" - // Leaf parameter - args[0] = elem - elem = "" - - if len(elem) == 0 { - // Leaf node. - switch method { - case "DELETE": - r.name = DeleteScriptOperation - r.summary = "Delete the specified script by ID" - r.operationID = "deleteScript" - r.pathPattern = "/scripts/{ScriptID}" - r.args = args - r.count = 1 - return r, true - case "GET": - r.name = GetScriptOperation - r.summary = "Get the specified script by ID" - r.operationID = "getScript" - r.pathPattern = "/scripts/{ScriptID}" - r.args = args - r.count = 1 - return r, true - case "POST": - r.name = UpdateScriptOperation - r.summary = "Update the specified script by ID" - r.operationID = "updateScript" - r.pathPattern = "/scripts/{ScriptID}" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - } - - elem = origElem - } - - elem = origElem - case 'u': // Prefix: "ubmissions" - origElem := elem - if l := len("ubmissions"); len(elem) >= l && elem[0:l] == "ubmissions" { + if l := len("release-submissions"); len(elem) >= l && elem[0:l] == "release-submissions" { elem = elem[l:] } else { break } if len(elem) == 0 { + // Leaf node. switch method { - case "GET": - r.name = ListSubmissionsOperation - r.summary = "Get list of submissions" - r.operationID = "listSubmissions" - r.pathPattern = "/submissions" - r.args = args - r.count = 0 - return r, true case "POST": - r.name = CreateSubmissionOperation - r.summary = "Create new submission" - r.operationID = "createSubmission" - r.pathPattern = "/submissions" + r.name = ReleaseSubmissionsOperation + r.summary = "Release a set of uploaded maps" + r.operationID = "releaseSubmissions" + r.pathPattern = "/release-submissions" r.args = args r.count = 0 return r, true @@ -797,33 +651,220 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { return } } + + elem = origElem + case 's': // Prefix: "s" + origElem := elem + if l := len("s"); len(elem) >= l && elem[0:l] == "s" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } switch elem[0] { - case '/': // Prefix: "/" + case 'c': // Prefix: "cript" origElem := elem - if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + if l := len("cript"); len(elem) >= l && elem[0:l] == "cript" { elem = elem[l:] } else { break } - // Param: "SubmissionID" - // Match until "/" - idx := strings.IndexByte(elem, '/') - if idx < 0 { - idx = len(elem) + if len(elem) == 0 { + break + } + switch elem[0] { + case '-': // Prefix: "-policy" + origElem := elem + if l := len("-policy"); len(elem) >= l && elem[0:l] == "-policy" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "GET": + r.name = ListScriptPolicyOperation + r.summary = "Get list of script policies" + r.operationID = "listScriptPolicy" + r.pathPattern = "/script-policy" + r.args = args + r.count = 0 + return r, true + case "POST": + r.name = CreateScriptPolicyOperation + r.summary = "Create a new script policy" + r.operationID = "createScriptPolicy" + r.pathPattern = "/script-policy" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/" + origElem := elem + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "ScriptPolicyID" + // Leaf parameter + args[0] = elem + elem = "" + + if len(elem) == 0 { + // Leaf node. + switch method { + case "DELETE": + r.name = DeleteScriptPolicyOperation + r.summary = "Delete the specified script policy by ID" + r.operationID = "deleteScriptPolicy" + r.pathPattern = "/script-policy/{ScriptPolicyID}" + r.args = args + r.count = 1 + return r, true + case "GET": + r.name = GetScriptPolicyOperation + r.summary = "Get the specified script policy by ID" + r.operationID = "getScriptPolicy" + r.pathPattern = "/script-policy/{ScriptPolicyID}" + r.args = args + r.count = 1 + return r, true + case "POST": + r.name = UpdateScriptPolicyOperation + r.summary = "Update the specified script policy by ID" + r.operationID = "updateScriptPolicy" + r.pathPattern = "/script-policy/{ScriptPolicyID}" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + } + + elem = origElem + case 's': // Prefix: "s" + origElem := elem + if l := len("s"); len(elem) >= l && elem[0:l] == "s" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + switch method { + case "GET": + r.name = ListScriptsOperation + r.summary = "Get list of scripts" + r.operationID = "listScripts" + r.pathPattern = "/scripts" + r.args = args + r.count = 0 + return r, true + case "POST": + r.name = CreateScriptOperation + r.summary = "Create a new script" + r.operationID = "createScript" + r.pathPattern = "/scripts" + r.args = args + r.count = 0 + return r, true + default: + return + } + } + switch elem[0] { + case '/': // Prefix: "/" + origElem := elem + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { + elem = elem[l:] + } else { + break + } + + // Param: "ScriptID" + // Leaf parameter + args[0] = elem + elem = "" + + if len(elem) == 0 { + // Leaf node. + switch method { + case "DELETE": + r.name = DeleteScriptOperation + r.summary = "Delete the specified script by ID" + r.operationID = "deleteScript" + r.pathPattern = "/scripts/{ScriptID}" + r.args = args + r.count = 1 + return r, true + case "GET": + r.name = GetScriptOperation + r.summary = "Get the specified script by ID" + r.operationID = "getScript" + r.pathPattern = "/scripts/{ScriptID}" + r.args = args + r.count = 1 + return r, true + case "POST": + r.name = UpdateScriptOperation + r.summary = "Update the specified script by ID" + r.operationID = "updateScript" + r.pathPattern = "/scripts/{ScriptID}" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + } + + elem = origElem + } + + elem = origElem + case 'u': // Prefix: "ubmissions" + origElem := elem + if l := len("ubmissions"); len(elem) >= l && elem[0:l] == "ubmissions" { + elem = elem[l:] + } else { + break } - args[0] = elem[:idx] - elem = elem[idx:] if len(elem) == 0 { switch method { case "GET": - r.name = GetSubmissionOperation - r.summary = "Retrieve map with ID" - r.operationID = "getSubmission" - r.pathPattern = "/submissions/{SubmissionID}" + r.name = ListSubmissionsOperation + r.summary = "Get list of submissions" + r.operationID = "listSubmissions" + r.pathPattern = "/submissions" r.args = args - r.count = 1 + r.count = 0 + return r, true + case "POST": + r.name = CreateSubmissionOperation + r.summary = "Create new submission" + r.operationID = "createSubmission" + r.pathPattern = "/submissions" + r.args = args + r.count = 0 return r, true default: return @@ -838,63 +879,33 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { break } + // Param: "SubmissionID" + // Match until "/" + idx := strings.IndexByte(elem, '/') + if idx < 0 { + idx = len(elem) + } + args[0] = elem[:idx] + elem = elem[idx:] + if len(elem) == 0 { - break + switch method { + case "GET": + r.name = GetSubmissionOperation + r.summary = "Retrieve map with ID" + r.operationID = "getSubmission" + r.pathPattern = "/submissions/{SubmissionID}" + r.args = args + r.count = 1 + return r, true + default: + return + } } switch elem[0] { - case 'c': // Prefix: "completed" + case '/': // Prefix: "/" origElem := elem - if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "POST": - r.name = SetSubmissionCompletedOperation - r.summary = "Retrieve map with ID" - r.operationID = "setSubmissionCompleted" - r.pathPattern = "/submissions/{SubmissionID}/completed" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - case 'm': // Prefix: "model" - origElem := elem - if l := len("model"); len(elem) >= l && elem[0:l] == "model" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "POST": - r.name = UpdateSubmissionModelOperation - r.summary = "Update model following role restrictions" - r.operationID = "updateSubmissionModel" - r.pathPattern = "/submissions/{SubmissionID}/model" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - case 's': // Prefix: "status/" - origElem := elem - if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" { + if l := len("/"); len(elem) >= l && elem[0:l] == "/" { elem = elem[l:] } else { break @@ -904,99 +915,9 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { break } switch elem[0] { - case 'r': // Prefix: "re" + case 'c': // Prefix: "completed" origElem := elem - if l := len("re"); len(elem) >= l && elem[0:l] == "re" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - break - } - switch elem[0] { - case 'j': // Prefix: "ject" - origElem := elem - if l := len("ject"); len(elem) >= l && elem[0:l] == "ject" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "POST": - r.name = ActionSubmissionRejectOperation - r.summary = "Role Reviewer changes status from Submitted -> Rejected" - r.operationID = "actionSubmissionReject" - r.pathPattern = "/submissions/{SubmissionID}/status/reject" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - case 'q': // Prefix: "quest-changes" - origElem := elem - if l := len("quest-changes"); len(elem) >= l && elem[0:l] == "quest-changes" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "POST": - r.name = ActionSubmissionRequestChangesOperation - r.summary = "Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested" - r.operationID = "actionSubmissionRequestChanges" - r.pathPattern = "/submissions/{SubmissionID}/status/request-changes" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - case 'v': // Prefix: "voke" - origElem := elem - if l := len("voke"); len(elem) >= l && elem[0:l] == "voke" { - elem = elem[l:] - } else { - break - } - - if len(elem) == 0 { - // Leaf node. - switch method { - case "POST": - r.name = ActionSubmissionRevokeOperation - r.summary = "Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction" - r.operationID = "actionSubmissionRevoke" - r.pathPattern = "/submissions/{SubmissionID}/status/revoke" - r.args = args - r.count = 1 - return r, true - default: - return - } - } - - elem = origElem - } - - elem = origElem - case 's': // Prefix: "submit" - origElem := elem - if l := len("submit"); len(elem) >= l && elem[0:l] == "submit" { + if l := len("completed"); len(elem) >= l && elem[0:l] == "completed" { elem = elem[l:] } else { break @@ -1006,10 +927,10 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { // Leaf node. switch method { case "POST": - r.name = ActionSubmissionSubmitOperation - r.summary = "Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted" - r.operationID = "actionSubmissionSubmit" - r.pathPattern = "/submissions/{SubmissionID}/status/submit" + r.name = SetSubmissionCompletedOperation + r.summary = "Retrieve map with ID" + r.operationID = "setSubmissionCompleted" + r.pathPattern = "/submissions/{SubmissionID}/completed" r.args = args r.count = 1 return r, true @@ -1019,9 +940,34 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 't': // Prefix: "trigger-" + case 'm': // Prefix: "model" origElem := elem - if l := len("trigger-"); len(elem) >= l && elem[0:l] == "trigger-" { + if l := len("model"); len(elem) >= l && elem[0:l] == "model" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = UpdateSubmissionModelOperation + r.summary = "Update model following role restrictions" + r.operationID = "updateSubmissionModel" + r.pathPattern = "/submissions/{SubmissionID}/model" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 's': // Prefix: "status/" + origElem := elem + if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" { elem = elem[l:] } else { break @@ -1031,9 +977,99 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { break } switch elem[0] { - case 'u': // Prefix: "upload" + case 'r': // Prefix: "re" origElem := elem - if l := len("upload"); len(elem) >= l && elem[0:l] == "upload" { + if l := len("re"); len(elem) >= l && elem[0:l] == "re" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + break + } + switch elem[0] { + case 'j': // Prefix: "ject" + origElem := elem + if l := len("ject"); len(elem) >= l && elem[0:l] == "ject" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = ActionSubmissionRejectOperation + r.summary = "Role Reviewer changes status from Submitted -> Rejected" + r.operationID = "actionSubmissionReject" + r.pathPattern = "/submissions/{SubmissionID}/status/reject" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'q': // Prefix: "quest-changes" + origElem := elem + if l := len("quest-changes"); len(elem) >= l && elem[0:l] == "quest-changes" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = ActionSubmissionRequestChangesOperation + r.summary = "Role Reviewer changes status from Validated|Accepted|Submitted -> ChangesRequested" + r.operationID = "actionSubmissionRequestChanges" + r.pathPattern = "/submissions/{SubmissionID}/status/request-changes" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'v': // Prefix: "voke" + origElem := elem + if l := len("voke"); len(elem) >= l && elem[0:l] == "voke" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = ActionSubmissionRevokeOperation + r.summary = "Role Submitter changes status from Submitted|ChangesRequested -> UnderConstruction" + r.operationID = "actionSubmissionRevoke" + r.pathPattern = "/submissions/{SubmissionID}/status/revoke" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + } + + elem = origElem + case 's': // Prefix: "submit" + origElem := elem + if l := len("submit"); len(elem) >= l && elem[0:l] == "submit" { elem = elem[l:] } else { break @@ -1043,10 +1079,10 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { // Leaf node. switch method { case "POST": - r.name = ActionSubmissionTriggerUploadOperation - r.summary = "Role Admin changes status from Validated -> Uploading" - r.operationID = "actionSubmissionTriggerUpload" - r.pathPattern = "/submissions/{SubmissionID}/status/trigger-upload" + r.name = ActionSubmissionSubmitOperation + r.summary = "Role Submitter changes status from UnderConstruction|ChangesRequested -> Submitted" + r.operationID = "actionSubmissionSubmit" + r.pathPattern = "/submissions/{SubmissionID}/status/submit" r.args = args r.count = 1 return r, true @@ -1056,28 +1092,68 @@ func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) { } elem = origElem - case 'v': // Prefix: "validate" + case 't': // Prefix: "trigger-" origElem := elem - if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + if l := len("trigger-"); len(elem) >= l && elem[0:l] == "trigger-" { elem = elem[l:] } else { break } if len(elem) == 0 { - // Leaf node. - switch method { - case "POST": - r.name = ActionSubmissionTriggerValidateOperation - r.summary = "Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating" - r.operationID = "actionSubmissionTriggerValidate" - r.pathPattern = "/submissions/{SubmissionID}/status/trigger-validate" - r.args = args - r.count = 1 - return r, true - default: - return + break + } + switch elem[0] { + case 'u': // Prefix: "upload" + origElem := elem + if l := len("upload"); len(elem) >= l && elem[0:l] == "upload" { + elem = elem[l:] + } else { + break } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = ActionSubmissionTriggerUploadOperation + r.summary = "Role Admin changes status from Validated -> Uploading" + r.operationID = "actionSubmissionTriggerUpload" + r.pathPattern = "/submissions/{SubmissionID}/status/trigger-upload" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem + case 'v': // Prefix: "validate" + origElem := elem + if l := len("validate"); len(elem) >= l && elem[0:l] == "validate" { + elem = elem[l:] + } else { + break + } + + if len(elem) == 0 { + // Leaf node. + switch method { + case "POST": + r.name = ActionSubmissionTriggerValidateOperation + r.summary = "Role Reviewer triggers validation and changes status from Submitted|Accepted -> Validating" + r.operationID = "actionSubmissionTriggerValidate" + r.pathPattern = "/submissions/{SubmissionID}/status/trigger-validate" + r.args = args + r.count = 1 + return r, true + default: + return + } + } + + elem = origElem } elem = origElem diff --git a/pkg/api/oas_schemas_gen.go b/pkg/api/oas_schemas_gen.go index 0a9fd56..2cfbe28 100644 --- a/pkg/api/oas_schemas_gen.go +++ b/pkg/api/oas_schemas_gen.go @@ -4,6 +4,7 @@ package api import ( "fmt" + "time" ) func (s *ErrorStatusCode) Error() string { @@ -254,6 +255,35 @@ func (o OptString) Or(d string) string { return d } +// Ref: #/components/schemas/ReleaseInfo +type ReleaseInfo struct { + SubmissionID int64 `json:"SubmissionID"` + Date time.Time `json:"Date"` +} + +// GetSubmissionID returns the value of SubmissionID. +func (s *ReleaseInfo) GetSubmissionID() int64 { + return s.SubmissionID +} + +// GetDate returns the value of Date. +func (s *ReleaseInfo) GetDate() time.Time { + return s.Date +} + +// SetSubmissionID sets the value of SubmissionID. +func (s *ReleaseInfo) SetSubmissionID(val int64) { + s.SubmissionID = val +} + +// SetDate sets the value of Date. +func (s *ReleaseInfo) SetDate(val time.Time) { + s.Date = val +} + +// ReleaseSubmissionsCreated is response for ReleaseSubmissions operation. +type ReleaseSubmissionsCreated struct{} + // Ref: #/components/schemas/Script type Script struct { ID int64 `json:"ID"` diff --git a/pkg/api/oas_server_gen.go b/pkg/api/oas_server_gen.go index ac66414..39f11d8 100644 --- a/pkg/api/oas_server_gen.go +++ b/pkg/api/oas_server_gen.go @@ -110,6 +110,12 @@ type Handler interface { // // GET /submissions ListSubmissions(ctx context.Context, params ListSubmissionsParams) ([]Submission, error) + // ReleaseSubmissions implements releaseSubmissions operation. + // + // Release a set of uploaded maps. + // + // POST /release-submissions + ReleaseSubmissions(ctx context.Context, req []ReleaseInfo) error // SetSubmissionCompleted implements setSubmissionCompleted operation. // // Retrieve map with ID. diff --git a/pkg/api/oas_unimplemented_gen.go b/pkg/api/oas_unimplemented_gen.go index b080398..6e0d639 100644 --- a/pkg/api/oas_unimplemented_gen.go +++ b/pkg/api/oas_unimplemented_gen.go @@ -166,6 +166,15 @@ func (UnimplementedHandler) ListSubmissions(ctx context.Context, params ListSubm return r, ht.ErrNotImplemented } +// ReleaseSubmissions implements releaseSubmissions operation. +// +// Release a set of uploaded maps. +// +// POST /release-submissions +func (UnimplementedHandler) ReleaseSubmissions(ctx context.Context, req []ReleaseInfo) error { + return ht.ErrNotImplemented +} + // SetSubmissionCompleted implements setSubmissionCompleted operation. // // Retrieve map with ID. diff --git a/pkg/service/submissions.go b/pkg/service/submissions.go index b027576..c2f29bc 100644 --- a/pkg/service/submissions.go +++ b/pkg/service/submissions.go @@ -478,3 +478,12 @@ func (svc *Service) ActionSubmissionTriggerValidate(ctx context.Context, params return nil } + +// ReleaseSubmissions invokes releaseSubmissions operation. +// +// Release a set of uploaded maps. +// +// POST /release-submissions +func (svc *Service) ReleaseSubmissions(ctx context.Context, request []api.ReleaseInfo) error { + return nil +}