oaspec/openapi/parser
Values
pub fn parse_error_to_string(
error: diagnostic.Diagnostic,
) -> String
Parse a schema reference (either $ref or inline schema). Convert a parse error to a human-readable string.
pub fn parse_file(
path: String,
) -> Result(
@internal OpenApiSpec(@internal Unresolved),
diagnostic.Diagnostic,
)
Parse an OpenAPI spec from a file path.
Supports both YAML (.yaml, .yml) and JSON (.json) files.
After parsing, resolves relative-file $ref values across schemas,
parameters, request bodies, responses, and path items — including
nested object/array properties and composition branches — by loading
the referenced files from disk and merging their definitions into the
main spec. Cyclic external ref graphs (A.yaml → B.yaml → A.yaml)
fail fast with a dedicated diagnostic. HTTP/HTTPS URLs are not
followed.
pub fn parse_file_with_progress(
path: String,
reporter: @internal Reporter,
) -> Result(
@internal OpenApiSpec(@internal Unresolved),
diagnostic.Diagnostic,
)
Same as parse_file, with a Reporter that receives a line per
stage (read, parse, resolve external refs). Used by the CLI to
give the user feedback on big specs (issue #352).
pub fn parse_json_string(
content: String,
) -> Result(
@internal OpenApiSpec(@internal Unresolved),
diagnostic.Diagnostic,
)
Parse an OpenAPI spec from a JSON string using OTP’s native JSON
decoder instead of yamerl. Roughly two orders of magnitude faster
than parse_string on large specs because the YAML pre-processing
and constructor passes are skipped (issue #352). Behaves like
parse_string once the tree is built — same OpenApiSpec shape,
same downstream pipeline. Diagnostics from this path do not carry
source line/column info because OTP json:decode/3 does not
expose decoder positions; the caller still gets the path-prefixed
error message that downstream tooling relies on.
pub fn parse_string(
content: String,
) -> Result(
@internal OpenApiSpec(@internal Unresolved),
diagnostic.Diagnostic,
)
Parse an OpenAPI spec from a YAML/JSON string. The default path
runs the input through yamerl, which preserves YAML semantics and
source locations but is too slow on large JSON specs (the GitHub
REST OpenAPI is ~12 MB and yamerl effectively hangs — see issue
#352). Use parse_json_string directly when the content is known
to be JSON.