bump(github.com/go-openapi/spec): 7abd5745472fff5eb3685386d5fb8bf38683154d

This commit is contained in:
Nikhita Raghunath
2017-09-19 11:25:48 +05:30
parent d08047c240
commit 9968c18a6c
51 changed files with 1597 additions and 574 deletions

View File

@@ -55,7 +55,7 @@ func (r *Ref) RemoteURI() string {
}
// IsValidURI returns true when the url the ref points to can be found
func (r *Ref) IsValidURI() bool {
func (r *Ref) IsValidURI(basepaths ...string) bool {
if r.String() == "" {
return true
}
@@ -81,14 +81,18 @@ func (r *Ref) IsValidURI() bool {
// check for local file
pth := v
if r.HasURLPathOnly {
p, e := filepath.Abs(pth)
base := "."
if len(basepaths) > 0 {
base = filepath.Dir(filepath.Join(basepaths...))
}
p, e := filepath.Abs(filepath.ToSlash(filepath.Join(base, pth)))
if e != nil {
return false
}
pth = p
}
fi, err := os.Stat(pth)
fi, err := os.Stat(filepath.ToSlash(pth))
if err != nil {
return false
}
@@ -116,25 +120,18 @@ func NewRef(refURI string) (Ref, error) {
return Ref{Ref: ref}, nil
}
// MustCreateRef creates a ref object but
// MustCreateRef creates a ref object but panics when refURI is invalid.
// Use the NewRef method for a version that returns an error.
func MustCreateRef(refURI string) Ref {
return Ref{Ref: jsonreference.MustCreateRef(refURI)}
}
// // NewResolvedRef creates a resolved ref
// func NewResolvedRef(refURI string, data interface{}) Ref {
// return Ref{
// Ref: jsonreference.MustCreateRef(refURI),
// Resolved: data,
// }
// }
// MarshalJSON marshals this ref into a JSON object
func (r Ref) MarshalJSON() ([]byte, error) {
str := r.String()
if str == "" {
if r.IsRoot() {
return []byte(`{"$ref":"#"}`), nil
return []byte(`{"$ref":""}`), nil
}
return []byte("{}"), nil
}