-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_schema_bundle.go
More file actions
46 lines (39 loc) · 1.31 KB
/
json_schema_bundle.go
File metadata and controls
46 lines (39 loc) · 1.31 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
package main
import (
"github.com/xeipuuv/gojsonreference"
"path/filepath"
"strings"
)
type JsonSchemaBundle struct {
Name string
Ref *gojsonreference.JsonReference
Schema JsonSchema
IsReferred bool
HasParent bool
}
func NewJsonSchemaBundle(ref *gojsonreference.JsonReference, schema JsonSchema, isReferred bool) JsonSchemaBundle {
var name string
if schema.Id != "" {
name = schema.Id
} else {
basename := filepath.Base(ref.GetUrl().String())
name = strings.Replace(basename, filepath.Ext(basename), "", 1)
}
return JsonSchemaBundle{name, ref, schema, isReferred, false}
}
func NewNamedChildJsonSchemaBundle(bundle JsonSchemaBundle, name string, schema JsonSchema) JsonSchemaBundle {
return JsonSchemaBundle{name, bundle.Ref, schema, bundle.IsReferred, true}
}
func NewChildJsonSchemaBundle(bundle JsonSchemaBundle, schema JsonSchema) JsonSchemaBundle {
return JsonSchemaBundle{bundle.Name, bundle.Ref, schema, bundle.IsReferred, true}
}
func (b JsonSchemaBundle) GetRelativeJsonReference(path string) (gojsonreference.JsonReference, error) {
ref, err := gojsonreference.NewJsonReference(path)
if err != nil {
return ref, err
}
return NewRelativeJsonReference(b.Ref, &ref)
}
func (b JsonSchemaBundle) IsSameRef(bundle JsonSchemaBundle) bool {
return b.Ref.GetUrl() == bundle.Ref.GetUrl()
}