io.openvalidation:openvalidation-antlr

Compose validation rules in the language you use every day, openVALIDATION handles code creation for you.

License

License

Categories

Categories

Ant Build Tools ANTLR Compiler-compiler
GroupId

GroupId

io.openvalidation
ArtifactId

ArtifactId

openvalidation-antlr
Last Version

Last Version

0.0.4.1
Release Date

Release Date

Type

Type

jar
Description

Description

Compose validation rules in the language you use every day, openVALIDATION handles code creation for you.

Download openvalidation-antlr

How to add to project

<!-- https://jarcasting.com/artifacts/io.openvalidation/openvalidation-antlr/ -->
<dependency>
    <groupId>io.openvalidation</groupId>
    <artifactId>openvalidation-antlr</artifactId>
    <version>0.0.4.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.openvalidation/openvalidation-antlr/
implementation 'io.openvalidation:openvalidation-antlr:0.0.4.1'
// https://jarcasting.com/artifacts/io.openvalidation/openvalidation-antlr/
implementation ("io.openvalidation:openvalidation-antlr:0.0.4.1")
'io.openvalidation:openvalidation-antlr:jar:0.0.4.1'
<dependency org="io.openvalidation" name="openvalidation-antlr" rev="0.0.4.1">
  <artifact name="openvalidation-antlr" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.openvalidation', module='openvalidation-antlr', version='0.0.4.1')
)
libraryDependencies += "io.openvalidation" % "openvalidation-antlr" % "0.0.4.1"
[io.openvalidation/openvalidation-antlr "0.0.4.1"]

Dependencies

compile (7)

Group / Artifact Type Version
org.antlr : antlr4-runtime jar 4.7.1
org.antlr : antlr4 jar 4.7.1
io.openvalidation : openvalidation-common jar 0.0.4.1
commons-io : commons-io jar 2.6
commons-lang : commons-lang jar 2.6
org.everit.json : org.everit.json.schema jar 1.5.1
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.21

test (6)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.4.0-RC1
org.junit.jupiter : junit-jupiter-engine jar 5.4.0-RC1
org.junit.jupiter : junit-jupiter-params jar 5.4.0-RC1
org.hamcrest : hamcrest-library jar 1.3
org.mockito : mockito-junit-jupiter jar 2.23.4
org.jetbrains.kotlin : kotlin-test jar 1.3.21

Project Modules

There are no modules declared in this project.



openVALIDATION a natural language no-code compiler






 

Build Status Azure DevOps tests (compact) Maven Central Follow us on Twitter

openvalidation.io | playground.openvalidation.io | docs.openvalidation.io

a natural language (no-code) compiler for validation rules




contents





introduction


a natural language compiler for validation rules


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

npm i openvalidation -g

jar

or just download the executable jar here 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

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:

var HUMLValidator = function() {
    var huml = new HUMLFramework();
    
        huml.appendRule("",
            ["age"],
            "user&#x27;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.

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:

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.




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




try


try it out directly in the browser on the playground




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.

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



Thank you to all the people and bots who already contributed to openVALIDATION!




contact


You can write an E-Mail, mention our twitter account @openVALIDATION or message us at our Instagram account @openvalidation_.




license


openVALIDATION was initially developed as part of a research project at BROCKHAUS AG 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

io.openvalidation

openVALIDATION

write once, DON'T CODE and run everywhere!

Versions

Version
0.0.4.1
0.0.4
0.0.3
0.0.2
0.0.1