-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
125 lines (108 loc) · 3.99 KB
/
Copy pathtypes.go
File metadata and controls
125 lines (108 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Package jsonstructure provides validators for JSON Structure schemas and instances.
package jsonstructure
import "fmt"
// ValidationResult represents the result of a validation operation.
type ValidationResult struct {
// IsValid indicates whether the validation passed.
IsValid bool `json:"isValid"`
// Errors contains validation errors (empty if valid).
Errors []ValidationError `json:"errors"`
// Warnings contains validation warnings (non-fatal issues).
Warnings []ValidationError `json:"warnings"`
}
// ValidationError represents a single validation error.
type ValidationError struct {
// Code is the error code for programmatic handling.
Code string `json:"code"`
// Message is a human-readable error description.
Message string `json:"message"`
// Path is the JSON Pointer path to the error location.
Path string `json:"path,omitempty"`
// Severity is the severity of the validation message.
Severity ValidationSeverity `json:"severity,omitempty"`
// Location is the source location (line/column) of the error.
Location JsonLocation `json:"location,omitempty"`
// SchemaPath is the path in the schema that caused the error.
SchemaPath string `json:"schemaPath,omitempty"`
}
// String returns a formatted string representation of the error.
func (e ValidationError) String() string {
result := ""
if e.Path != "" {
result += e.Path + " "
}
if e.Location.IsKnown() {
result += fmt.Sprintf("(%d:%d) ", e.Location.Line, e.Location.Column)
}
result += "[" + e.Code + "] " + e.Message
if e.SchemaPath != "" {
result += " (schema: " + e.SchemaPath + ")"
}
return result
}
// SchemaValidatorOptions configures schema validation.
type SchemaValidatorOptions struct {
// Extended enables extended validation features.
Extended bool
// AllowDollar allows $ in property names (required for validating metaschemas).
AllowDollar bool
// AllowImport enables processing of $import/$importdefs.
AllowImport bool
// ExternalSchemas maps URIs to schema objects for import resolution.
// Each schema should have a '$id' field matching the import URI.
ExternalSchemas map[string]interface{}
// MaxValidationDepth is the maximum depth for validation recursion. Default is 64.
MaxValidationDepth int
// WarnOnUnusedExtensionKeywords controls whether to emit warnings when extension
// keywords are used without being enabled via $schema or $uses. Default is true.
WarnOnUnusedExtensionKeywords *bool
}
// InstanceValidatorOptions configures instance validation.
type InstanceValidatorOptions struct {
// Extended enables extended validation features (minLength, pattern, etc.).
Extended bool
// AllowImport enables processing of $import/$importdefs.
AllowImport bool
// MaxValidationDepth is the maximum depth for validation recursion. Default is 64.
MaxValidationDepth int
}
// PrimitiveTypes lists all primitive types supported by JSON Structure Core.
var PrimitiveTypes = []string{
"string", "boolean", "null",
"int8", "uint8", "int16", "uint16", "int32", "uint32",
"int64", "uint64", "int128", "uint128",
"float", "float8", "double", "decimal",
"number", "integer",
"date", "datetime", "time", "duration",
"uuid", "uri", "binary", "jsonpointer",
}
// CompoundTypes lists all compound types supported by JSON Structure Core.
var CompoundTypes = []string{
"object", "array", "set", "map", "tuple", "choice", "any",
}
// AllTypes lists all valid JSON Structure types.
var AllTypes = append(append([]string{}, PrimitiveTypes...), CompoundTypes...)
// NumericTypes lists all numeric types.
var NumericTypes = []string{
"number", "integer", "float", "double", "decimal", "float8",
"int8", "uint8", "int16", "uint16", "int32", "uint32",
"int64", "uint64", "int128", "uint128",
}
// isValidType checks if a type name is valid.
func isValidType(t string) bool {
for _, valid := range AllTypes {
if t == valid {
return true
}
}
return false
}
// isNumericType checks if a type is numeric.
func isNumericType(t string) bool {
for _, num := range NumericTypes {
if t == num {
return true
}
}
return false
}