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.
$ rebar3 compile
compile_pattern/1,2— Compile a JS/OpenAPI regex pattern to an Erlang regex (optionally strict/anchored). ReturnsMPor throws an exception.validate_format/2— Check if a value is valid for a given OpenAPI format. Returnstrueorfalse.known_formats/0— List all supported OpenAPI format names.
compile/1,2— Translate and compile JS regex to Erlang regex
validate_format/2— Validates whether or not a string matches the pattern for a known formatknown_formats/0— List supported formats
email, uuid, date, date_time, ipv4, ipv6, hostname, uri, password, byte, int32, int64, float, double, binary, time
MP = oas_util:compile_pattern(<<"^foo[0-9]+bar$">>).
re:run(<<"foo123bar">>, MP).MP = oas_util:compile_pattern(<<"foo">>, true).
re:run(<<"foo">>, MP). % matches
re:run(<<"xfoo">>, MP). % nomatchoas_util:validate_format(email, <<"[email protected]">>). % true
oas_util:validate_format(email, <<"foo@">>). % falseoas_util:known_formats().MIT License — see LICENSE.md