contract

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package contract 提供操作登记表与源码路由、Swagger 的开发期检查。 Package contract provides development-time checks between the operation registry, source routes, and Swagger.

Index

Constants

View Source
const (
	StatusOperation     = "operation"
	StatusException     = "exception"
	StatusHistoricalGap = "historical_gap"
)
View Source
const ReportVersion = 1

Variables

This section is empty.

Functions

func FindNewHistoricalGaps

func FindNewHistoricalGaps(previous Report, current Report) []string

FindNewHistoricalGaps 返回当前报告中新出现且没有登记或例外说明的路由。 FindNewHistoricalGaps returns routes that newly appear without an operation or exception entry.

func MarshalReport

func MarshalReport(report Report) ([]byte, error)

MarshalReport 生成带稳定缩进和结尾换行的 JSON。 MarshalReport produces JSON with stable indentation and a trailing newline.

Types

type Report

type Report struct {
	Version      int           `json:"version"`
	BaselineDate string        `json:"baseline_date,omitempty"`
	Summary      ReportSummary `json:"summary"`
	Routes       []RouteStatus `json:"routes"`
	SwaggerOnly  []Route       `json:"swagger_only,omitempty"`
}

Report 是路由、Swagger 和操作登记状态的可重复生成报告。 Report is a reproducible report of routes, Swagger coverage, and operation registration status.

func BuildReport

func BuildReport(repositoryRoot string, specs []operation.OperationSpec, exceptions []operation.RouteException) (Report, error)

BuildReport 构建当前仓库的操作契约报告。 BuildReport builds the current repository operation-contract report.

func LoadReport

func LoadReport(filename string) (Report, error)

LoadReport 从 JSON 文件读取基线报告。 LoadReport loads a baseline report from a JSON file.

type ReportSummary

type ReportSummary struct {
	RouteCount            int `json:"route_count"`
	SwaggerPathCount      int `json:"swagger_path_count"`
	SwaggerOperationCount int `json:"swagger_operation_count"`
	SwaggerDocumented     int `json:"swagger_documented_routes"`
	RegisteredOperations  int `json:"registered_operations"`
	RouteExceptions       int `json:"route_exceptions"`
	HistoricalGaps        int `json:"historical_gaps"`
}

ReportSummary 汇总报告中的关键计数。 ReportSummary summarizes the key counts in a report.

type Route

type Route struct {
	Method string `json:"method"`
	Path   string `json:"path"`
	Source string `json:"source"`
}

Route 描述从 Gin 路由注册代码中读取到的一条路由。 Route describes one route extracted from Gin registration source code.

func CollectRoutes

func CollectRoutes(repositoryRoot string) ([]Route, error)

CollectRoutes 读取仓库当前的 /api/v1 Gin 路由注册。 CollectRoutes reads the repository's current /api/v1 Gin route registrations.

type RouteStatus

type RouteStatus struct {
	Method      string                  `json:"method"`
	Path        string                  `json:"path"`
	Source      string                  `json:"source"`
	Status      string                  `json:"status"`
	OperationID string                  `json:"operation_id,omitempty"`
	Mode        operation.OperationMode `json:"mode,omitempty"`
	Swagger     bool                    `json:"swagger"`
}

RouteStatus 描述一条源码路由当前的登记和 Swagger 状态。 RouteStatus describes the current registry and Swagger status of one source route.

Jump to

Keyboard shortcuts

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