api_openapi

package
v0.0.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MaxRequestBodyBytes = coreopenapi.MaxDocumentBytes + 1024

Variables

This section is empty.

Functions

func BuildExport

func BuildExport(snapshot DocumentSnapshot, server string) ([]byte, error)

BuildExport produces the standard public OpenAPI representation for a document snapshot without exposing management-only route fields.

func GatewayServer

func GatewayServer(c *app.Context, slug string) string

GatewayServer returns the public gateway URL used by exported documents.

func LimitRequestBody

func LimitRequestBody(next gin.HandlerFunc) gin.HandlerFunc

LimitRequestBody bounds the OpenAPI envelope before strict JSON binding.

Types

type DocumentResponse

type DocumentResponse struct {
	DocumentSnapshot
	Export json.RawMessage `json:"export"`
}

type DocumentSnapshot

type DocumentSnapshot struct {
	Service ServiceDocument `json:"service"`
	Routes  []RouteDocument `json:"routes"`
}

type Handler

type Handler struct {
	App      app.Application
	Importer Importer
	Finder   OpenAPIDocumentFinder
}

func (*Handler) Get

func (h *Handler) Get(c *app.Context, req IDRequest) (DocumentResponse, error)

func (*Handler) Import

func (h *Handler) Import(c *app.Context, req ImportCommand) (api.Created[ImportResult], error)

func (*Handler) Preview

func (h *Handler) Preview(c *app.Context, req PreviewRequest) (PreviewResponse, error)

func (*Handler) Update

func (h *Handler) Update(c *app.Context, req UpdateRequest) (DocumentResponse, error)

type IDRequest

type IDRequest struct {
	ID uint `uri:"id" binding:"required"`
}

type ImportCommand

type ImportCommand struct {
	Document       json.RawMessage                `json:"document" binding:"required"`
	Slug           string                         `json:"slug" binding:"required,max=64"`
	Choices        []coreopenapi.RouteGroupChoice `json:"choices"`
	SelectedServer *int                           `json:"selected_server"`
	BackendName    string                         `json:"backend_name" binding:"required,max=64"`
	Upstream       UpstreamDraft                  `json:"upstream" binding:"required"`
	PricePerCall   int64                          `json:"price_per_call"`
}

type ImportPublisher

type ImportPublisher interface {
	PublishService(context.Context, string, models.APIService) error
	PublishUpstream(context.Context, string, models.APIUpstream) error
	PublishRoute(context.Context, string, models.APIRoute) error
}

type ImportResult

type ImportResult struct {
	ServiceID  uint   `json:"service_id"`
	BackendID  uint   `json:"backend_id"`
	UpstreamID uint   `json:"upstream_id"`
	RouteIDs   []uint `json:"route_ids"`
}

type Importer

type Importer struct {
	UpstreamCreator api_upstream.Creator
	Publisher       ImportPublisher
}

func (Importer) Import

func (i Importer) Import(ctx dao.Context, cmd ImportCommand) (ImportResult, error)

type OpenAPIDocumentFinder

type OpenAPIDocumentFinder struct{}

func (OpenAPIDocumentFinder) Find

func (OpenAPIDocumentFinder) Find(ctx dao.Context, serviceID uint) (DocumentSnapshot, error)

func (OpenAPIDocumentFinder) FindVisible

func (OpenAPIDocumentFinder) FindVisible(ctx dao.Context, serviceID uint, routeIDs *[]uint) (DocumentSnapshot, error)

FindVisible returns a service document containing only enabled routes in the supplied authorization scope. A nil route scope retains every enabled route.

func (OpenAPIDocumentFinder) FindVisibleInTx

func (OpenAPIDocumentFinder) FindVisibleInTx(tx dao.Context, serviceID uint, routeIDs *[]uint) (DocumentSnapshot, error)

FindVisibleInTx composes the scoped document read into a caller-owned core read transaction so authorization and documents can share one snapshot.

type PreviewRequest

type PreviewRequest struct {
	Document json.RawMessage `json:"document" binding:"required"`
}

type PreviewResponse

type PreviewResponse struct {
	Service  ServiceDraft  `json:"service"`
	Servers  []ServerDraft `json:"servers"`
	Routes   []RouteDraft  `json:"routes"`
	Problems []Problem     `json:"problems"`
}

type Problem

type Problem = coreopenapi.Problem

type RouteDocument

type RouteDocument struct {
	ID           uint                              `json:"id"`
	Slug         string                            `json:"slug"`
	UpstreamPath string                            `json:"upstream_path"`
	UpdatedAt    int64                             `json:"updated_at"`
	Paths        map[string]models.OpenAPIPathItem `json:"paths"`
}

type RouteDocumentUpdate

type RouteDocumentUpdate struct {
	ID        uint                              `json:"id" binding:"required"`
	UpdatedAt int64                             `json:"updated_at" binding:"required"`
	Paths     map[string]models.OpenAPIPathItem `json:"paths" binding:"required"`
}

type RouteDraft

type RouteDraft struct {
	Slug           string            `json:"slug"`
	DisplayName    string            `json:"display_name"`
	UpstreamPath   string            `json:"upstream_path"`
	AllowedMethods []string          `json:"allowed_methods"`
	Paths          []string          `json:"paths"`
	PublicPaths    map[string]string `json:"public_paths"`
	PathCount      int               `json:"path_count"`
	OperationCount int               `json:"operation_count"`
}

type ServerDraft

type ServerDraft struct {
	Index       int    `json:"index"`
	URL         string `json:"url"`
	Description string `json:"description,omitempty"`
}

type ServiceDocument

type ServiceDocument struct {
	ID          uint                          `json:"id"`
	Slug        string                        `json:"slug"`
	Name        string                        `json:"name"`
	Description string                        `json:"description"`
	UpdatedAt   int64                         `json:"updated_at"`
	Document    models.OpenAPIServiceDocument `json:"document"`
}

type ServiceDocumentUpdate

type ServiceDocumentUpdate struct {
	ID        uint                          `json:"id" binding:"required"`
	UpdatedAt int64                         `json:"updated_at" binding:"required"`
	Document  models.OpenAPIServiceDocument `json:"document" binding:"required"`
}

type ServiceDraft

type ServiceDraft struct {
	Slug        string `json:"slug"`
	Name        string `json:"name"`
	Description string `json:"description"`
}

type UpdateRequest

type UpdateRequest struct {
	ID      uint                  `uri:"id" json:"-" binding:"required"`
	Service ServiceDocumentUpdate `json:"service" binding:"required"`
	Routes  []RouteDocumentUpdate `json:"routes" binding:"required"`
}

type UpstreamDraft

type UpstreamDraft struct {
	Name           string                              `json:"name" binding:"required,max=64"`
	BaseURL        string                              `json:"base_url"`
	Weight         int                                 `json:"weight"`
	Priority       int                                 `json:"priority"`
	AuthType       models.APIUpstreamAuthType          `json:"auth_type"`
	Credential     *api_upstream.APIUpstreamCredential `json:"credential"`
	ProxyURL       *string                             `json:"proxy_url"`
	HeaderOverride map[string]string                   `json:"header_override"`
	Status         *int                                `json:"status"`
}

UpstreamDraft carries the non-document fields needed to create the first upstream. BaseURL is optional because a selected OpenAPI server supplies it; documents without servers require it in selectedUpstreamInput.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL