ketansaxena / schema-validator Goto Github PK
View Code? Open in Web Editor NEWSchema validation utility for YAML/JSON files against a pre defined schema
Home Page: https://ketantechracers.github.io/schema-validator
License: MIT License
Schema validation utility for YAML/JSON files against a pre defined schema
Home Page: https://ketantechracers.github.io/schema-validator
License: MIT License
Would you accept a PR replacing the validate dependency with simple-schema-validation, which fixes this bug?
Right now, we have to create a schema file or schema js object to verify target object. Can we have a utility by which I can just pass a targetObject
which would get compared to the structure of a sourceObject
?
I have a request, can we have the logging as optional or add an optional level
lets say, verbose
, warn
and error
.
It would help reduce the amount of logs on the terminal.
The schema
bin file uses windows style line endings (\r\n) and this breaks attempts to use the package on non-windows systems.
The edge case here is that npm performs conversion of \r\n to \n for "bins" files, but yarn does not.
Hi great module. Thanks for this one.
I have a need to check child key/values under parents with wildcards.
Example:
foo:
bar:
color: blue
baz:
color: red
Where color needs to be checked but it's immediate parent is not always known: foo.*.color
. Anyway to accomplish this?
Hi,
I want to validate whether the given yaml parameter matches a certain regex. Is this possible somehow?
Example:
IP:
type: string
required: true
regex: ^\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b$
This tool is great, but so far int merely prints errors and warnings, which makes it difficult to evaluate the validation status e.g. by a CI script or pre-commit hook.
A naïve implementation might just evaluate the list of errors and warnings and exit the process with a non-zero status:
const errorsAndWarnings = validateSchema(targetObj, options)
if (errorsAndWarnings?.length > 0) {
process.exit(1)
}
I running my yaml validation in one of my projects and I want my build to fail if I get any errors and not on just warnings. validateSchema() returns Errors+Warnings list irrespective of the log levels we have set and there is no way to differentiate between errors and warnings from the list returned. Can we return the list of errors depending on what the log level is set?
As soon as I include "yaml-schema-validator": "^1.1.9"
in my package.json
and npm install
it, mocha --opts mocha.opts
fails with this error message:
$ mocha --opts mocha.opts
error: unknown option `--opts'
My project has these dependencies:
"devDependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"eslint": "^6.5.1",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-import": "^2.14.0",
"fast-xml-parser": "3.13.0",
"mocha": "^6.2.1",
"nyc": "^14.1.1",
"yaml-schema-validator": "^1.1.9"
},
"dependencies": {
"app-root-path": "^2.2.1",
"bluebird": "^3.7.0",
"config": "^3.2.3",
"glob": "^7.1.4",
"js-yaml": "^3.13.1",
"json5": "^2.1.1",
"jszip": "^3.2.2",
"lodash": "^4.17.11",
"moment": "^2.22.2",
"moment-range": "^4.0.1",
"moment-timezone": "^0.5.23",
"normalize-path": "^3.0.0",
"ramda": "^0.26.1",
"sql.js": "^1.0.0",
"winston": "^3.2.1",
"yargs": "^14.2.0"
}
If I remove yaml-schema-validator
, the command mocha --opts mocha.opts
runs all tests as expected.
The problematic behavior is observed regardless of platform, it's the same on Linux, Windows, or macOS. Node.js version 10.16.3 was used.
services:
- name: a name
ports:
- port: 81
service: web
- port: 10101
service: api
- name: another name
ports:
- port: 2801
name: api
- port: 2802
name: mysql
- port: 31975
service: nodePort/public api
- port: 31976
service: nodePort/internal api
Thank you for writing this, I find your library to be super helpful!
ISSUE
Upon execution of your example, I get the following error:
ReferenceError: Schema is not defined
I was not able to locate your definition/import of
Schema
in your code.
CODE
// custom validation function checking value for a regex
const checkHexColor = val => {
return /^#[0-9a-fA-F]$/.test(val)
}
const car = new Schema({
color: {
type: String,
use: { checkHexColor }
}
})
Required not working correctly on multi level file. For example
I define schema as:
person:
name:
type: string
required: true
dob:
type: string
car:
name:
type: string
required: true
and my yml under test can be:
car:
name: 'BMW'
So it should not complain person.name is required.
Currently it complain that person.name is missing. It should only complain if upper level object exist eg
car:
name: 'BMW'
person:
dob: 24-10
Compatibility issue with yargs package. When i try to use both while creating my owm cmd tool, options for schema-validator overrides my yargs options
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.