OpenAPI namespace.
It contains OpenAPI 3.0 document parsing and code generation (models).
Generate C++ models and their anch-json mappers from the document schemas ( components.schemas ).
Mapping:
string → std::string ( anch::UUID for uuid format, anch::date::DateTime for date-time format, anch::date::Date for date format), integer → int32_t / int64_t , number → float / double , boolean → bool ;
- objects with properties and
allOf compositions → structures, inline objects get a name built from their path (<Model><Property>) ;
- string enumerations → enum class (unknown values are rejected on deserialization) ;
array → std::vector , objects with additionalProperties schema only → std::map<std::string,T> ;
- optional and
nullable properties → std::optional , arrays and maps are empty when absent ;
- required properties are registered with
anch::val::required (absent or not nullable null value is refused on deserialization) ;
minLength , maxLength , minimum , maximum (exclusive or not), multipleOf , minItems , maxItems , uniqueItems , minProperties , maxProperties and non string enum → anch-json value constraints (array items and map values constraints with anch::val::items ) ;
pattern → anch::val::pattern (invalid ECMAScript patterns are ignored with a warning), string format (which is not mapped to a type) → anch::val::format ;
- models have a default
operator== ;
- recursive references →
std::shared_ptr ;
- other schemas (primitives, arrays, maps) → aliases (
using ).
Not supported (warning, or error in strict mode): oneOf / anyOf , free-form objects, nested containers (array of arrays, ...), references outside #/components/schemas .
With server and client options, anch-rest endpoints are generated from the document paths: service interface, its registration in anch::rest::Api and typed client (see endpoints generation).
- Parameters
-
| api | the OpenAPI document |
| options | the generation options |
- Returns
- the generated header, source and warnings
- Exceptions
-