Skip to content

leonardb/oas_util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oas_util: OpenAPI Regex & Format Utilities for Erlang

This library provides utilities for working with OpenAPI/JSON Schema regex patterns and format validation in Erlang. It translates JavaScript-style regexes to Erlang/PCRE2, and provides ready-to-use patterns for common OpenAPI formats. Compiled regexes are cached using persistent_term.

Build

$ rebar3 compile

Modules & API

oas_util

  • compile_pattern/1,2 — Compile a JS/OpenAPI regex pattern to an Erlang regex (optionally strict/anchored). Returns MP or throws an exception.
  • validate_format/2 — Check if a value is valid for a given OpenAPI format. Returns true or false.
  • known_formats/0 — List all supported OpenAPI format names.

oas_pattern

  • compile/1,2 — Translate and compile JS regex to Erlang regex

oas_format

  • validate_format/2 — Validates whether or not a string matches the pattern for a known format
  • known_formats/0 — List supported formats

Supported OpenAPI Formats

email, uuid, date, date_time, ipv4, ipv6, hostname, uri, password, byte, int32, int64, float, double, binary, time

Usage Examples

Compile a JS/OpenAPI regex pattern

MP = oas_util:compile_pattern(<<"^foo[0-9]+bar$">>).
re:run(<<"foo123bar">>, MP).

Compile with strict mode (anchored)

MP = oas_util:compile_pattern(<<"foo">>, true).
re:run(<<"foo">>, MP). % matches
re:run(<<"xfoo">>, MP). % nomatch

Validate an OpenAPI format (e.g., email)

oas_util:validate_format(email, <<"[email protected]">>). % true
oas_util:validate_format(email, <<"foo@">>). % false

List all supported formats

oas_util:known_formats().

License

MIT License — see LICENSE.md

About

Utility library for working with patterns and formats in OpenAPI specifications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages