forked from go-openapi/spec
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored expander and ref resolver for readability (go-openapi#135)
[NO CHANGE IN FUNCTIONALITY] * refactored associated units tests for readability * reshuffled resolver funcs and associated tests to a dedicated file * removed panic() in ResolveRef (now return error) [used by go-swagger] Signed-off-by: Frederic BIDON <[email protected]>
- Loading branch information
Showing
12 changed files
with
1,243 additions
and
1,116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package spec | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDefaultResolutionCache(t *testing.T) { | ||
jsonSchema := MustLoadJSONSchemaDraft04() | ||
swaggerSchema := MustLoadSwagger20Schema() | ||
|
||
cache := defaultResolutionCache() | ||
|
||
sch, ok := cache.Get("not there") | ||
assert.False(t, ok) | ||
assert.Nil(t, sch) | ||
|
||
sch, ok = cache.Get("http://swagger.io/v2/schema.json") | ||
assert.True(t, ok) | ||
assert.Equal(t, swaggerSchema, sch) | ||
|
||
sch, ok = cache.Get("http://json-schema.org/draft-04/schema") | ||
assert.True(t, ok) | ||
assert.Equal(t, jsonSchema, sch) | ||
|
||
cache.Set("something", "here") | ||
sch, ok = cache.Get("something") | ||
assert.True(t, ok) | ||
assert.Equal(t, "here", sch) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package spec | ||
|
||
import "errors" | ||
|
||
var ( | ||
// ErrUnknownTypeForReference indicates that a resolved reference was found in an unsupported container type | ||
ErrUnknownTypeForReference = errors.New("unknown type for the resolved reference") | ||
|
||
// ErrResolveRefNeedsAPointer indicates that a $ref target must be a valid JSON pointer | ||
ErrResolveRefNeedsAPointer = errors.New("resolve ref: target needs to be a pointer") | ||
|
||
// ErrDerefUnsupportedType indicates that a resolved reference was found in an unsupported container type. | ||
// At the moment, $ref are supported only inside: schemas, parameters, responses, path items | ||
ErrDerefUnsupportedType = errors.New("deref: unsupported type") | ||
|
||
// ErrExpandUnsupportedType indicates that $ref expansion is attempted on some invalid type | ||
ErrExpandUnsupportedType = errors.New("expand: unsupported type. Input should be of type *Parameter or *Response") | ||
) |
Oops, something went wrong.