1- # lua-resty-openapi-validator
1+ Name
2+ ====
23
3- Pure Lua OpenAPI request validator for OpenResty / LuaJIT.
4+ lua-resty-openapi-validator - Pure Lua OpenAPI request validator for OpenResty / LuaJIT.
5+
6+ ![ CI] ( https://github.com/api7/lua-resty-openapi-validator/actions/workflows/test.yml/badge.svg )
7+ ![ License] ( https://img.shields.io/badge/License-Apache_2.0-blue.svg )
8+
9+ Table of Contents
10+ =================
11+
12+ * [ Description] ( #description )
13+ * [ Install] ( #install )
14+ * [ Quick Start] ( #quick-start )
15+ * [ API] ( api.md )
16+ * [ Validation Scope] ( #validation-scope )
17+ * [ OpenAPI 3.1 Support] ( #openapi-31-support )
18+ * [ Benchmark] ( #benchmark )
19+ * [ Testing] ( #testing )
20+
21+ Description
22+ ===========
423
524Validates HTTP requests against OpenAPI 3.0 and 3.1 specifications using
625[ lua-resty-radixtree] ( https://github.com/api7/lua-resty-radixtree ) for path
726matching and [ api7/jsonschema] ( https://github.com/api7/jsonschema ) for schema
827validation. No Go FFI or external processes required.
928
10- ## Performance
29+ Install
30+ =======
1131
12- ** ~ 45% higher throughput** than the Go FFI-based validator under concurrent load
13- (single worker, 50 connections). See [ benchmark/RESULTS.md] ( benchmark/RESULTS.md ) .
32+ > Dependencies
1433
15- ## Installation
34+ - [ api7/jsonschema] ( https://github.com/api7/jsonschema ) — JSON Schema Draft 4/6/7 validation
35+ - [ lua-resty-radixtree] ( https://github.com/api7/lua-resty-radixtree ) — radix tree path routing
36+ - [ lua-cjson] ( https://github.com/openresty/lua-cjson ) — JSON encoding/decoding
37+
38+ > install by luarocks
1639
17- ``` bash
40+ ``` shell
1841luarocks install lua-resty-openapi-validator
1942```
2043
21- Or add the ` lib/ ` directory to your ` lua_package_path ` .
44+ > install by source
2245
23- ### Dependencies
46+ ``` shell
47+ git clone https://github.com/api7/lua-resty-openapi-validator.git
48+ cd lua-resty-openapi-validator
49+ make dev
50+ sudo make install
51+ ```
2452
25- - [ api7/jsonschema] ( https://github.com/api7/jsonschema ) — JSON Schema Draft 4/6/7 validation
26- - [ lua-resty-radixtree] ( https://github.com/api7/lua-resty-radixtree ) — radix tree path routing
27- - [ lua-cjson] ( https://github.com/openresty/lua-cjson ) — JSON encoding/decoding
53+ [ Back to TOC] ( #table-of-contents )
2854
29- ## Quick Start
55+ Quick Start
56+ ===========
3057
3158``` lua
3259local ov = require (" resty.openapi_validator" )
3360
3461-- compile once (cache the result)
3562local validator , err = ov .compile (spec_json_string , {
36- strict = true , -- error on unsupported 3.1 keywords (default: true)
37- coerce_types = true , -- coerce query/header string values to schema types (default: true)
38- fail_fast = false , -- return on first error (default: false)
63+ strict = true , -- error on unsupported 3.1 keywords (default: true)
3964})
4065if not validator then
4166 ngx .log (ngx .ERR , " spec compile error: " , err )
@@ -59,38 +84,37 @@ if not ok then
5984end
6085```
6186
62- ### Selective Validation
87+ See [ API documentation ] ( api.md ) for details on all methods and options.
6388
64- Skip specific validation steps:
89+ [ Back to TOC ] ( #table-of-contents )
6590
66- ``` lua
67- local ok , err = validator :validate_request (req , {
68- skip_query = true , -- skip query parameter validation
69- skip_body = true , -- skip request body validation
70- })
71- ```
72-
73- ## Validation Scope
91+ Validation Scope
92+ ================
7493
7594| Feature | Status |
7695| ---| ---|
7796| Path parameter matching & validation | ✅ |
7897| Query parameter validation (with type coercion) | ✅ |
7998| Header validation | ✅ |
8099| Request body validation (JSON) | ✅ |
100+ | Request body validation (form-urlencoded) | ✅ |
81101| ` style ` / ` explode ` parameter serialization | ✅ |
82102| ` $ref ` resolution (document-internal) | ✅ |
83103| Circular ` $ref ` support | ✅ |
84104| ` allOf ` / ` oneOf ` / ` anyOf ` composition | ✅ |
85105| ` additionalProperties ` | ✅ |
86106| OpenAPI 3.0 ` nullable ` | ✅ |
87107| OpenAPI 3.1 type arrays (` ["string", "null"] ` ) | ✅ |
108+ | ` readOnly ` / ` writeOnly ` validation | ✅ |
88109| Response validation | ❌ (not planned for v1) |
89110| Security scheme validation | ❌ |
90111| External ` $ref ` (URLs, files) | ❌ |
91- | ` multipart/form-data ` body | ⚠️ (skipped, returns OK) |
112+ | ` multipart/form-data ` body | ⚠️ basic support |
113+
114+ [ Back to TOC] ( #table-of-contents )
92115
93- ## OpenAPI 3.1 Support
116+ OpenAPI 3.1 Support
117+ ===================
94118
95119OpenAPI 3.1 uses JSON Schema Draft 2020-12. Since the underlying jsonschema
96120library supports up to Draft 7, schemas are normalized at compile time:
@@ -104,15 +128,29 @@ library supports up to Draft 7, schemas are normalized at compile time:
104128| ` $ref ` with sibling keywords | → ` allOf: [resolved, {siblings}] ` |
105129| ` $dynamicRef ` , ` unevaluatedProperties ` | Error (strict) / Warning (lenient) |
106130
107- ## Testing
131+ [ Back to TOC] ( #table-of-contents )
132+
133+ Benchmark
134+ =========
108135
109- ``` bash
136+ ** ~ 45% higher throughput** than the Go FFI-based validator under concurrent load
137+ (single worker, 50 connections). See [ benchmark/RESULTS.md] ( benchmark/RESULTS.md ) .
138+
139+ [ Back to TOC] ( #table-of-contents )
140+
141+ Testing
142+ =======
143+
144+ ``` shell
110145make test
111146```
112147
113- Runs 200 tests across unit tests and conformance tests ported from
148+ Runs unit tests and conformance tests ported from
114149[ kin-openapi] ( https://github.com/getkin/kin-openapi ) .
115150
116- ## License
151+ [ Back to TOC] ( #table-of-contents )
152+
153+ License
154+ =======
117155
118156Apache 2.0
0 commit comments