JSON validation presenter for Unifig
Transforms configuration validation errors into json string.
JSON of contents
Installation
npm i @unifig/validation-presenter-json
yarn add @unifig/validation-presenter-json
Quick Start
import { Config, PlainConfigAdapter } from '@unifig/core';
import { toJSON } from '@unifig/validation-presenter-json';
function bootstrap() {
const validationError = Config.registerSync({
templates: [StorageOptions, NetworkOptions],
adapter: new PlainConfigAdapter({}),
});
if (validationError) {
console.error(toJSON(validationError));
process.exit(1);
}
}
bootstrap();
Example output
[
{
"template": "TemplateMock",
"errors": [
{
"property": "port",
"type": "Number",
"source": "PORT",
"currentValue": "not-a-port",
"failedConstraints": [{ "name": "isInt", "details": "port must be an integer number" }]
},
{
"property": "db",
"children": [
{
"property": "url",
"type": "String",
"source": "DB_URL",
"failedConstraints": [{ "name": "isString", "details": "url must be a string" }]
},
{
"property": "password",
"type": "String",
"source": "DB_PASSWORD",
"failedConstraints": [{ "name": "isString", "details": "password must be a string" }]
}
]
}
]
}
]
License
This project is licensed under the MIT License - see the LICENSE file for details.