677 lines
15 KiB
Go
677 lines
15 KiB
Go
// Code generated by ogen, DO NOT EDIT.
|
|
|
|
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/ogen-go/ogen/uri"
|
|
)
|
|
|
|
var (
|
|
rn12AllowedHeaders = map[string]string{
|
|
"POST": "Content-Type",
|
|
}
|
|
rn1AllowedHeaders = map[string]string{
|
|
"POST": "Content-Type",
|
|
}
|
|
rn10AllowedHeaders = map[string]string{
|
|
"POST": "Content-Type,Idempotency-Key",
|
|
}
|
|
rn9AllowedHeaders = map[string]string{
|
|
"POST": "Content-Type",
|
|
}
|
|
rn6AllowedHeaders = map[string]string{
|
|
"DELETE": "X-Csrf-Token",
|
|
}
|
|
)
|
|
|
|
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] {
|
|
case '/': // Prefix: "/api/v1/"
|
|
|
|
if l := len("/api/v1/"); len(elem) >= l && elem[0:l] == "/api/v1/" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
break
|
|
}
|
|
switch elem[0] {
|
|
case 'h': // Prefix: "healthz"
|
|
|
|
if l := len("healthz"); len(elem) >= l && elem[0:l] == "healthz" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "GET":
|
|
s.handleGetHealthzRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "GET",
|
|
allowedHeaders: nil,
|
|
acceptPost: "",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
case 'i': // Prefix: "identity/"
|
|
|
|
if l := len("identity/"); len(elem) >= l && elem[0:l] == "identity/" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
break
|
|
}
|
|
switch elem[0] {
|
|
case 'c': // Prefix: "consent-texts/"
|
|
|
|
if l := len("consent-texts/"); len(elem) >= l && elem[0:l] == "consent-texts/" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
// Param: "purpose"
|
|
// Leaf parameter, slashes are prohibited
|
|
idx := strings.IndexByte(elem, '/')
|
|
if idx >= 0 {
|
|
break
|
|
}
|
|
args[0] = elem
|
|
elem = ""
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "GET":
|
|
s.handleGetConsentTextRequest([1]string{
|
|
args[0],
|
|
}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "GET",
|
|
allowedHeaders: nil,
|
|
acceptPost: "",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
case 'e': // Prefix: "email-verification"
|
|
|
|
if l := len("email-verification"); len(elem) >= l && elem[0:l] == "email-verification" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
break
|
|
}
|
|
switch elem[0] {
|
|
case '-': // Prefix: "-requests"
|
|
|
|
if l := len("-requests"); len(elem) >= l && elem[0:l] == "-requests" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "POST":
|
|
s.handleResendEmailVerificationRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "POST",
|
|
allowedHeaders: rn12AllowedHeaders,
|
|
acceptPost: "application/json",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
case 's': // Prefix: "s"
|
|
|
|
if l := len("s"); len(elem) >= l && elem[0:l] == "s" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "POST":
|
|
s.handleConfirmEmailRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "POST",
|
|
allowedHeaders: rn1AllowedHeaders,
|
|
acceptPost: "application/json",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
case 'm': // Prefix: "me"
|
|
|
|
if l := len("me"); len(elem) >= l && elem[0:l] == "me" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "GET":
|
|
s.handleGetCurrentAccountRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "GET",
|
|
allowedHeaders: nil,
|
|
acceptPost: "",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
case 'r': // Prefix: "registrations"
|
|
|
|
if l := len("registrations"); len(elem) >= l && elem[0:l] == "registrations" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "POST":
|
|
s.handleRegisterAccountRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "POST",
|
|
allowedHeaders: rn10AllowedHeaders,
|
|
acceptPost: "application/json",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
case 's': // Prefix: "sessions"
|
|
|
|
if l := len("sessions"); len(elem) >= l && elem[0:l] == "sessions" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
switch r.Method {
|
|
case "POST":
|
|
s.handleLoginRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "POST",
|
|
allowedHeaders: rn9AllowedHeaders,
|
|
acceptPost: "application/json",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
switch elem[0] {
|
|
case '/': // Prefix: "/current"
|
|
|
|
if l := len("/current"); len(elem) >= l && elem[0:l] == "/current" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch r.Method {
|
|
case "DELETE":
|
|
s.handleLogoutRequest([0]string{}, elemIsEscaped, w, r)
|
|
case "GET":
|
|
s.handleGetCurrentSessionRequest([0]string{}, elemIsEscaped, w, r)
|
|
default:
|
|
s.notAllowed(w, r, notAllowedParams{
|
|
allowedMethods: "DELETE,GET",
|
|
allowedHeaders: rn6AllowedHeaders,
|
|
acceptPost: "",
|
|
acceptPatch: "",
|
|
})
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
s.notFound(w, r)
|
|
}
|
|
|
|
// Route is route object.
|
|
type Route struct {
|
|
name string
|
|
summary string
|
|
operationID string
|
|
operationGroup 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
|
|
}
|
|
|
|
// OperationGroup returns the x-ogen-operation-group value.
|
|
func (r Route) OperationGroup() string {
|
|
return r.operationGroup
|
|
}
|
|
|
|
// 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] {
|
|
case '/': // Prefix: "/api/v1/"
|
|
|
|
if l := len("/api/v1/"); len(elem) >= l && elem[0:l] == "/api/v1/" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
break
|
|
}
|
|
switch elem[0] {
|
|
case 'h': // Prefix: "healthz"
|
|
|
|
if l := len("healthz"); len(elem) >= l && elem[0:l] == "healthz" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "GET":
|
|
r.name = GetHealthzOperation
|
|
r.summary = "Check whether the API process is responding."
|
|
r.operationID = "GetHealthz"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/healthz"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
case 'i': // Prefix: "identity/"
|
|
|
|
if l := len("identity/"); len(elem) >= l && elem[0:l] == "identity/" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
break
|
|
}
|
|
switch elem[0] {
|
|
case 'c': // Prefix: "consent-texts/"
|
|
|
|
if l := len("consent-texts/"); len(elem) >= l && elem[0:l] == "consent-texts/" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
// Param: "purpose"
|
|
// Leaf parameter, slashes are prohibited
|
|
idx := strings.IndexByte(elem, '/')
|
|
if idx >= 0 {
|
|
break
|
|
}
|
|
args[0] = elem
|
|
elem = ""
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "GET":
|
|
r.name = GetConsentTextOperation
|
|
r.summary = "Read the currently published text of a registration consent."
|
|
r.operationID = "GetConsentText"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/consent-texts/{purpose}"
|
|
r.args = args
|
|
r.count = 1
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
case 'e': // Prefix: "email-verification"
|
|
|
|
if l := len("email-verification"); len(elem) >= l && elem[0:l] == "email-verification" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
break
|
|
}
|
|
switch elem[0] {
|
|
case '-': // Prefix: "-requests"
|
|
|
|
if l := len("-requests"); len(elem) >= l && elem[0:l] == "-requests" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "POST":
|
|
r.name = ResendEmailVerificationOperation
|
|
r.summary = "Request a new email verification link."
|
|
r.operationID = "ResendEmailVerification"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/email-verification-requests"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
case 's': // Prefix: "s"
|
|
|
|
if l := len("s"); len(elem) >= l && elem[0:l] == "s" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "POST":
|
|
r.name = ConfirmEmailOperation
|
|
r.summary = "Verify an email with the one-time token from the link."
|
|
r.operationID = "ConfirmEmail"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/email-verifications"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
case 'm': // Prefix: "me"
|
|
|
|
if l := len("me"); len(elem) >= l && elem[0:l] == "me" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "GET":
|
|
r.name = GetCurrentAccountOperation
|
|
r.summary = "Read the account of the current session."
|
|
r.operationID = "GetCurrentAccount"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/me"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
case 'r': // Prefix: "registrations"
|
|
|
|
if l := len("registrations"); len(elem) >= l && elem[0:l] == "registrations" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "POST":
|
|
r.name = RegisterAccountOperation
|
|
r.summary = "Register an account by email with a scenario and consent C1."
|
|
r.operationID = "RegisterAccount"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/registrations"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
case 's': // Prefix: "sessions"
|
|
|
|
if l := len("sessions"); len(elem) >= l && elem[0:l] == "sessions" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
switch method {
|
|
case "POST":
|
|
r.name = LoginOperation
|
|
r.summary = "Sign in with email and password and start a session."
|
|
r.operationID = "Login"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/sessions"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
switch elem[0] {
|
|
case '/': // Prefix: "/current"
|
|
|
|
if l := len("/current"); len(elem) >= l && elem[0:l] == "/current" {
|
|
elem = elem[l:]
|
|
} else {
|
|
break
|
|
}
|
|
|
|
if len(elem) == 0 {
|
|
// Leaf node.
|
|
switch method {
|
|
case "DELETE":
|
|
r.name = LogoutOperation
|
|
r.summary = "Sign out and revoke the current session."
|
|
r.operationID = "Logout"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/sessions/current"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
case "GET":
|
|
r.name = GetCurrentSessionOperation
|
|
r.summary = "Read the current session and its CSRF token."
|
|
r.operationID = "GetCurrentSession"
|
|
r.operationGroup = ""
|
|
r.pathPattern = "/api/v1/identity/sessions/current"
|
|
r.args = args
|
|
r.count = 0
|
|
return r, true
|
|
default:
|
|
return
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
return r, false
|
|
}
|