Convert all Schema YAML to JSON

Signed-off-by: Ian Howell <ian.howell0@gmail.com>
pull/5350/head
Ian Howell 7 years ago
parent 44017710e7
commit a4cb9582aa

@ -0,0 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"addresses": {
"description": "List of addresses",
"items": {
"properties": {
"city": {
"type": "string"
},
"number": {
"type": "number"
},
"street": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"age": {
"description": "Age",
"minimum": 0,
"type": "integer"
},
"employmentInfo": {
"properties": {
"salary": {
"minimum": 0,
"type": "number"
},
"title": {
"type": "string"
}
},
"required": [
"salary"
],
"type": "object"
},
"firstname": {
"description": "First name",
"type": "string"
},
"lastname": {
"type": "string"
},
"likesCoffee": {
"type": "boolean"
},
"phoneNumbers": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"firstname",
"lastname",
"addresses",
"employmentInfo"
],
"title": "Values",
"type": "object"
}

@ -1,46 +0,0 @@
$schema: http://json-schema.org/draft-07/schema#
title: Values
type: object
properties:
firstname:
description: First name
type: string
lastname:
type: string
likesCoffee:
type: boolean
age:
description: Age
type: integer
minimum: 0
employmentInfo:
type: object
properties:
salary:
type: number
minimum: 0
title:
type: string
required:
- salary
addresses:
description: List of addresses
type: array
items:
type: object
properties:
city:
type: string
street:
type: string
number:
type: number
phoneNumbers:
type: array
items:
type: string
required:
- firstname
- lastname
- addresses
- employmentInfo

@ -0,0 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"addresses": {
"description": "List of addresses",
"items": {
"properties": {
"city": {
"type": "string"
},
"number": {
"type": "number"
},
"street": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"age": {
"description": "Age",
"minimum": 0,
"type": "integer"
},
"employmentInfo": {
"properties": {
"salary": {
"minimum": 0,
"type": "number"
},
"title": {
"type": "string"
}
},
"required": [
"salary"
],
"type": "object"
},
"firstname": {
"description": "First name",
"type": "string"
},
"lastname": {
"type": "string"
},
"likesCoffee": {
"type": "boolean"
},
"phoneNumbers": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"firstname",
"lastname",
"addresses",
"employmentInfo"
],
"title": "Values",
"type": "object"
}

@ -1,46 +0,0 @@
$schema: http://json-schema.org/draft-07/schema#
title: Values
type: object
properties:
firstname:
description: First name
type: string
lastname:
type: string
likesCoffee:
type: boolean
age:
description: Age
type: integer
minimum: 0
employmentInfo:
type: object
properties:
salary:
type: number
minimum: 0
title:
type: string
required:
- salary
addresses:
description: List of addresses
type: array
items:
type: object
properties:
city:
type: string
street:
type: string
number:
type: number
phoneNumbers:
type: array
items:
type: string
required:
- firstname
- lastname
- addresses
- employmentInfo

@ -26,7 +26,7 @@ wordpress/
LICENSE # OPTIONAL: A plain text file containing the license for the chart LICENSE # OPTIONAL: A plain text file containing the license for the chart
README.md # OPTIONAL: A human-readable README file README.md # OPTIONAL: A human-readable README file
values.yaml # The default configuration values for this chart values.yaml # The default configuration values for this chart
values.schema.yaml # OPTIONAL: A JSON Schema for imposing a structure on the values.yaml file values.schema.json # OPTIONAL: A JSON Schema for imposing a structure on the values.yaml file
charts/ # A directory containing any charts upon which this chart depends. charts/ # A directory containing any charts upon which this chart depends.
templates/ # A directory of templates that, when combined with values, templates/ # A directory of templates that, when combined with values,
# will generate valid Kubernetes manifest files. # will generate valid Kubernetes manifest files.
@ -767,35 +767,46 @@ Also, global variables of parent charts take precedence over the global variable
### Schema Files ### Schema Files
Sometimes, a chart maintainer might want to define a structure on their values. Sometimes, a chart maintainer might want to define a structure on their values.
This can be done by defining a schema in the `values.schema.yaml` file. A This can be done by defining a schema in the `values.schema.json` file. A
schema is the yaml representation of a [JSON Schema](https://json-schema.org/). schema is represented as a [JSON Schema](https://json-schema.org/).
It might look something like this: It might look something like this:
```yaml ```json
$schema: http://json-schema.org/draft-07/schema# {
title: Values "$schema": "http://json-schema.org/draft-07/schema#",
type: object "properties": {
properties: "image": {
name: "description": "Container Image",
description: Service name "properties": {
type: string "repo": {
protocol: "type": "string"
type: string },
port: "tag": {
description: Port "type": "string"
type: integer }
minimum: 0 },
image: "type": "object"
description: Container Image },
type: object "name": {
properties: "description": "Service name",
repo: "type": "string"
type: string },
tag: "port": {
type: string "description": "Port",
required: "minimum": 0,
- protocol "type": "integer"
- port },
"protocol": {
"type": "string"
}
},
"required": [
"protocol",
"port"
],
"title": "Values",
"type": "object"
}
``` ```
This schema will be applied to the values to validate it. Validation occurs This schema will be applied to the values to validate it. Validation occurs

@ -90,7 +90,7 @@ func LoadFiles(files []*BufferedFile) (*chart.Chart, error) {
return c, errors.Wrap(err, "cannot load values.yaml") return c, errors.Wrap(err, "cannot load values.yaml")
} }
c.RawValues = f.Data c.RawValues = f.Data
case f.Name == "values.schema.yaml": case f.Name == "values.schema.json":
c.Schema = f.Data c.Schema = f.Data
case strings.HasPrefix(f.Name, "templates/"): case strings.HasPrefix(f.Name, "templates/"):
c.Templates = append(c.Templates, &chart.File{Name: f.Name, Data: f.Data}) c.Templates = append(c.Templates, &chart.File{Name: f.Name, Data: f.Data})

@ -80,7 +80,7 @@ icon: https://example.com/64x64.png
Data: []byte("var: some values"), Data: []byte("var: some values"),
}, },
{ {
Name: "values.schema.yaml", Name: "values.schema.json",
Data: []byte("type: Values"), Data: []byte("type: Values"),
}, },
{ {

@ -0,0 +1,67 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"properties": {
"addresses": {
"description": "List of addresses",
"items": {
"properties": {
"city": {
"type": "string"
},
"number": {
"type": "number"
},
"street": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"age": {
"description": "Age",
"minimum": 0,
"type": "integer"
},
"employmentInfo": {
"properties": {
"salary": {
"minimum": 0,
"type": "number"
},
"title": {
"type": "string"
}
},
"required": [
"salary"
],
"type": "object"
},
"firstname": {
"description": "First name",
"type": "string"
},
"lastname": {
"type": "string"
},
"likesCoffee": {
"type": "boolean"
},
"phoneNumbers": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"firstname",
"lastname",
"addresses",
"employmentInfo"
],
"title": "Values",
"type": "object"
}

@ -1,46 +0,0 @@
$schema: http://json-schema.org/draft-07/schema#
title: Values
type: object
properties:
firstname:
description: First name
type: string
lastname:
type: string
likesCoffee:
type: boolean
age:
description: Age
type: integer
minimum: 0
employmentInfo:
type: object
properties:
salary:
type: number
minimum: 0
title:
type: string
required:
- salary
addresses:
description: List of addresses
type: array
items:
type: object
properties:
city:
type: string
street:
type: string
number:
type: number
phoneNumbers:
type: array
items:
type: string
required:
- firstname
- lastname
- addresses
- employmentInfo

@ -166,7 +166,7 @@ func TestValidateAgainstSchema(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Error reading YAML file: %s", err) t.Fatalf("Error reading YAML file: %s", err)
} }
schema, err := ioutil.ReadFile("./testdata/test-values.schema.yaml") schema, err := ioutil.ReadFile("./testdata/test-values.schema.json")
if err != nil { if err != nil {
t.Fatalf("Error reading YAML file: %s", err) t.Fatalf("Error reading YAML file: %s", err)
} }
@ -181,7 +181,7 @@ func TestValidateAgainstSchemaNegative(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Error reading YAML file: %s", err) t.Fatalf("Error reading YAML file: %s", err)
} }
schema, err := ioutil.ReadFile("./testdata/test-values.schema.yaml") schema, err := ioutil.ReadFile("./testdata/test-values.schema.json")
if err != nil { if err != nil {
t.Fatalf("Error reading YAML file: %s", err) t.Fatalf("Error reading YAML file: %s", err)
} }
@ -480,53 +480,73 @@ chapter:
} }
func TestReadSchema(t *testing.T) { func TestReadSchema(t *testing.T) {
schemaTest := `# Test YAML parse schemaTest := `{
$schema: http://json-schema.org/draft-07/schema# "$schema": "http://json-schema.org/draft-07/schema#",
title: Values "properties": {
type: object "addresses": {
properties: "description": "List of addresses",
firstname: "items": {
description: First name "properties": {
type: string "city": {
lastname: "type": "string"
type: string },
likesCoffee: "number": {
type: boolean "type": "number"
age: },
description: Age "street": {
type: integer "type": "string"
minimum: 0 }
employmentInfo: },
type: object "type": "object"
properties: },
salary: "type": "array"
type: number },
minimum: 0 "age": {
title: "description": "Age",
type: string "minimum": 0,
required: "type": "integer"
- salary },
addresses: "employmentInfo": {
description: List of addresses "properties": {
type: array "salary": {
items: "minimum": 0,
type: object "type": "number"
properties: },
city: "title": {
type: string "type": "string"
street: }
type: string },
number: "required": [
type: number "salary"
phoneNumbers: ],
type: array "type": "object"
items: },
type: string "firstname": {
required: "description": "First name",
- firstname "type": "string"
- lastname },
- addresses "lastname": {
- employmentInfo "type": "string"
},
"likesCoffee": {
"type": "boolean"
},
"phoneNumbers": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"firstname",
"lastname",
"addresses",
"employmentInfo"
],
"title": "Values",
"type": "object"
}
` `
data, err := ReadValues([]byte(schemaTest)) data, err := ReadValues([]byte(schemaTest))
if err != nil { if err != nil {

@ -55,7 +55,7 @@ func validateValuesFile(valuesPath string) error {
} }
ext := filepath.Ext(valuesPath) ext := filepath.Ext(valuesPath)
schemaPath := valuesPath[:len(valuesPath)-len(ext)] + ".schema.yaml" schemaPath := valuesPath[:len(valuesPath)-len(ext)] + ".schema.json"
schema, err := ioutil.ReadFile(schemaPath) schema, err := ioutil.ReadFile(schemaPath)
if len(schema) == 0 { if len(schema) == 0 {
return nil return nil

Loading…
Cancel
Save