Documentation
¶
Index ¶
- Constants
- Variables
- func IsSchemaError(err error) bool
- func IsUnmarshalError(err error) bool
- func NewSchemaError(message string, path string, simplifyFunc SimplifyFunc) error
- type KeywordValidatorFunc
- type Schema
- func ParseSchema(jsonStr string) (Schema, error)
- func SimplifyDefault(schema Schema, _ schemaPath) Schema
- func SimplifyNegativeVal(schema Schema, path schemaPath) Schema
- func SimplifyRemoveAdditionalProperties(schema Schema, path schemaPath) Schema
- func SimplifyRemoveAnyOf(schema Schema, path schemaPath) Schema
- func SimplifyRemoveConstraints(schema Schema, path schemaPath) Schema
- func SimplifyRemoveDefs(schema Schema, path schemaPath) Schema
- func SimplifyRemoveDefsEmptySubSchema(schema Schema, path schemaPath) Schema
- func SimplifyRemoveDescription(schema Schema, path schemaPath) Schema
- func SimplifyRemoveDuplicateType(schema Schema, path schemaPath) Schema
- func SimplifyRemoveEnum(schema Schema, path schemaPath) Schema
- func SimplifyRemoveID(schema Schema, path schemaPath) Schema
- func SimplifyRemoveItems(schema Schema, path schemaPath) Schema
- func SimplifyRemoveParentSchema(schema Schema, path schemaPath) Schema
- func SimplifyRemovePattern(schema Schema, path schemaPath) Schema
- func SimplifyRemoveProperties(schema Schema, path schemaPath) Schema
- func SimplifyRemoveRef(schema Schema, path schemaPath) Schema
- func SimplifyRemoveRequired(schema Schema, path schemaPath) Schema
- func SimplifyRemoveSubSchema(schema Schema, path schemaPath) Schema
- func SimplifyRemoveType(schema Schema, path schemaPath) Schema
- type SchemaDict
- type SchemaError
- type SchemaList
- type SchemaValidatorConfig
- type SchemaValidatorOption
- func WithMaxAnyOfItems(max int) SchemaValidatorOption
- func WithMaxEnumItems(max int) SchemaValidatorOption
- func WithMaxEnumStringCheckThreshold(max int) SchemaValidatorOption
- func WithMaxEnumStringLength(max int) SchemaValidatorOption
- func WithMaxSchemaDepth(max int) SchemaValidatorOption
- func WithMaxSchemaSize(max int) SchemaValidatorOption
- func WithMaxTotalPropertiesKeysNum(max int) SchemaValidatorOption
- func WithValidateLevel(level ValidateLevel) SchemaValidatorOption
- type SimplifyFunc
- type UnmarshalError
- type ValidateLevel
Constants ¶
View Source
const ( Type = "type" Properties = "properties" AdditionalProperties = "additionalProperties" Items = "items" Enum = "enum" Required = "required" AnyOf = "anyOf" Description = "description" Defs = "$defs" Ref = "$ref" Title = "title" Id = "$id" Default = "default" Pattern = "pattern" MaxLength = "maxLength" MinLength = "minLength" Maximum = "maximum" Minimum = "minimum" MaxItems = "maxItems" MinItems = "minItems" String = "string" Number = "number" Integer = "integer" Boolean = "boolean" Null = "null" Array = "array" Object = "object" Root = "root" )
Variables ¶
View Source
var ( // Valid types and supported types ValidTypes = map[string]bool{ "string": true, "number": true, "integer": true, "boolean": true, "null": true, "array": true, "object": true, } // Common keywords CommonKeywords = map[string]bool{ "description": true, "title": true, } // Allowed keywords for different types ObjectAllowedKeywords = mergeMaps(map[string]bool{ "type": true, "properties": true, "required": true, "additionalProperties": true, "$ref": true, "anyOf": true, "default": true, }, CommonKeywords) ArrayAllowedKeywords = mergeMaps(map[string]bool{ "type": true, "items": true, "minItems": true, "maxItems": true, "$ref": true, "default": true, }, CommonKeywords) StringAllowedKeywords = mergeMaps(map[string]bool{ "type": true, "minLength": true, "maxLength": true, "pattern": true, "enum": true, "default": true, }, CommonKeywords) BooleanAllowedKeywords = mergeMaps(map[string]bool{ "type": true, "enum": true, "default": true, }, CommonKeywords) NullAllowedKeywords = mergeMaps(map[string]bool{ "type": true, "enum": true, "default": true, }, CommonKeywords) NumberAllowedKeywords = mergeMaps(map[string]bool{ "type": true, "minimum": true, "maximum": true, "enum": true, "default": true, }, CommonKeywords) TopLevelOnlyKeywords = map[string]bool{ "$defs": true, "$id": true, } // Contexts where $ref is allowed, "properties", "$defs", "root" will be processed independently RefAllowedContexts = map[string]bool{ "additionalProperties": true, "anyOf": true, "items": true, } // currently supported keywords SupportedKeywords = map[string]bool{ "type": true, "properties": true, "additionalProperties": true, "items": true, "enum": true, "required": true, "anyOf": true, "description": true, "$defs": true, "$ref": true, "title": true, "$id": true, "default": true, "maxLength": true, "minLength": true, "maximum": true, "minimum": true, "maxItems": true, "minItems": true, } // will be supported in the future FutureKeywords = map[string]bool{ "pattern": true, } InvalidPropertyNames = map[string]bool{ "$defs": true, "$ref": true, "anyOf": true, "required": true, "additionalProperties": true, } )
Functions ¶
func IsSchemaError ¶
func IsUnmarshalError ¶
func NewSchemaError ¶
func NewSchemaError(message string, path string, simplifyFunc SimplifyFunc) error
Types ¶
type KeywordValidatorFunc ¶
type Schema ¶
func ParseSchema ¶
func SimplifyDefault ¶
func SimplifyNegativeVal ¶
func SimplifyRemoveAnyOf ¶
func SimplifyRemoveDefs ¶
func SimplifyRemoveEnum ¶
func SimplifyRemoveID ¶
func SimplifyRemoveItems ¶
func SimplifyRemovePattern ¶
func SimplifyRemoveRef ¶
func SimplifyRemoveRequired ¶
func SimplifyRemoveSubSchema ¶
func SimplifyRemoveType ¶
func (Schema) Canonical ¶
Canonical returns a schema representation that conforms to Moonshot AI server requirements. It uses `ultra` validation level, which is the most permissive level supported by the enforcer-server. If the original schema has issues, it returns a simplified schema.
func (Schema) Validate ¶
func (s Schema) Validate(options ...SchemaValidatorOption) error
type SchemaDict ¶
type SchemaError ¶
type SchemaError struct {
Path string `json:"path,omitempty"`
Message string `json:"message,omitempty"`
SimplifyFunc SimplifyFunc `json:"-"`
}
func (*SchemaError) Error ¶
func (e *SchemaError) Error() string
type SchemaList ¶
type SchemaList = []any
type SchemaValidatorConfig ¶
type SchemaValidatorConfig struct {
ValidateLevel ValidateLevel `json:"validateLevel,omitempty"`
MaxEnumItems int `json:"maxEnumItems,omitempty"`
MaxEnumStringLength int `json:"maxEnumStringLength,omitempty"`
MaxEnumStringCheckThreshold int `json:"maxEnumStringCheckThreshold,omitempty"`
MaxAnyOfItems int `json:"maxAnyOfItems,omitempty"`
MaxSchemaDepth int `json:"maxSchemaDepth,omitempty"`
MaxSchemaSize int `json:"maxSchemaSize,omitempty"`
MaxTotalPropertiesKeysNum int `json:"maxTotalPropertiesKeysNum,omitempty"`
}
func DefaultValidatorConfig ¶
func DefaultValidatorConfig() SchemaValidatorConfig
func (*SchemaValidatorConfig) IsGreaterThanStrict ¶ added in v0.1.4
func (c *SchemaValidatorConfig) IsGreaterThanStrict() bool
func (*SchemaValidatorConfig) IsLite ¶
func (c *SchemaValidatorConfig) IsLite() bool
func (*SchemaValidatorConfig) IsLoose ¶
func (c *SchemaValidatorConfig) IsLoose() bool
func (*SchemaValidatorConfig) IsStrict ¶
func (c *SchemaValidatorConfig) IsStrict() bool
func (*SchemaValidatorConfig) IsTest ¶
func (c *SchemaValidatorConfig) IsTest() bool
do not use in production
func (*SchemaValidatorConfig) IsUltra ¶ added in v0.1.3
func (c *SchemaValidatorConfig) IsUltra() bool
type SchemaValidatorOption ¶
type SchemaValidatorOption func(*SchemaValidatorConfig)
func WithMaxAnyOfItems ¶
func WithMaxAnyOfItems(max int) SchemaValidatorOption
WithMaxAnyOfItems set max anyOf items
func WithMaxEnumItems ¶
func WithMaxEnumItems(max int) SchemaValidatorOption
WithMaxEnumItems set max enum items
func WithMaxEnumStringCheckThreshold ¶
func WithMaxEnumStringCheckThreshold(max int) SchemaValidatorOption
WithMaxEnumStringCheckThreshold set max enum string check threshold
func WithMaxEnumStringLength ¶
func WithMaxEnumStringLength(max int) SchemaValidatorOption
WithMaxEnumStringLength set max enum string length
func WithMaxSchemaDepth ¶
func WithMaxSchemaDepth(max int) SchemaValidatorOption
WithMaxSchemaDepth set max schema depth
func WithMaxSchemaSize ¶
func WithMaxSchemaSize(max int) SchemaValidatorOption
WithMaxSchemaSize set max schema size
func WithMaxTotalPropertiesKeysNum ¶
func WithMaxTotalPropertiesKeysNum(max int) SchemaValidatorOption
WithMaxTotalPropertiesKeysNum set max total properties keys num
func WithValidateLevel ¶
func WithValidateLevel(level ValidateLevel) SchemaValidatorOption
type SimplifyFunc ¶
func SimplifyRemoveSchemaKeys ¶ added in v0.1.8
func SimplifyRemoveSchemaKeys(keys []string) SimplifyFunc
deletes the given keys from the schema at path
type UnmarshalError ¶
type UnmarshalError struct {
Err error `json:"error,omitempty"`
}
func NewUnmarshalError ¶
func NewUnmarshalError(err error) *UnmarshalError
func (*UnmarshalError) Error ¶
func (e *UnmarshalError) Error() string
type ValidateLevel ¶
type ValidateLevel string
const ( ValidateLevelDefault ValidateLevel = "default" // default == ultra ValidateLevelLoose ValidateLevel = "loose" ValidateLevelLite ValidateLevel = "lite" ValidateLevelStrict ValidateLevel = "strict" ValidateLevelUltra ValidateLevel = "ultra" ValidateLevelTest ValidateLevel = "test" // Do not use in production! )
Source Files
¶
Click to show internal directories.
Click to hide internal directories.