https://github.com/openvalidation/openvalidation
Compose validation rules in the language you use every day, openVALIDATION handles code creation for you.
https://github.com/openvalidation/openvalidation
cli code-generation csharp dsl java-8 javascript language lowcode natural-language nocode open-source validation-rules
Last synced: 10 months ago
JSON representation
Compose validation rules in the language you use every day, openVALIDATION handles code creation for you.
- Host: GitHub
- URL: https://github.com/openvalidation/openvalidation
- Owner: openvalidation
- License: apache-2.0
- Created: 2019-05-17T14:23:38.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-03-30T20:09:20.000Z (almost 4 years ago)
- Last Synced: 2025-03-25T06:22:39.518Z (10 months ago)
- Topics: cli, code-generation, csharp, dsl, java-8, javascript, language, lowcode, natural-language, nocode, open-source, validation-rules
- Language: Java
- Homepage: http://openvalidation.io/
- Size: 5.42 MB
- Stars: 68
- Watchers: 8
- Forks: 13
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README

openvalidation.io | playground.openvalidation.io | docs.openvalidation.io
a natural language (no-code) compiler for validation rules
## contents
- [introduction](#introduction)
- [install](#install)
- [npm](#npm)
- [jar](#jar)
- [docker image](#docker-image)
- [run](#run)
- [npm](#npm-cli)
- [jar](#executable-jar)
- [docker container](#docker-container)
- [result](#result)
- [cli parameters](#cli-parameters)
- [integrate](#integrate)
- [samples](#samples)
- [understand](#understand)
- [try](#try)
- [contribute](#contribute)
- [contact](#contact)
- [license](#license)
## introduction
openVALIDATION enables programming validation rules using natural languages, such as German or English.
The rules recorded in natural language are readable not only by humans but also by machines and therefore no longer need to be programmed by a software developer. This task is now taken over by openVALIDATION compiler. With integrated code generators, corresponding source code in the desired programming language can be generated automatically, such as Java, C#, JavaScript or Python, with more to come. This code can then be integrated into any application (services, frontends, middleware).
Write once, DONT CODE and run everywhere!
## install
### npm
install via npm as global cli command
```bash
npm i openvalidation -g
```
### jar
or just download the executable jar [here](https://downloadarchive.blob.core.windows.net/openvalidation-generator/openvalidation.jar) or via curl:
```
curl 'https://downloadarchive.blob.core.windows.net/openvalidation-generator/openvalidation.jar' --output openvalidation.jar
```
### docker image
```
docker pull openvalidation/openvalidation-rest
```
## run
### npm cli
```bash
openvalidation -r "user's age should not be less than 18 years" -s "{age:0}" -c en -l javascript
```
### executable jar
```
java -jar openvalidation.jar -r "user's age should not be less than 18 years" -s "{age : 0}" -c en -l javascript
```
### docker container
```
docker run -p 7070:80 openvalidation/openvalidation-rest
curl -X POST -H "Content-Type: application/json" -d "{\"rule\":\"user's age should not be less than 18 years\",\"culture\":\"en\",\"language\":\"JavaScript\",\"schema\":\"{age:0}\"}" http://localhost:7070/
```
### result
The following JavaScript code will be generated:
```javascript
var HUMLValidator = function() {
var huml = new HUMLFramework();
huml.appendRule("",
["age"],
"user's age should not be less than 18 years",
function(model) {
return huml.LESS_THAN(model.age, 18.0);
},
false
);
this.validate = function(model){
return huml.validate(model);
}
}
```
The generated code does not depend on 3'rd party libraries at all. Therefore, a custom framework is generated in addition to the rules. This framework contains a basic architecture to integrate the generated validation rules more easily into other systems.
### cli parameters
**-r** (--rule)
validation rule in a natural language
**-s** (--schema)
schema in JSON Schema or JSON Object format
**-c** (--culture)
culture code of the natural language. For example **de** for German or **en** for English.
The culture of **current system** will be used as Default if the parameter -c was not specified.
**en** is the absolute fallback if specified culture not supported by openVALIDATION.
**-l** (--language)
the programming language of the generation output.
**Java** is a default language. Available: Java, JavaScript, CSharp, (Python and Rust are still in development)
**-o** (--output)
The Output option defines a directory where the generated code files are stored. Without specifying the output parameter, the generated code is only displayed in the console. If no output directory is specified, the result will only be displayed in the console.
See more CLI Options... at docs.openvalidation.io
## integrate
The first step is to generate a rule in e.g. nodejs. To generate code files, the output directory must be defined with the parameter -o.
```bash
openvalidation -r "user's age should not be less than 18 years" -s "{age:0}" -c en -l node -o ./
```
the compiler generates 2 code files OpenValidation.js (the actual rules) and HUMLFramework.js (the generic framework)
Now you can integrate the generated code into a NodeJS application:
```javascript
var openVALIDATION = require('./OpenValidation.js');
var data = {name:'Alex', age:17};
var validationRESULT = openVALIDATION.validate(data);
if (validationRESULT.hasErrors) {
console.log(validationRESULT.errors);
} else {
console.log("this data is valid!");
}
```
Further integration examples can be found [here](https://docs.openvalidation.io/openvalidation-integration).
## samples
Here are examples of different validation rules:
rule
schema
description
the name should be Alex
{name:''}
simple rule. The rule itself is also the error message
if the name is not Alex
then the given name is not Alex
{name:''}
simple if/then rule. The text after then is the error message
a name must be Alex, Peter or Helmut
{name:''}
condition with multiple(OR) values
Berlin as capital city
the location has to be a capital city
{location:''}
domain specific expression as variable
the age is smaller than 18 years as underage
the user must not be underage
and his name should be Alex
{age:0, name:''}
preconditions as variable
user's age - 18 years as actual work experience
{age:0}
arithmetic
age and smaller as operator younger
user must not be younger than 18 years
{age:0}
semantic, domain specific comparison operator
first item from names as Boss
the Boss should be Alex
{names:['Alex','Peter','Helmut']}
first item from list
first number from numbers with a value bigger than 3 as magic number
the magic number has to be 4
{numbers:[1,2,3,4,5,6,7]}
filtering the list
## understand
openVALIDATION enables programming of validation rules using natural languages, such as German or English and many more.
The rules recorded in natural language are readable not only by humans but also by the computer and therefore no longer need to be programmed by a software developer.
**The grammar**
The Grammar of openVALIDATION based on a natural language is both formal and natural. This distinguishes this grammar from other programming languages or DSL's. It allows the use of additional semantic or grammatical content. The additional content is only relevant for human readability. The machine, on the other hand, ignores this addition. Thus it is possible to express the rules in a grammatically correct way on the one hand and to give them a semantic context on the other. This all makes the rules easier to understand. Rules formulated with openVALIDATION are thus at the same time a formal, machine-processable specification, but also a documentation that is easy for humans to understand.
For more details check out our [documentation and guides](https://docs.openvalidation.io)
## try
try it out directly in the browser on the [playground](https://playground.openvalidation.io/)
## contribute
We still have 2 zeros in the version 0.0.X of openVALIDATION, so there is still a lot to do. If you want to join us, you are more than welcome to participate!
Check our [contribution guide](https://docs.openvalidation.io/contribution/contribution-guide).
Even if you're not a developer or don't fully understand the technical part of openVALIDATION yet, it doesn't matter. There are many different ways to join the project.
Check our [contribution guide especially for beginners](https://docs.openvalidation.io/contribution/for-beginners)
Thank you to all the people and bots who already contributed to openVALIDATION!
## contact
You can write an [E-Mail](mailto:validaria@openvalidation.io), mention our twitter account [@openVALIDATION](https://twitter.com/openVALIDATION) or message us at our Instagram account [@openvalidation_](https://www.instagram.com/openvalidation_/).
## license
openVALIDATION was initially developed as part of a research project at [BROCKHAUS AG](http://brockhaus-ag.de) in Dortmund.
Only an Open Source solution can unfold its true potential. That's why we released it on GitHub as an open-source project under the Apache 2.0 license.
See [LICENSE.txt](LICENSE.txt)
