This guide walks you from zero to a set of deployable WAF rules generated from your OpenAPI specification.
- Java 8 or later (Java 11+ recommended)
- Maven 3.6.0 or later — only needed if you build from source
Download the latest oashield-cli.jar from the
Releases page.
git clone https://github.com/cognitivegears/oashield.git
cd oashield
mvn package -P build-cli-jarThis produces target/oashield-cli.jar.
java -cp oashield-cli.jar org.openapitools.codegen.OpenAPIGenerator \
generate -g modsecurity3 \
-i /path/to/openapi.yaml \
-o /path/to/output/dirReplace -i with the path to your OpenAPI spec and -o with the directory
where the generated .conf rules should be written.
Windows: the same command works; if you add multiple classpath entries, separate them with
;instead of:.
To validate JSON request bodies against the OpenAPI schema (and to target Coraza), select the engine flavor:
java -cp oashield-cli.jar org.openapitools.codegen.OpenAPIGenerator \
generate -g modsecurity3 \
-i /path/to/openapi.yaml \
-o /path/to/output/dir \
--additional-properties engineFlavor=coraza,schemaRulePath=rules/schema.jsonSee Configuration for every option and the differences between engine flavors.
Copy the generated .conf files from your output directory into your
ModSecurity or Coraza setup, alongside your API or in a sidecar. The rules are
standard SecLang, so they load the same way any other rule file does.
For a worked example, see the sample specs in samples/ and the
pre-generated output in samples/output/petstore/.
mvn testFor integration tests against real WAF engines, see Integration Testing.