Skip to content

Conversation

@TJKoury
Copy link

@TJKoury TJKoury commented Dec 19, 2025

JSON Schema import/export

This PR makes JSON Schema a first-class schema format for flatc, while still flowing through the existing FlatBuffers schema IR (reflection/reflection.fbs).

What’s included

JSON Schema export: flatc --jsonschema generates *.schema.json from .fbs
JSON Schema import: treat *.schema.json as a schema input (IDL-like), map into the FlatBuffers schema IR, and run normal generators
Optional lossless round-tripping: --jsonschema-xflatbuffers emits x-flatbuffers vendor-extension metadata + meta-schema docs

Docs + tests:

Generation + golden + round-trip stability: tests/JsonSchemaTest.sh
Import “wild” JSON Schema/OpenAPI fixtures + stable regeneration: tests/JsonSchemaImportTest.sh (fixtures under tests/jsonschema_import/)
Usage examples
Export FlatBuffers → JSON Schema: flatc --jsonschema -o out schema.fbs
Export (lossless): flatc --jsonschema --jsonschema-xflatbuffers -o out schema.fbs
Import JSON Schema → generators: flatc --cpp -o out schema.schema.json (override root via --root-type when needed)

Implementation notes / review tips

CLI wiring + .schema.json input detection: src/flatc.cpp
JSON Schema importer: Parser::DoParseJsonSchema in src/idl_parser.cpp
JSON Schema generator: src/idl_gen_json_schema.cpp
x-flatbuffers meta-schema: docs/source/schemas/x-flatbuffers.schema.json
Testing

Passed testing locally:

ctest (runs flattests)
tests/CppTest.sh
tests/JsonSchemaTest.sh
tests/JsonSchemaImportTest.sh
tests/PythonTest.sh
Go tests (default + --preserve-case)
tests/PHPTest.sh (default + --preserve-case)

The importer is intentionally permissive (unknown JSON Schema/OpenAPI keywords are ignored).
Full fidelity requires x-flatbuffers metadata; without it, some FlatBuffers semantics can’t be expressed in plain JSON Schema.

@TJKoury TJKoury linked an issue Dec 19, 2025 that may be closed by this pull request
@TJKoury TJKoury closed this Dec 19, 2025
@TJKoury TJKoury reopened this Dec 19, 2025
@TJKoury TJKoury merged commit 5dda8eb into master Dec 19, 2025
92 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import JSON Schema as IDL

2 participants