maps-service/pkg/internal/oas_router_gen.go

746 lines
16 KiB
Go
Raw Normal View History

2024-12-14 19:55:56 +00:00
// Code generated by ogen, DO NOT EDIT.
package api
import (
"net/http"
"net/url"
"strings"
"github.com/ogen-go/ogen/uri"
)
func (s *Server) cutPrefix(path string) (string, bool) {
prefix := s.cfg.Prefix
if prefix == "" {
return path, true
}
if !strings.HasPrefix(path, prefix) {
// Prefix doesn't match.
return "", false
}
// Cut prefix from the path.
return strings.TrimPrefix(path, prefix), true
}
// ServeHTTP serves http request as defined by OpenAPI v3 specification,
// calling handler that matches the path or returning not found error.
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
elem := r.URL.Path
elemIsEscaped := false
if rawPath := r.URL.RawPath; rawPath != "" {
if normalized, ok := uri.NormalizeEscapedPath(rawPath); ok {
elem = normalized
elemIsEscaped = strings.ContainsRune(elem, '%')
}
}
elem, ok := s.cutPrefix(elem)
if !ok || len(elem) == 0 {
s.notFound(w, r)
return
}
args := [1]string{}
// Static code generated router with unwrapped path search.
switch {
default:
if len(elem) == 0 {
break
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case '/': // Prefix: "/s"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("/s"); len(elem) >= l && elem[0:l] == "/s" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case 'c': // Prefix: "cript"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("cript"); len(elem) >= l && elem[0:l] == "cript" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case '-': // Prefix: "-policy"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("-policy"); len(elem) >= l && elem[0:l] == "-policy" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
2024-12-18 23:06:39 +00:00
// Leaf node.
2024-12-14 19:55:56 +00:00
switch r.Method {
2024-12-18 23:06:39 +00:00
case "GET":
s.handleListScriptPolicyRequest([0]string{}, elemIsEscaped, w, r)
2024-12-14 19:55:56 +00:00
case "POST":
2024-12-18 02:12:00 +00:00
s.handleCreateScriptPolicyRequest([0]string{}, elemIsEscaped, w, r)
2024-12-14 19:55:56 +00:00
default:
2024-12-18 23:06:39 +00:00
s.notAllowed(w, r, "GET,POST")
2024-12-14 19:55:56 +00:00
}
return
}
elem = origElem
2024-12-18 02:12:00 +00:00
case 's': // Prefix: "s"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("s"); len(elem) >= l && elem[0:l] == "s" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
2024-12-18 02:12:00 +00:00
switch r.Method {
2024-12-18 23:06:39 +00:00
case "GET":
s.handleListScriptsRequest([0]string{}, elemIsEscaped, w, r)
2024-12-18 02:12:00 +00:00
case "POST":
s.handleCreateScriptRequest([0]string{}, elemIsEscaped, w, r)
default:
2024-12-18 23:06:39 +00:00
s.notAllowed(w, r, "GET,POST")
2024-12-18 02:12:00 +00:00
}
return
2024-12-14 19:55:56 +00:00
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case '/': // Prefix: "/"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
2024-12-18 02:12:00 +00:00
// Param: "ScriptID"
// Leaf parameter
args[0] = elem
elem = ""
2024-12-14 19:55:56 +00:00
if len(elem) == 0 {
// Leaf node.
switch r.Method {
2024-12-18 02:12:00 +00:00
case "GET":
s.handleGetScriptRequest([1]string{
2024-12-14 19:55:56 +00:00
args[0],
}, elemIsEscaped, w, r)
default:
2024-12-18 02:12:00 +00:00
s.notAllowed(w, r, "GET")
2024-12-14 19:55:56 +00:00
}
return
}
elem = origElem
2024-12-18 02:12:00 +00:00
}
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
}
// 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 elem[0] {
case '/': // Prefix: "/"
origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
case 'm': // Prefix: "model"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("model"); len(elem) >= l && elem[0:l] == "model" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "POST":
2024-12-18 02:12:00 +00:00
s.handleUpdateSubmissionModelRequest([1]string{
2024-12-14 19:55:56 +00:00
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "POST")
}
return
}
2024-12-18 02:12:00 +00:00
elem = origElem
case 's': // Prefix: "status/"
origElem := elem
if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
case 'r': // Prefix: "releaser-released"
origElem := elem
if l := len("releaser-released"); len(elem) >= l && elem[0:l] == "releaser-released" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "POST":
s.handleActionSubmissionReleasedRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "POST")
}
return
}
elem = origElem
case 'v': // Prefix: "validator-"
origElem := elem
if l := len("validator-"); len(elem) >= l && elem[0:l] == "validator-" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
case 'f': // Prefix: "failed"
origElem := elem
if l := len("failed"); len(elem) >= l && elem[0:l] == "failed" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "POST":
s.handleActionSubmissionAcceptedRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "POST")
}
return
}
elem = origElem
case 'u': // Prefix: "uploaded"
origElem := elem
if l := len("uploaded"); len(elem) >= l && elem[0:l] == "uploaded" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "POST":
s.handleActionSubmissionUploadedRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "POST")
}
return
}
elem = origElem
case 'v': // Prefix: "validated"
origElem := elem
if l := len("validated"); len(elem) >= l && elem[0:l] == "validated" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch r.Method {
case "POST":
s.handleActionSubmissionValidatedRequest([1]string{
args[0],
}, elemIsEscaped, w, r)
default:
s.notAllowed(w, r, "POST")
}
return
}
elem = origElem
}
elem = origElem
}
2024-12-14 19:55:56 +00:00
elem = origElem
}
elem = origElem
}
elem = origElem
}
elem = origElem
}
}
s.notFound(w, r)
}
// Route is route object.
type Route struct {
name string
summary string
operationID string
pathPattern string
count int
args [1]string
}
// Name returns ogen operation name.
//
// It is guaranteed to be unique and not empty.
func (r Route) Name() string {
return r.name
}
// Summary returns OpenAPI summary.
func (r Route) Summary() string {
return r.summary
}
// OperationID returns OpenAPI operationId.
func (r Route) OperationID() string {
return r.operationID
}
// PathPattern returns OpenAPI path.
func (r Route) PathPattern() string {
return r.pathPattern
}
// Args returns parsed arguments.
func (r Route) Args() []string {
return r.args[:r.count]
}
// FindRoute finds Route for given method and path.
//
// Note: this method does not unescape path or handle reserved characters in path properly. Use FindPath instead.
func (s *Server) FindRoute(method, path string) (Route, bool) {
return s.FindPath(method, &url.URL{Path: path})
}
// FindPath finds Route for given method and URL.
func (s *Server) FindPath(method string, u *url.URL) (r Route, _ bool) {
var (
elem = u.Path
args = r.args
)
if rawPath := u.RawPath; rawPath != "" {
if normalized, ok := uri.NormalizeEscapedPath(rawPath); ok {
elem = normalized
}
defer func() {
for i, arg := range r.args[:r.count] {
if unescaped, err := url.PathUnescape(arg); err == nil {
r.args[i] = unescaped
}
}
}()
}
elem, ok := s.cutPrefix(elem)
if !ok {
return r, false
}
// Static code generated router with unwrapped path search.
switch {
default:
if len(elem) == 0 {
break
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case '/': // Prefix: "/s"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("/s"); len(elem) >= l && elem[0:l] == "/s" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case 'c': // Prefix: "cript"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("cript"); len(elem) >= l && elem[0:l] == "cript" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case '-': // Prefix: "-policy"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("-policy"); len(elem) >= l && elem[0:l] == "-policy" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
2024-12-18 23:06:39 +00:00
// Leaf node.
2024-12-14 19:55:56 +00:00
switch method {
2024-12-18 23:06:39 +00:00
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
2024-12-14 19:55:56 +00:00
case "POST":
2024-12-18 02:12:00 +00:00
r.name = CreateScriptPolicyOperation
r.summary = "Create a new script policy"
r.operationID = "createScriptPolicy"
r.pathPattern = "/script-policy"
2024-12-14 19:55:56 +00:00
r.args = args
2024-12-18 02:12:00 +00:00
r.count = 0
2024-12-14 19:55:56 +00:00
return r, true
default:
return
}
}
elem = origElem
2024-12-18 02:12:00 +00:00
case 's': // Prefix: "s"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("s"); len(elem) >= l && elem[0:l] == "s" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
2024-12-18 02:12:00 +00:00
switch method {
2024-12-18 23:06:39 +00:00
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
2024-12-18 02:12:00 +00:00
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
}
2024-12-14 19:55:56 +00:00
}
switch elem[0] {
2024-12-18 02:12:00 +00:00
case '/': // Prefix: "/"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
2024-12-18 02:12:00 +00:00
// Param: "ScriptID"
// Leaf parameter
args[0] = elem
elem = ""
2024-12-14 19:55:56 +00:00
if len(elem) == 0 {
// Leaf node.
switch method {
2024-12-18 02:12:00 +00:00
case "GET":
r.name = GetScriptOperation
r.summary = "Get the specified script by ID"
r.operationID = "getScript"
r.pathPattern = "/scripts/{ScriptID}"
2024-12-14 19:55:56 +00:00
r.args = args
r.count = 1
return r, true
default:
return
}
}
elem = origElem
2024-12-18 02:12:00 +00:00
}
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
}
// 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 elem[0] {
case '/': // Prefix: "/"
origElem := elem
if l := len("/"); len(elem) >= l && elem[0:l] == "/" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
case 'm': // Prefix: "model"
2024-12-14 19:55:56 +00:00
origElem := elem
2024-12-18 02:12:00 +00:00
if l := len("model"); len(elem) >= l && elem[0:l] == "model" {
2024-12-14 19:55:56 +00:00
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "POST":
2024-12-18 02:12:00 +00:00
r.name = UpdateSubmissionModelOperation
r.summary = "Update model following role restrictions"
r.operationID = "updateSubmissionModel"
r.pathPattern = "/submissions/{SubmissionID}/model"
2024-12-14 19:55:56 +00:00
r.args = args
r.count = 1
return r, true
default:
return
}
}
2024-12-18 02:12:00 +00:00
elem = origElem
case 's': // Prefix: "status/"
origElem := elem
if l := len("status/"); len(elem) >= l && elem[0:l] == "status/" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
case 'r': // Prefix: "releaser-released"
origElem := elem
if l := len("releaser-released"); len(elem) >= l && elem[0:l] == "releaser-released" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "POST":
r.name = ActionSubmissionReleasedOperation
r.summary = "(Internal endpoint) Role Releaser changes status from releasing -> released"
r.operationID = "actionSubmissionReleased"
r.pathPattern = "/submissions/{SubmissionID}/status/releaser-released"
r.args = args
r.count = 1
return r, true
default:
return
}
}
elem = origElem
case 'v': // Prefix: "validator-"
origElem := elem
if l := len("validator-"); len(elem) >= l && elem[0:l] == "validator-" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
break
}
switch elem[0] {
case 'f': // Prefix: "failed"
origElem := elem
if l := len("failed"); len(elem) >= l && elem[0:l] == "failed" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "POST":
r.name = ActionSubmissionAcceptedOperation
r.summary = "(Internal endpoint) Role Validator changes status from Validating -> Accepted"
r.operationID = "actionSubmissionAccepted"
r.pathPattern = "/submissions/{SubmissionID}/status/validator-failed"
r.args = args
r.count = 1
return r, true
default:
return
}
}
elem = origElem
case 'u': // Prefix: "uploaded"
origElem := elem
if l := len("uploaded"); len(elem) >= l && elem[0:l] == "uploaded" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "POST":
r.name = ActionSubmissionUploadedOperation
r.summary = "(Internal endpoint) Role Validator changes status from Uploading -> Uploaded"
r.operationID = "actionSubmissionUploaded"
r.pathPattern = "/submissions/{SubmissionID}/status/validator-uploaded"
r.args = args
r.count = 1
return r, true
default:
return
}
}
elem = origElem
case 'v': // Prefix: "validated"
origElem := elem
if l := len("validated"); len(elem) >= l && elem[0:l] == "validated" {
elem = elem[l:]
} else {
break
}
if len(elem) == 0 {
// Leaf node.
switch method {
case "POST":
r.name = ActionSubmissionValidatedOperation
r.summary = "(Internal endpoint) Role Validator changes status from Validating -> Validated"
r.operationID = "actionSubmissionValidated"
r.pathPattern = "/submissions/{SubmissionID}/status/validator-validated"
r.args = args
r.count = 1
return r, true
default:
return
}
}
elem = origElem
}
elem = origElem
}
2024-12-14 19:55:56 +00:00
elem = origElem
}
elem = origElem
}
elem = origElem
}
elem = origElem
}
}
return r, false
}