Skip to content

Instantly share code, notes, and snippets.

@brandones
Last active November 7, 2019 21:16
Show Gist options
  • Save brandones/74a4c06e531001046bd68aa5dfe3e4c0 to your computer and use it in GitHub Desktop.
Save brandones/74a4c06e531001046bd68aa5dfe3e4c0 to your computer and use it in GitHub Desktop.
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