...
{
"@openmrs/esm-login": {
"logo": {
"src": "https://pbs.twimg.com/media/C1w_czvWgAAWONL.jpg"
}
},
"@openmrs/esm-home": {
"search": {
"numResultsPerPage": 20
}
}
}
How do I
...
configure my OpenMRS implementation?
There are two methods for doing so.
...
import { defineConfigSchema, validators } from "@openmrs/esm-module-config"
defineConfigSchema("@openmrs/esm-hologram-doctor", {
hologram: {
color: {
default: false,
validators: [validators.isBoolean]
}
},
virtualProvider}
}
The above would expect a configuration file structured like
{
"@openmrs/esm-hologram-doctor": {
name"hologram: {
family"color": {true
default: "Kenobi",
}
}
}
Note that each configuration element should have an object for a value, and that this object must define the default for that element. Do not do this:
? defineConfigSchema("@openmrs/esm-hologram-doctor",
? hologram: {
? validatorssalutation: [
"Some friendly default salutation! ? this is wrong!"
validators.isString,
? })
The following names are reserved and cannot be used as config keys: default
, validators
, and arrayElements
. Doing so will result in undefined behavior. Do not do this:
? defineConfigSchema("@openmrs/esm-hologram-doctor",
? hologram: {
? salutation: {
validator(n? => n != "Vader", "cannot bedefault: a vader")
{
? ]default: "Greetings ? this is bad don't }do it"
? }
}
})
Validators
You should provide validators for your configuration elements wherever possible. This reduces the probability that implementers using your module will have hard-to-debug runtime errors. It gives you, the module developer, the opportunity to provide implementers with very helpful explanations about why their configuration won't work.
...
For convenience, some common validators are provided out of the box. These are
- isBoolean
- isString
Arrays
You can accept and validate arrays, and arrays containing objects, in your configuration schema. This is configured with the arrayElements
parameter. For example, a schema which would accept an array of strings:
virtualProvider: {
name: {
given: {
default: ["Obi", "Wan"]
arrayElements: {
validators: [validators.isString]
}}}}
Here is an example of a schema that expects an array of objects structured in a particular way.
robots: {
default: [
{ name: "R2-D2", homeworld: "Naboo" },
{ name: "C-3PO", homeworld: "Tatooine" }
],
arrayElements: {
name: { validators: [robotNameValidator] },
homeworld: {
default: null // not required
validators: [validators.isString]
}
}
}
This schema will require that any objects in the robots
array must only have the keys name
and homeworld
.
Using config values
The generic way
...