Merge branch 'master' into add-support-for-duration

This commit is contained in:
Yann Hamon 2025-05-12 10:46:23 +02:00 committed by GitHub
commit c6f80859ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 22151 additions and 9578 deletions

View file

@ -56,7 +56,7 @@ func (l *HTTPURLLoader) Load(url string) (any, error) {
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(body))
if err != nil {
return nil, err
return nil, NewNonJSONResponseError(err)
}
return s, nil

View file

@ -10,3 +10,13 @@ func NewNotFoundError(err error) *NotFoundError {
}
func (e *NotFoundError) Error() string { return e.err.Error() }
func (e *NotFoundError) Retryable() bool { return false }
type NonJSONResponseError struct {
err error
}
func NewNonJSONResponseError(err error) *NotFoundError {
return &NotFoundError{err}
}
func (e *NonJSONResponseError) Error() string { return e.err.Error() }
func (e *NonJSONResponseError) Retryable() bool { return false }

View file

@ -390,6 +390,10 @@ func downloadSchema(registries []registry.Registry, l jsonschema.SchemeURLLoader
if _, notfound := err.(*loader.NotFoundError); notfound {
continue
}
if _, nonJSONError := err.(*loader.NonJSONResponseError); nonJSONError {
continue
}
return nil, err
}

View file

@ -316,7 +316,7 @@ lastName: bar
}`),
false,
false,
Error,
Valid,
[]ValidationError{},
},
{
@ -361,7 +361,7 @@ lastName: bar
[]byte(`<html>error page</html>`),
true,
false,
Error,
Skipped,
[]ValidationError{},
},
{
@ -475,6 +475,9 @@ interval: test
return "", nil, loader.NewNotFoundError(nil)
}
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(testCase.schemaRegistry1))
if err != nil {
return "", s, loader.NewNonJSONResponseError(err)
}
return "", s, err
}),
newMockRegistry(func() (string, any, error) {
@ -482,6 +485,9 @@ interval: test
return "", nil, loader.NewNotFoundError(nil)
}
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(testCase.schemaRegistry2))
if err != nil {
return "", s, loader.NewNonJSONResponseError(err)
}
return "", s, err
}),
},
@ -550,6 +556,9 @@ age: not a number
regs: []registry.Registry{
newMockRegistry(func() (string, any, error) {
s, err := jsonschema.UnmarshalJSON(bytes.NewReader(schema))
if err != nil {
return "", s, loader.NewNonJSONResponseError(err)
}
return "", s, err
}),
},