openapi: Add validation logic

This allows validation of a yaml/json object against an openapi schema.
A lot more testing would be needed to validate the logic, and also this
is not plumbed in, so it can't be used by kubectl yet.
This commit is contained in:
Antoine Pelisse
2017-07-05 09:50:56 -07:00
parent eb735bfeb0
commit ba11c7370f
10 changed files with 838 additions and 8 deletions

View File

@@ -77,6 +77,10 @@ type Path struct {
key string
}
func NewPath(key string) Path {
return Path{key: key}
}
func (p *Path) Get() []string {
if p == nil {
return []string{}
@@ -92,7 +96,23 @@ func (p *Path) Len() int {
}
func (p *Path) String() string {
return strings.Join(p.Get(), ".")
return strings.Join(p.Get(), "")
}
// ArrayPath appends an array index and creates a new path
func (p *Path) ArrayPath(i int) Path {
return Path{
parent: p,
key: fmt.Sprintf("[%d]", i),
}
}
// FieldPath appends a field name and creates a new path
func (p *Path) FieldPath(field string) Path {
return Path{
parent: p,
key: fmt.Sprintf(".%s", field),
}
}
// BaseSchema holds data used by each types of schema.