Question related to yamlText not having the declared property in schema text
Closed this issue · 1 comments
Hi,
I am trying out the below and am expecting to see an error because the yamlText has a property "state" that is not defined in the schema text. Should I be expecting an error indicating "state" is not defined in schema? I want to be able to detect any properties that are not defined in schema but present in yamlText be indicated.
var yamlText = id: id1 name: joe state: married
var schemaText = { "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "status": {"type": "string"} }, "required": ["id", "name"], "optional": ["status" ] }
func main() {
fmt.Println(schemaText)
var m interface{}
err := yaml.Unmarshal([]byte(yamlText), &m)
if err != nil {
panic(err)
}
compiler := jsonschema.NewCompiler()
//compiler.Draft = jsonschema.Draft4
if err := compiler.AddResource("schema.json", strings.NewReader(schemaText)); err != nil {
panic(err)
}
schema, err := compiler.Compile("schema.json")
if err != nil {
panic(err)
}
if err := schema.ValidateInterface(m); err != nil {
panic(err)
}
}
Never mind, figured out that using "additionalProperties":false fixes my issue