Skip to content

Instantly share code, notes, and snippets.

@brandones
Last active Nov 7, 2019
Embed
What would you like to do?
Arrays in OpenMRS MF Configurations
// Example 1: Array of primitives
// input
foo: [2, 42, 99]
// schema
{
foo: {
default: [1, 1, 2, 3],
arrayElements: {
validators: [isInteger]
},
validators: [
lengthBetween(1, 4)
]
}
}
// Example 2: Array of objects
// input
foo: [
{ qux: "abc", quy: "xyz" },
{ qux: "bcd" },
{ quy: "def" }
]
// schema
{
foo: {
default: [
{ qux: "qux1", quy: "quy1" },
{ quy: "quy2" }
],
arrayElements: {
qux: {
default: "N/A",
validators: [isString]
},
quy: {
default: "",
validators: [isString]
}
},
validators: [lengthBetween(1, 4)]
}
}
// result
foo: [
{ qux: "abc", quy: "xyz" },
{ qux: "bcd", quy: "" },
{ qux: "N/A", quy: "def" }
]
// Default resulting config object (with no provided config input):
foo: [
{ qux: "qux1", quy: "quy1" },
{ qux: "N/A", quy: "quy2" }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment