Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

api7/lua-resty-openapi-validator

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Name

lua-resty-openapi-validator - Pure Lua OpenAPI request validator for OpenResty / LuaJIT.

CI License

Table of Contents

Description

Validates HTTP requests against OpenAPI 3.0 and 3.1 specifications using lua-resty-radixtree for path matching and api7/jsonschema for schema validation. Pure Lua, no external processes required.

Install

Dependencies

install by luarocks

luarocks install lua-resty-openapi-validator

install by source

git clone https://github.com/api7/lua-resty-openapi-validator.git
cd lua-resty-openapi-validator
make dev
sudo make install

Back to TOC

Quick Start

local ov = require("resty.openapi_validator")

-- compile once (cache the result)
local validator, err = ov.compile(spec_json_string, {
    strict = true,  -- error on unsupported 3.1 keywords (default: true)
})
if not validator then
    ngx.log(ngx.ERR, "spec compile error: ", err)
    return
end

-- validate per-request
local ok, err = validator:validate_request({
    method       = ngx.req.get_method(),
    path         = ngx.var.uri,
    query        = ngx.req.get_uri_args(),
    headers      = ngx.req.get_headers(0, true),
    body         = ngx.req.get_body_data(),
    content_type = ngx.var.content_type,
})

if not ok then
    ngx.status = 400
    ngx.say(err)
    return
end

See API documentation for details on all methods and options.

Back to TOC

Validation Scope

Feature Status
Path parameter matching & validation
Query parameter validation (with type coercion)
Header validation
Request body validation (JSON)
Request body validation (form-urlencoded)
style / explode parameter serialization
$ref resolution (document-internal)
Circular $ref support
allOf / oneOf / anyOf composition
additionalProperties
OpenAPI 3.0 nullable
OpenAPI 3.1 type arrays (["string", "null"])
readOnly / writeOnly validation
Response validation ❌ (not planned for v1)
Security scheme validation
External $ref (URLs, files)
multipart/form-data body ⚠️ basic support

Back to TOC

OpenAPI 3.1 Support

OpenAPI 3.1 uses JSON Schema Draft 2020-12. Since the underlying jsonschema library supports up to Draft 7, schemas are normalized at compile time:

3.1 / 2020-12 Feature Normalization
prefixItems items (tuple form)
$defs definitions
dependentRequired / dependentSchemas dependencies
type: ["string", "null"] Passed through (Draft 7 compatible)
$ref with sibling keywords allOf: [resolved, {siblings}]
$dynamicRef, unevaluatedProperties Error (strict) / Warning (lenient)

Back to TOC

Testing

make test

Runs unit tests and conformance tests covering OpenAPI 3.0 / 3.1 features (parameter serialization, request body validation, discriminator, $ref, readOnly/writeOnly, deepObject/form/multipart, etc.).

Back to TOC

License

Apache 2.0

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Morty Proxy This is a proxified and sanitized view of the page, visit original site.