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_dependencies.h>
14#include <sourcemeta/core/openapi_error.h>
15#include <sourcemeta/core/openapi_types.h>
41namespace sourcemeta::core {
78SOURCEMETA_CORE_OPENAPI_EXPORT
93SOURCEMETA_CORE_OPENAPI_EXPORT
119SOURCEMETA_CORE_OPENAPI_EXPORT
121 -> std::optional<JSON::StringView>;
141SOURCEMETA_CORE_OPENAPI_EXPORT
176SOURCEMETA_CORE_OPENAPI_EXPORT
186 std::optional<JSON::StringView>
name{std::nullopt};
188 std::optional<JSON::StringView>
url{std::nullopt};
190 std::optional<JSON::StringView>
email{std::nullopt};
204 std::optional<JSON::StringView>
url{std::nullopt};
218 std::optional<JSON::StringView>
summary{std::nullopt};
224 std::optional<OpenAPIContact>
contact{std::nullopt};
226 std::optional<OpenAPILicense>
license{std::nullopt};
310 std::optional<JSON::String>
parent{std::nullopt};
325 std::vector<std::optional<JSON::String>>
tags;
365 std::optional<JSON::StringView>
parent{std::nullopt};
383 using Locations = std::map<JSON::String, Location, std::less<>>;
387 using References = std::map<JSON::String, Reference, std::less<>>;
444 const SchemaResolver &resolver,
const std::string_view default_base =
"",
445 std::uint64_t max_locations = std::numeric_limits<std::uint64_t>::max(),
526 [[nodiscard]] auto
base() const noexcept ->
JSON::StringView;
628 template <std::invocable<const
JSON::String &, const
Location &> F>
630 for (
const auto &entry : this->
locations()) {
631 callback(entry.first, entry.second);
658 template <std::predicate<const JSON::String &, const Location &> F>
659 [[nodiscard]]
auto any_object(
const F &predicate)
const ->
bool {
660 for (
const auto &entry : this->
locations()) {
661 if (predicate(entry.first, entry.second)) {
692 template <std::invocable<const JSON::String &, const Reference &> F>
694 for (
const auto &entry : this->
references()) {
695 callback(entry.first, entry.second);
722 template <std::invocable<const JSON::String &, const Reference &> F>
725 callback(entry.first, entry.second);
751 template <std::invocable<const Operation &> F>
753 for (
const auto &operation : this->
operations()) {
779 template <std::invocable<const Discriminator &> F>
782 callback(discriminator);
882#pragma warning(disable : 4251)
885 std::unique_ptr<Internal> internal_;
918SOURCEMETA_CORE_OPENAPI_EXPORT
1015SOURCEMETA_CORE_OPENAPI_EXPORT
1068SOURCEMETA_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:41
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:942
OpenAPIOperationKind OperationKind
How an Operation Object is reached from the entry document.
Definition openapi.h:262
auto base() const noexcept -> JSON::StringView
std::optional< JSON::StringView > url
Where to find the contact information, as a URI reference.
Definition openapi.h:188
auto for_each_security_reference(const F &callback) const -> void
Definition openapi.h:723
std::optional< OpenAPIContact > contact
The contact information for the API.
Definition openapi.h:224
auto info() const noexcept -> const OpenAPIInfo &
auto schemas() const noexcept -> const SchemaFrame &
auto for_each_object(const F &callback) const -> void
Definition openapi.h:629
std::optional< JSON::StringView > summary
A short summary of the API.
Definition openapi.h:218
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:226
auto for_each_discriminator(const F &callback) const -> void
Definition openapi.h:780
std::optional< JSON::StringView > url
Where to find the license used for the API, as a URI reference.
Definition openapi.h:204
JSON::StringView version
Definition openapi.h:216
Callback callback
A callback to report each place that bundling embedded.
Definition openapi.h:959
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:186
Namer namer
A callback to name each place that bundling embeds.
Definition openapi.h:961
JSON::StringView name
The license name used for the API.
Definition openapi.h:199
std::uint64_t max_locations
Definition openapi.h:957
auto object_count() const noexcept -> std::size_t
How many Objects the description holds.
auto discriminators() const noexcept -> const std::vector< Discriminator > &
OpenAPIObjectKind ObjectKind
What kind of Object a position holds.
Definition openapi.h:260
auto for_each_operation(const F &callback) const -> void
Definition openapi.h:752
auto standalone() const noexcept -> bool
auto any_object(const F &predicate) const -> bool
Definition openapi.h:659
auto for_each_reference(const F &callback) const -> void
Definition openapi.h:693
auto references() const noexcept -> const References &
auto uri(const Pointer &pointer) const -> JSON::String
std::optional< JSON::StringView > identifier
Definition openapi.h:202
auto traverse(const JSON::StringView uri) const -> const Location *
auto security_references() const noexcept -> const References &
std::optional< JSON::StringView > email
The email address of the contact person or organisation.
Definition openapi.h:190
auto reference_count() const noexcept -> std::size_t
std::map< JSON::String, Location, std::less<> > Locations
Definition openapi.h:383
OpenAPIFrame(const JSON &document, const SchemaWalker &walker, const SchemaResolver &resolver, const std::string_view default_base="", std::uint64_t max_locations=std::numeric_limits< std::uint64_t >::max(), const OpenAPIFrame *entry=nullptr)
std::function< JSON::String(JSON::StringView, JSON::StringView)> Namer
Definition openapi.h:936
std::optional< JSON::StringView > terms_of_service
Where to find the terms of service for the API, as a URI reference.
Definition openapi.h:222
auto version() const noexcept -> OpenAPIVersion
JSON::StringView title
The title of the API.
Definition openapi.h:213
std::map< JSON::String, Reference, std::less<> > References
Definition openapi.h:387
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:220
std::function< void(JSON::StringView, const sourcemeta::core::Pointer &)> Callback
Definition openapi.h:928
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_is_document(const JSON &document) -> bool
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_base(const JSON &document, const std::string_view retrieval) -> JSON::String
SOURCEMETA_CORE_OPENAPI_EXPORT auto openapi_version_string(const JSON &document) -> std::optional< JSON::StringView >
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:48
std::function< OpenAPIResolverResult(std::string_view)> OpenAPIResolver
Definition openapi_types.h:167
@ OPENAPI_3_0
The OpenAPI Specification 3.0 revision.
Definition openapi.h:50
@ OPENAPI_3_2
The OpenAPI Specification 3.2 revision.
Definition openapi.h:54
@ OPENAPI_3_1
The OpenAPI Specification 3.1 revision.
Definition openapi.h:52