@@ -78,14 +78,14 @@ func (l SchemeURLLoader) Load(url string) (any, error) {
78
78
//go:embed metaschemas
79
79
var metaFS embed.FS
80
80
81
- func loadMeta (url string ) (any , error ) {
81
+ func openMeta (url string ) (fs. File , error ) {
82
82
u , meta := strings .CutPrefix (url , "http://json-schema.org/" )
83
83
if ! meta {
84
84
u , meta = strings .CutPrefix (url , "https://json-schema.org/" )
85
85
}
86
86
if meta {
87
87
if u == "schema" {
88
- return loadMeta (draftLatest .url )
88
+ return openMeta (draftLatest .url )
89
89
}
90
90
f , err := metaFS .Open ("metaschemas/" + u )
91
91
if err != nil {
@@ -94,9 +94,34 @@ func loadMeta(url string) (any, error) {
94
94
}
95
95
return nil , err
96
96
}
97
- return UnmarshalJSON ( f )
97
+ return f , err
98
98
}
99
99
return nil , nil
100
+
101
+ }
102
+
103
+ func isMeta (url string ) bool {
104
+ f , err := openMeta (url )
105
+ if err != nil {
106
+ return true
107
+ }
108
+ if f != nil {
109
+ f .Close ()
110
+ return true
111
+ }
112
+ return false
113
+ }
114
+
115
+ func loadMeta (url string ) (any , error ) {
116
+ f , err := openMeta (url )
117
+ if err != nil {
118
+ return nil , err
119
+ }
120
+ if f == nil {
121
+ return nil , nil
122
+ }
123
+ defer f .Close ()
124
+ return UnmarshalJSON (f )
100
125
}
101
126
102
127
// --
@@ -106,11 +131,12 @@ type defaultLoader struct {
106
131
loader URLLoader
107
132
}
108
133
109
- func (l * defaultLoader ) add (url url , doc any ) {
134
+ func (l * defaultLoader ) add (url url , doc any ) bool {
110
135
if _ , ok := l .docs [url ]; ok {
111
- return
136
+ return false
112
137
}
113
138
l .docs [url ] = doc
139
+ return true
114
140
}
115
141
116
142
func (l * defaultLoader ) load (url url ) (any , error ) {
@@ -214,6 +240,16 @@ func (e *UnsupportedURLSchemeError) Error() string {
214
240
215
241
// --
216
242
243
+ type ResourceExistsError struct {
244
+ url string
245
+ }
246
+
247
+ func (e * ResourceExistsError ) Error () string {
248
+ return fmt .Sprintf ("resource for %q already exists" , e .url )
249
+ }
250
+
251
+ // --
252
+
217
253
// UnmarshalJSON unmarshals into [any] without losing
218
254
// number precision using [json.Number].
219
255
func UnmarshalJSON (r io.Reader ) (any , error ) {
0 commit comments