contract

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractContract

func ExtractContract(
	route extractor.RawRoute,
	fn ast.Node,
	info *types.Info,
	paramNames resolver.HandlerParamNames,
	pkgs []*packages.Package,
) (model.RequestDef, []model.ResponseDef, []string)

ExtractContract is the top-level orchestrator that calls all sub-extractors in order and assembles the complete request and response contract for a single endpoint.

fn should be either *ast.FuncDecl or *ast.FuncLit.

func ExtractHeaders

func ExtractHeaders(body *ast.BlockStmt, info *types.Info, paramNames resolver.HandlerParamNames) []model.ParamDef

ExtractHeaders walks a handler function body and detects header access patterns for both net/http and gin.

func ExtractPathParams

func ExtractPathParams(pattern string, fnBody *ast.BlockStmt, info *types.Info, paramNames resolver.HandlerParamNames) []model.ParamDef

ExtractPathParams parses {param} segments from a route pattern and produces an initial ParamDef list. If fnBody and info are provided, the handler body is scanned for type upgrade evidence (strconv.Atoi → integer, uuid.Parse → uuid).

func ExtractQueryParams

func ExtractQueryParams(body *ast.BlockStmt, info *types.Info, paramNames resolver.HandlerParamNames) []model.ParamDef

ExtractQueryParams walks a handler function body and detects query parameter access patterns for both net/http and gin.

func ExtractResponses

func ExtractResponses(body *ast.BlockStmt, info *types.Info, paramNames resolver.HandlerParamNames, pkgs []*packages.Package) ([]model.ResponseDef, []string)

ExtractResponses walks a handler function body and extracts all response definitions. For gin handlers, responses are co-located (easy). For net/http handlers, branch-aware pairing is used.

func ResolveStatusCode

func ResolveStatusCode(expr ast.Expr, info *types.Info) int

ResolveStatusCode resolves a status code expression to an integer. Uses go/constant for compile-time constants, falls back to known http.StatusXxx names. Returns -1 if unresolvable.

Types

type BodyResult

type BodyResult struct {
	BodyType       types.Type // The resolved type of the request body struct (nil if none)
	ContentType    string     // "application/json", "multipart/form-data", or combo
	IsMultipart    bool
	FileParams     []model.ParamDef // File params from FormFile calls
	BindQueryType  types.Type       // Struct type from ShouldBindQuery — promotes fields to QueryParams
	BindHeaderType types.Type       // Struct type from ShouldBindHeader — promotes fields to Headers
	Unresolved     []string         // Anything that couldn't be determined
}

BodyResult holds the outcome of request body extraction.

func ExtractBody

func ExtractBody(body *ast.BlockStmt, info *types.Info, paramNames resolver.HandlerParamNames) BodyResult

ExtractBody walks a handler function body and detects request body patterns for both net/http (json.NewDecoder/Unmarshal) and gin (ShouldBindJSON, etc.).

Jump to

Keyboard shortcuts

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