odin-jsonschema

Implementation of JSON schema for Odin
Log | Files | Refs | LICENSE

commit e195d6ba7384d4195e66307dfec66d27084b6f02
parent a3c881c467613b5b8d0fcc8e0ad124a18ea8c62c
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Thu, 23 Jul 2026 09:23:40 -0300

cmd/jschema: add -openapi flag

Optional flag that controls openapi idiom support.

If not supplied, a cheap heuristic check on the document is performed:
if a document contains "openapi" root property then openapi features are
enabled.

The caller always has final say with the cli flag.

Diffstat:
Msrc/cmd/jschema/main.odin | 21+++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/src/cmd/jschema/main.odin b/src/cmd/jschema/main.odin @@ -51,6 +51,19 @@ run :: proc() -> int { output = arg[len("-o:"):] case strings.has_prefix(arg, "-pkg:"): opts.package_name = arg[len("-pkg:"):] + case strings.has_prefix(arg, "-openapi"): + rest := arg[len("-openapi"):] + switch { + case rest == "": + opts.openapi = true + case rest == ":true": + opts.openapi = true + case rest == ":false": + opts.openapi = false + case: + fmt.eprintfln("jschema: invalid value for -openapi %q\n%s", arg, USAGE) + return 2 + } case strings.has_prefix(arg, "-root:"): opts.root_name = arg[len("-root:"):] case strings.has_prefix(arg, "-"): @@ -129,8 +142,12 @@ report :: proc(err: jschema.Error) { } } -USAGE :: `usage: jschema [schema.json] [-o:output.odin] [-pkg:name] [-root:name] +USAGE :: `usage: jschema [schema.json] [-o:output.odin] [-pkg:name] [-root:name] [-openapi[:true|:false]] Generates Odin type declarations from a JSON Schema (draft-07 or 2020-12). Reads from stdin when no schema path is given; writes to stdout when -o is -not given.` +not given. + +OpenAPI idioms (if/then/else lowering, Or_Reference($T) generic union) are +auto-detected from a top-level "openapi" property. -openapi forces the +mode on; -openapi:false forces it off.`