schema

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0, Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package schema 提供轻量 JSON Schema 子集校验能力

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatSchemaError

func FormatSchemaError(result validate.CompareResult) string

FormatSchemaError 提取 schema 校验错误消息

func ValidateJSONSchema

func ValidateJSONSchema(data, schema any) validate.CompareResult

ValidateJSONSchema 校验数据是否符合 schema

func ValidateStructWithSchema

func ValidateStructWithSchema(structData, schema any) validate.CompareResult

ValidateStructWithSchema 校验结构体或 map 是否符合 schema

Types

type JSONSchema

type JSONSchema struct {
	Type                 string                `json:"type,omitempty"`
	Required             []string              `json:"required,omitempty"`
	Properties           map[string]JSONSchema `json:"properties,omitempty"`
	Items                *JSONSchema           `json:"items,omitempty"`
	Enum                 []any                 `json:"enum,omitempty"`
	MinLength            *int                  `json:"minLength,omitempty"`
	MaxLength            *int                  `json:"maxLength,omitempty"`
	Minimum              *float64              `json:"minimum,omitempty"`
	Maximum              *float64              `json:"maximum,omitempty"`
	AdditionalProperties bool                  `json:"additionalProperties,omitempty"`
}

JSONSchema 描述 Argus 支持的 JSON Schema 子集

func QuickSchema

func QuickSchema(properties map[string]string, required ...string) JSONSchema

QuickSchema 根据字段类型快速创建对象 schema

type SchemaBuilder

type SchemaBuilder struct {
	// contains filtered or unexported fields
}

SchemaBuilder 提供链式构建 JSONSchema 的能力

func NewSchemaBuilder

func NewSchemaBuilder() *SchemaBuilder

NewSchemaBuilder 创建 SchemaBuilder

func (*SchemaBuilder) ArrayProperty

func (b *SchemaBuilder) ArrayProperty(name string, items JSONSchema) *SchemaBuilder

ArrayProperty 增加数组属性

func (*SchemaBuilder) Build

func (b *SchemaBuilder) Build() JSONSchema

Build 返回 JSONSchema

func (*SchemaBuilder) BuildJSON

func (b *SchemaBuilder) BuildJSON() string

BuildJSON 返回 JSON 字符串

func (*SchemaBuilder) Enum

func (b *SchemaBuilder) Enum(values ...any) *SchemaBuilder

Enum 设置枚举值

func (*SchemaBuilder) NumberProperty

func (b *SchemaBuilder) NumberProperty(name string, min, max *float64) *SchemaBuilder

NumberProperty 增加数值属性

func (*SchemaBuilder) Property

func (b *SchemaBuilder) Property(name string, propSchema JSONSchema) *SchemaBuilder

Property 增加属性 schema

func (*SchemaBuilder) Required

func (b *SchemaBuilder) Required(fields ...string) *SchemaBuilder

Required 设置必填字段

func (*SchemaBuilder) StringProperty

func (b *SchemaBuilder) StringProperty(name string, minLen, maxLen int) *SchemaBuilder

StringProperty 增加字符串属性

func (*SchemaBuilder) Type

func (b *SchemaBuilder) Type(t string) *SchemaBuilder

Type 设置 schema 类型

Jump to

Keyboard shortcuts

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