Boost C++ Libraries

PrevUpHomeNext

Function template json_schema_for

boost::taar::json_schema_for — A JSON Schema (2020-12 vocabulary) for C++ type T.

Synopsis

// In header: <boost/taar/core/json_schema.hpp>


template<typename T> boost::json::object json_schema_for();

Description

  • bool -> {"type":"boolean"}; integral -> integer; floating point -> number; string-like -> string.

  • std::optional<U> -> the schema of U.

  • boost::json::value -> {} (any); boost::json::object -> {"type":"object"}; boost::json::array -> {"type":"array"}.

  • Sequences (std::vector, std::array, ...) -> array with items from the element type.

  • Maps with string keys -> object with additionalProperties.

  • BOOST_DESCRIBE_STRUCTed types -> object with properties from the public members, required listing the non-optional ones and title naming the type (used by the OpenAPI generator to hoist the schema into components). BOOST_DESCRIBE_ENUMed types -> string with enum.

  • Anything else -> {"type":"object"}.


PrevUpHomeNext