1#ifndef SOURCEMETA_CORE_OPENAPI_H_
2#define SOURCEMETA_CORE_OPENAPI_H_
4#ifndef SOURCEMETA_CORE_OPENAPI_EXPORT
5#include <sourcemeta/core/openapi_export.h>
8#include <sourcemeta/core/json.h>
9#include <sourcemeta/core/jsonpointer.h>
10#include <sourcemeta/core/jsonschema.h>
13#include <sourcemeta/core/openapi_error.h>
39namespace sourcemeta::core {
71SOURCEMETA_CORE_OPENAPI_EXPORT
86SOURCEMETA_CORE_OPENAPI_EXPORT
96 std::optional<JSON::StringView>
name{std::nullopt};
98 std::optional<JSON::StringView>
url{std::nullopt};
100 std::optional<JSON::StringView>
email{std::nullopt};
114 std::optional<JSON::StringView>
url{std::nullopt};
128 std::optional<JSON::StringView>
summary{std::nullopt};
134 std::optional<OpenAPIContact>
contact{std::nullopt};
136 std::optional<OpenAPILicense>
license{std::nullopt};
223 ExternalDocumentation,
304 std::optional<JSON::String>
parent{std::nullopt};
319 std::vector<std::optional<JSON::String>>
tags;
353 std::optional<JSON::StringView>
parent{std::nullopt};
371 using Locations = std::map<JSON::String, Location, std::less<>>;
375 using References = std::map<JSON::String, Reference, std::less<>>;
424 const SchemaResolver &resolver, std::string_view default_base =
"",
425 std::uint64_t max_locations = std::numeric_limits<std::uint64_t>::max());
505 [[nodiscard]] auto
base() const noexcept ->
JSON::StringView;
607 template <std::invocable<const
JSON::String &, const
Location &> F>
609 for (
const auto &entry : this->
locations()) {
610 callback(entry.first, entry.second);
637 template <std::predicate<const JSON::String &, const Location &> F>
638 [[nodiscard]]
auto any_object(
const F &predicate)
const ->
bool {
639 for (
const auto &entry : this->
locations()) {
640 if (predicate(entry.first, entry.second)) {
671 template <std::invocable<const JSON::String &, const Reference &> F>
673 for (
const auto &entry : this->
references()) {
674 callback(entry.first, entry.second);
701 template <std::invocable<const JSON::String &, const Reference &> F>
704 callback(entry.first, entry.second);
730 template <std::invocable<const Operation &> F>
732 for (
const auto &operation : this->
operations()) {
758 template <std::invocable<const Discriminator &> F>
761 callback(discriminator);
861#pragma warning(disable : 4251)
864 std::unique_ptr<Internal> internal_;
882SOURCEMETA_CORE_OPENAPI_EXPORT
897SOURCEMETA_CORE_OPENAPI_EXPORT
959SOURCEMETA_CORE_OPENAPI_EXPORT
1056SOURCEMETA_CORE_OPENAPI_EXPORT
1109SOURCEMETA_CORE_OPENAPI_EXPORT
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
std::basic_string_view< Char, CharTraits > StringView
The string view type used by the JSON document.
Definition json_value.h:54
GenericPointer< JSON::String, PropertyHashJSON< JSON::String > > Pointer
Definition jsonpointer.h:39
SOURCEMETA_CORE_JSONSCHEMA_EXPORT auto schema_resolver(const std::string_view identifier) -> SchemaResolverResult
std::function< SchemaResolverResult(std::string_view)> SchemaResolver
Definition jsonschema_types.h:41
std::function< const SchemaWalkerResult &( std::string_view, const SchemaVocabularies &)> SchemaWalker
Definition jsonschema_types.h:254
std::string_view default_base
Definition openapi.h:983
auto base() const noexcept -> JSON::StringView
std::optional< JSON::StringView > url
Where to find the contact information, as a URI reference.
Definition openapi.h:98
auto for_each_security_reference(const F &callback) const -> void
Definition openapi.h:702
std::optional< OpenAPIContact > contact
The contact information for the API.
Definition openapi.h:134
auto info() const noexcept -> const OpenAPIInfo &
auto schemas() const noexcept -> const SchemaFrame &
auto for_each_object(const F &callback) const -> void
Definition openapi.h:608
ObjectKind
Definition openapi.h:175
@ Document
Definition openapi.h:178
std::optional< JSON::StringView > summary
A short summary of the API.
Definition openapi.h:128
auto operations() const noexcept -> const std::vector< Operation > &
Every operation the described API exposes.
std::optional< OpenAPILicense > license
The license information for the API.
Definition openapi.h:136
auto for_each_discriminator(const F &callback) const -> void
Definition openapi.h:759
std::optional< JSON::StringView > url
Where to find the license used for the API, as a URI reference.
Definition openapi.h:114
JSON::StringView version
Definition openapi.h:126
Callback callback
A callback to report each place that bundling embedded.
Definition openapi.h:1000
auto locations() const noexcept -> const Locations &
Every Object the description holds, keyed by the URI addressing each one.
std::optional< JSON::StringView > name
The identifying name of the contact person or organisation.
Definition openapi.h:96
Namer namer
A callback to name each place that bundling embeds.
Definition openapi.h:1002
JSON::StringView name
The license name used for the API.
Definition openapi.h:109
std::uint64_t max_locations
Definition openapi.h:998
auto object_count() const noexcept -> std::size_t
How many Objects the description holds.
OpenAPIFrame(const JSON &document, const SchemaWalker &walker, const SchemaResolver &resolver, std::string_view default_base="", std::uint64_t max_locations=std::numeric_limits< std::uint64_t >::max())
auto discriminators() const noexcept -> const std::vector< Discriminator > &
auto for_each_operation(const F &callback) const -> void
Definition openapi.h:731
auto standalone() const noexcept -> bool
auto any_object(const F &predicate) const -> bool
Definition openapi.h:638
auto for_each_reference(const F &callback) const -> void
Definition openapi.h:672
auto references() const noexcept -> const References &
auto uri(const Pointer &pointer) const -> JSON::String
std::optional< JSON::StringView > identifier
Definition openapi.h:112
auto traverse(const JSON::StringView uri) const -> const Location *
auto security_references() const noexcept -> const References &
OperationKind
Definition openapi.h:249
std::optional< JSON::StringView > email
The email address of the contact person or organisation.
Definition openapi.h:100
auto reference_count() const noexcept -> std::size_t
std::map< JSON::String, Location, std::less<> > Locations
Definition openapi.h:371
std::function< JSON::String(JSON::StringView, JSON::StringView)> Namer
Definition openapi.h:977
std::optional< JSON::StringView > terms_of_service
Where to find the terms of service for the API, as a URI reference.
Definition openapi.h:132
auto version() const noexcept -> OpenAPIVersion
JSON::StringView title
The title of the API.
Definition openapi.h:123
std::map< JSON::String, Reference, std::less<> > References
Definition openapi.h:375
auto to_json(const std::optional< PointerPositionTracker > &tracker=std::nullopt) const -> JSON
std::optional< JSON::StringView > description
A description of the API, which may be written in CommonMark.
Definition openapi.h:130
std::function< void(JSON::StringView, const sourcemeta::core::Pointer &)> Callback
Definition openapi.h:969
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_kind_name(const OpenAPIFrame::ObjectKind kind) noexcept -> JSON::StringView
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_operation_kind_name(const OpenAPIFrame::OperationKind kind) noexcept -> JSON::StringView
OwnedOrReference< JSON > OpenAPIResolverResult
Definition openapi.h:904
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_bundle(JSON &document, const SchemaWalker &walker, const SchemaResolver &schema_resolver, const OpenAPIResolver &resolver, const OpenAPIBundleOptions &options={}) -> void
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_version(const JSON &document) -> std::optional< OpenAPIVersion >
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_version_name(const OpenAPIVersion version) noexcept -> JSON::StringView
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_format(JSON &document, const OpenAPIFrame &frame) -> void
OpenAPIVersion
Definition openapi.h:43
std::function< OpenAPIResolverResult(std::string_view)> OpenAPIResolver
Definition openapi.h:930
@ OPENAPI_3_2
The OpenAPI Specification 3.2 revision.
Definition openapi.h:47
@ OPENAPI_3_1
The OpenAPI Specification 3.1 revision.
Definition openapi.h:45