ALPHA VERSION, APIs may changes.
A jsonnet validation follow json schema .
When hidden field __schema__
with json schema exists, will validate the object
local t = import 'github.com/jsonnetmod/types/t.libsonnet';
local Meta = {
__schema__:: {
type: 'object',
properties: {
name: { type: 'string' },
age: { type: 'string' },
},
required: ['name']
},
};
// or with build helper
local Meta = t.objectOf({
name: t.string(),
age:: t.number(), // hidden means not required
});
t.validate(Meta {
name: 1, // should throw error like `$.name` should be a string value
age: 18,
})
- draft7
- draft6
- draft4
- draft3
-
$ref
with remote url need native functions:fetch(url): string
to fetch remote json schema raw dataparseJson(json data): {} | []
to parse json schema from raw data
-
pattern
&&patternProperties
native function:regexMatch(regex, str: string): bool
in custom jsonnet vm