Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
openapi_error.h
1#ifndef SOURCEMETA_CORE_OPENAPI_ERROR_H_
2#define SOURCEMETA_CORE_OPENAPI_ERROR_H_
3
4#ifndef SOURCEMETA_CORE_OPENAPI_EXPORT
5#include <sourcemeta/core/openapi_export.h>
6#endif
7
8#include <sourcemeta/core/json.h>
9#include <sourcemeta/core/jsonpointer.h>
10
11#include <cstdint> // std::uint64_t
12#include <exception> // std::exception
13#include <string> // std::string
14#include <string_view> // std::string_view
15#include <utility> // std::move
16
17namespace sourcemeta::core {
18
19// Exporting symbols that depends on the standard C++ library is considered
20// safe.
21// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
22#if defined(_MSC_VER)
23#pragma warning(push)
24#pragma warning(disable : 4251 4275)
25#endif
26
40class SOURCEMETA_CORE_OPENAPI_EXPORT OpenAPIError : public std::exception {
41public:
43 OpenAPIError(Pointer location, const char *message)
44 : location_{std::move(location)}, message_{message} {}
45 OpenAPIError(Pointer location, std::string message) = delete;
46 OpenAPIError(Pointer location, std::string &&message) = delete;
47 OpenAPIError(Pointer location, std::string_view message) = delete;
48
52 : base_{std::move(base)}, location_{std::move(location)},
53 message_{message} {}
54 OpenAPIError(JSON::String base, Pointer location,
55 std::string message) = delete;
56 OpenAPIError(JSON::String base, Pointer location,
57 std::string &&message) = delete;
58 OpenAPIError(JSON::String base, Pointer location,
59 std::string_view message) = delete;
60
61 [[nodiscard]] auto what() const noexcept -> const char * override {
62 return this->message_;
63 }
64
67 [[nodiscard]] auto location() const noexcept -> const Pointer & {
68 return this->location_;
69 }
70
73 [[nodiscard]] auto base() const noexcept -> JSON::StringView {
74 return this->base_;
75 }
76
77private:
78 JSON::String base_;
79 Pointer location_;
80 const char *message_;
81};
82
97class SOURCEMETA_CORE_OPENAPI_EXPORT OpenAPIResolutionError
98 : public std::exception {
99public:
103 JSON::String identifier, const char *message)
104 : base_{std::move(base)}, location_{std::move(location)},
105 identifier_{std::move(identifier)}, message_{message} {}
107 JSON::String identifier, std::string message) = delete;
109 JSON::String identifier,
110 std::string &&message) = delete;
112 JSON::String identifier,
113 std::string_view message) = delete;
114
115 [[nodiscard]] auto what() const noexcept -> const char * override {
116 return this->message_;
117 }
118
120 [[nodiscard]] auto identifier() const noexcept -> JSON::StringView {
121 return this->identifier_;
122 }
123
126 [[nodiscard]] auto location() const noexcept -> const Pointer & {
127 return this->location_;
128 }
129
131 [[nodiscard]] auto base() const noexcept -> JSON::StringView {
132 return this->base_;
133 }
134
135private:
136 JSON::String base_;
137 Pointer location_;
138 JSON::String identifier_;
139 const char *message_;
140};
141
156class SOURCEMETA_CORE_OPENAPI_EXPORT OpenAPIReferenceError
157 : public std::exception {
158public:
162 JSON::String identifier, const char *message)
163 : base_{std::move(base)}, location_{std::move(location)},
164 identifier_{std::move(identifier)}, message_{message} {}
166 JSON::String identifier, std::string message) = delete;
168 JSON::String identifier,
169 std::string &&message) = delete;
171 JSON::String identifier,
172 std::string_view message) = delete;
173
174 [[nodiscard]] auto what() const noexcept -> const char * override {
175 return this->message_;
176 }
177
179 [[nodiscard]] auto identifier() const noexcept -> JSON::StringView {
180 return this->identifier_;
181 }
182
185 [[nodiscard]] auto location() const noexcept -> const Pointer & {
186 return this->location_;
187 }
188
190 [[nodiscard]] auto base() const noexcept -> JSON::StringView {
191 return this->base_;
192 }
193
194private:
195 JSON::String base_;
196 Pointer location_;
197 JSON::String identifier_;
198 const char *message_;
199};
200
212class SOURCEMETA_CORE_OPENAPI_EXPORT OpenAPIFrameLimitError
213 : public std::exception {
214public:
216 OpenAPIFrameLimitError(const std::uint64_t limit) : limit_{limit} {}
217
218 [[nodiscard]] auto what() const noexcept -> const char * override {
219 return "The OpenAPI Description exceeds the maximum number of locations "
220 "that framing may register";
221 }
222
224 [[nodiscard]] auto limit() const noexcept -> std::uint64_t {
225 return this->limit_;
226 }
227
228private:
229 std::uint64_t limit_;
230};
231
243class SOURCEMETA_CORE_OPENAPI_EXPORT OpenAPIBundleLimitError
244 : public std::exception {
245public:
247 OpenAPIBundleLimitError(const std::uint64_t limit) : limit_{limit} {}
248
249 [[nodiscard]] auto what() const noexcept -> const char * override {
250 return "The OpenAPI Description exceeds the maximum number of locations "
251 "that bundling may analyse";
252 }
253
255 [[nodiscard]] auto limit() const noexcept -> std::uint64_t {
256 return this->limit_;
257 }
258
259private:
260 std::uint64_t limit_;
261};
262
263#if defined(_MSC_VER)
264#pragma warning(pop)
265#endif
266
267} // namespace sourcemeta::core
268
269#endif
std::basic_string< Char, CharTraits, Allocator< Char > > String
The string type used by the JSON document.
Definition json_value.h:52
Definition json_value.h:39
GenericPointer< JSON::String, PropertyHashJSON< JSON::String > > Pointer
Definition jsonpointer.h:39
auto location() const noexcept -> const Pointer &
Definition openapi_error.h:67
auto base() const noexcept -> JSON::StringView
Definition openapi_error.h:73
OpenAPIReferenceError(JSON::String base, Pointer location, JSON::String identifier, const char *message)
Definition openapi_error.h:161
OpenAPIError(Pointer location, const char *message)
Construct an error from where the problem is and a message.
Definition openapi_error.h:43
auto identifier() const noexcept -> JSON::StringView
The URI that nothing could produce a document for.
Definition openapi_error.h:120
auto base() const noexcept -> JSON::StringView
Get the base URI of the document that makes the reference.
Definition openapi_error.h:190
auto limit() const noexcept -> std::uint64_t
The maximum number of locations that framing was allowed to register.
Definition openapi_error.h:224
auto base() const noexcept -> JSON::StringView
Get the base URI of the document that makes the reference.
Definition openapi_error.h:131
OpenAPIError(JSON::String base, Pointer location, const char *message)
Definition openapi_error.h:51
auto location() const noexcept -> const Pointer &
Definition openapi_error.h:185
OpenAPIResolutionError(JSON::String base, Pointer location, JSON::String identifier, const char *message)
Definition openapi_error.h:102
OpenAPIBundleLimitError(const std::uint64_t limit)
Create a bundling limit error.
Definition openapi_error.h:247
OpenAPIFrameLimitError(const std::uint64_t limit)
Create a framing limit error.
Definition openapi_error.h:216
auto limit() const noexcept -> std::uint64_t
The maximum number of locations that bundling was allowed to register.
Definition openapi_error.h:255
auto location() const noexcept -> const Pointer &
Definition openapi_error.h:126
auto identifier() const noexcept -> JSON::StringView
The URI that the reference names, resolved and canonicalised.
Definition openapi_error.h:179
Definition openapi_error.h:40
Definition openapi_error.h:157
Definition openapi_error.h:98