Golang JSON schema validation libraries validate that required fields on the schema are present in the service request/response.
I need to validate that any field in a service request or response must be a property on the schema. If a property in the payload does not exist in the schema, the validation should fail.
For example: a GET response:
{
"pet": "dog",
"name": "Scooby",
"licence": "123-123"
}
In my sample JSON schema, none of the fields are required. However, if I changed the field "pet" to "petBreed" in my service, it will not be caught by a JSON schema validator (e.g. https://github.com/xeipuuv/gojsonschema).
Making all fields required is not an option. Can anyone suggest a library in Go that will:
- validate that all the response fields are in the schema
- not fail if a field from the schema isn't in the response