getml / reflect-cpp

A C++20 library for fast serialization, deserialization and validation using reflection. Supports JSON, BSON, CBOR, flexbuffers, msgpack, TOML, XML, YAML / msgpack.org[C++20]

Home Page:https://getml.github.io/reflect-cpp/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JSON Schema

liuzicheng1987 opened this issue · comments

One feature we are currently missing is the automatic generation of a JSON schema. Please refer to the JSON schema specification for details:

https://json-schema.org/specification

The envisioned syntax is like this:

const std::string json_schema = rfl::json::to_schema<MyStruct>();

The function does not have to be consteval or constexpr. Runtime is fine.

Also, there doesn't have to be a reader. Maybe, in the future, we will be crazy enough to generate named tuples (https://github.com/getml/reflect-cpp/blob/main/docs/named_tuple.md) from JSON schema strings at compile time (which should be possible, in theory), but at the moment I would be happy if the syntax outlined above would work.

Please note that reflect-cpp contains validators like the Regex validators, numeric validators and AnyOf, AllOf, OneOf. It also supports Literals and Enums. These are deliberately designed with the JSON schema in mind and should be supported by the JSON schema as well. Please refer to the JSON schema specification for details. Also take a look at the reflect-cpp documentation to get a better understanding of these types (https://github.com/getml/reflect-cpp/tree/main/docs, particularly section 2)