satay_codegen/error/validation.rs
1/// Errors that can occur while validating an OpenAPI document.
2///
3/// This enum is [`non_exhaustive`](https://doc.rust-lang.org/reference/attributes/type_system.html)
4/// so new variants may be added in future releases without a semver break.
5#[derive(Debug, thiserror::Error)]
6#[non_exhaustive]
7pub enum ValidationError {
8 // -- Document and component shape validation --
9 /// The OpenAPI version is not supported.
10 ///
11 /// Error message: `unsupported OpenAPI version `{version}`; Satay supports OpenAPI 3.1`
12 #[error("unsupported OpenAPI version `{version}`; Satay supports OpenAPI 3.1")]
13 UnsupportedOpenApiVersion { version: String },
14
15 /// A schema component uses a type that is not supported.
16 ///
17 /// Error message: `unsupported type `{kind}` in schema `{schema}``
18 #[error("unsupported type `{kind}` in schema `{schema}`")]
19 UnsupportedComponentType { schema: String, kind: String },
20
21 /// A schema component is missing a required `type`, `$ref`, `enum`, or `properties` declaration.
22 ///
23 /// Error message: `schema `{schema}` must declare `type`, `$ref`, `enum`, or `properties``
24 #[error("schema `{schema}` must declare `type`, `$ref`, `enum`, or `properties`")]
25 MissingComponentSchemaType { schema: String },
26
27 /// An object schema is missing the required `properties` field.
28 ///
29 /// Error message: `object schema `{schema}` must declare `properties``
30 #[error("object schema `{schema}` must declare `properties`")]
31 MissingObjectProperties { schema: String },
32
33 /// The OpenAPI document is missing the required `paths` field.
34 ///
35 /// Error message: `OpenAPI document must declare `paths``
36 #[error("OpenAPI document must declare `paths`")]
37 MissingPaths,
38
39 // -- Enum and schema type validation --
40 /// A schema uses an enum with a non-string type.
41 ///
42 /// Error message: `{context} uses enum type `{kind}`; only string enums are supported`
43 #[error("{context} uses enum type `{kind}`; only string enums are supported")]
44 UnsupportedEnumType { context: String, kind: String },
45
46 /// A schema declares an enum that is not an array.
47 ///
48 /// Error message: `{context} has a non-array enum`
49 #[error("{context} has a non-array enum")]
50 NonArrayEnum { context: String },
51
52 /// A schema declares an enum with no values.
53 ///
54 /// Error message: `{context} has an empty enum`
55 #[error("{context} has an empty enum")]
56 EmptyEnum { context: String },
57
58 /// A schema enum contains a non-string value.
59 ///
60 /// Error message: `{context} contains a non-string enum value; only string enums are supported`
61 #[error("{context} contains a non-string enum value; only string enums are supported")]
62 NonStringEnumValue { context: String },
63
64 /// A schema declares a `const` value that is not one of its `enum` values.
65 ///
66 /// Error message: `{context} declares a `const` value that is not in its `enum``
67 #[error("{context} declares a `const` value that is not in its `enum`")]
68 ConstNotInEnum { context: String },
69
70 /// An `x-satay.enum-variants` value is not an object.
71 ///
72 /// Error message: `{context}.x-satay.enum-variants must be an object`
73 #[error("{context}.x-satay.enum-variants must be an object")]
74 InvalidSatayEnumVariants { context: String },
75
76 /// An `x-satay.enum-variants` entry points at a value that is not in the enum.
77 ///
78 /// Error message: `{context}.x-satay.enum-variants contains `{wire_name}`, which is not declared in the enum`
79 #[error(
80 "{context}.x-satay.enum-variants contains `{wire_name}`, which is not declared in the enum"
81 )]
82 UnknownSatayEnumVariantValue { context: String, wire_name: String },
83
84 /// An `x-satay.enum-variants` entry has a non-string Rust variant name.
85 ///
86 /// Error message: `{context}.x-satay.enum-variants[{wire_name:?}] must be a string`
87 #[error("{context}.x-satay.enum-variants[{wire_name:?}] must be a string")]
88 InvalidSatayEnumVariantName { context: String, wire_name: String },
89
90 /// An `x-satay.enum-variants` entry uses a name reserved for generated fallback variants.
91 ///
92 /// Error message: `{context}.x-satay.enum-variants[{wire_name:?}] uses reserved fallback variant `{rust_name}``
93 #[error(
94 "{context}.x-satay.enum-variants[{wire_name:?}] uses reserved fallback variant `{rust_name}`"
95 )]
96 ReservedSatayEnumVariantName {
97 context: String,
98 wire_name: String,
99 rust_name: String,
100 },
101
102 /// Two `x-satay.enum-variants` entries produce the same Rust variant name.
103 ///
104 /// Error message: `{context}.x-satay.enum-variants maps multiple values to `{rust_name}``
105 #[error("{context}.x-satay.enum-variants maps multiple values to `{rust_name}`")]
106 DuplicateSatayEnumVariantName { context: String, rust_name: String },
107
108 /// An operation-level `x-satay` extension is not an object.
109 ///
110 /// Error message: `operation `{operation_id}` has a non-object `x-satay` extension`
111 #[error("operation `{operation_id}` has a non-object `x-satay` extension")]
112 OperationSatayNotObject { operation_id: String },
113
114 /// An operation-level `x-satay` extension uses an unsupported key.
115 ///
116 /// Error message: `operation `{operation_id}` uses unsupported `x-satay` key `{key}`; only `skip` is supported`
117 #[error(
118 "operation `{operation_id}` uses unsupported `x-satay` key `{key}`; only `skip` is supported"
119 )]
120 UnsupportedOperationSatayKey { operation_id: String, key: String },
121
122 /// An operation-level `x-satay.skip` value is not a boolean.
123 ///
124 /// Error message: `operation `{operation_id}` `x-satay.skip` must be a boolean`
125 #[error("operation `{operation_id}` `x-satay.skip` must be a boolean")]
126 OperationSataySkipNotBoolean { operation_id: String },
127
128 /// A schema has a `required` field that is not an array.
129 ///
130 /// Error message: `{context} has a non-array `required` field`
131 #[error("{context} has a non-array `required` field")]
132 NonArrayRequired { context: String },
133
134 /// A schema `required` array contains a non-string element.
135 ///
136 /// Error message: `{context} has a non-string required field name`
137 #[error("{context} has a non-string required field name")]
138 NonStringRequiredField { context: String },
139
140 /// An integer schema uses an unsupported format.
141 ///
142 /// Error message: `{context} uses unsupported integer format `{format}``
143 #[error("{context} uses unsupported integer format `{format}`")]
144 UnsupportedIntegerFormat { context: String, format: String },
145
146 /// A number schema uses an unsupported format.
147 ///
148 /// Error message: `{context} uses unsupported number format `{format}``
149 #[error("{context} uses unsupported number format `{format}`")]
150 UnsupportedNumberFormat { context: String, format: String },
151
152 /// An `x-satay.parse-as` value is not a supported target type.
153 ///
154 /// Error message: `{context} uses unsupported x-satay.parse-as `{parse_as}``
155 #[error("{context} uses unsupported x-satay.parse-as `{parse_as}`")]
156 UnsupportedSatayParseAs { context: String, parse_as: String },
157
158 /// An `x-satay.parse-as` value is not a string.
159 ///
160 /// Error message: `{context}.x-satay.parse-as must be a string`
161 #[error("{context}.x-satay.parse-as must be a string")]
162 InvalidSatayParseAs { context: String },
163
164 /// `x-satay.parse-as` was applied to an unsupported wire schema.
165 ///
166 /// Error message: `{context} uses x-satay.parse-as `{parse_as}` on `{kind}`; supported parse-as wire schemas are string schemas, plus integer schemas for bool`
167 #[error(
168 "{context} uses x-satay.parse-as `{parse_as}` on `{kind}`; supported parse-as wire schemas are string schemas, plus integer schemas for bool"
169 )]
170 SatayParseAsRequiresString {
171 context: String,
172 parse_as: String,
173 kind: String,
174 },
175
176 /// An `x-satay.none-if` value is not an array.
177 ///
178 /// Error message: `{context}.x-satay.none-if must be an array`
179 #[error("{context}.x-satay.none-if must be an array")]
180 InvalidSatayNoneIf { context: String },
181
182 /// An `x-satay.none-if` array is empty.
183 ///
184 /// Error message: `{context}.x-satay.none-if must contain at least one string`
185 #[error("{context}.x-satay.none-if must contain at least one string")]
186 EmptySatayNoneIf { context: String },
187
188 /// An `x-satay.none-if` entry is not a string.
189 ///
190 /// Error message: `{context}.x-satay.none-if values must be strings`
191 #[error("{context}.x-satay.none-if values must be strings")]
192 InvalidSatayNoneIfValue { context: String },
193
194 /// `x-satay.none-if` was applied outside a struct property.
195 ///
196 /// Error message: `{context} uses x-satay.none-if outside a struct field`
197 #[error("{context} uses x-satay.none-if outside a struct field")]
198 SatayNoneIfRequiresStructField { context: String },
199
200 /// `x-satay.none-if` was not paired with a string-backed parser.
201 ///
202 /// Error message: `{context} uses x-satay.none-if without a string-backed x-satay.parse-as`
203 #[error("{context} uses x-satay.none-if without a string-backed x-satay.parse-as")]
204 SatayNoneIfRequiresParsedString { context: String },
205
206 /// `x-satay.none-if` and `x-satay.treat-error-as-none` were combined.
207 ///
208 /// Error message: `{context} cannot combine x-satay.none-if with x-satay.treat-error-as-none`
209 #[error("{context} cannot combine x-satay.none-if with x-satay.treat-error-as-none")]
210 ConflictingSatayNoneHandling { context: String },
211
212 /// An `x-satay.integer-type` value is not a supported Rust integer type.
213 ///
214 /// Error message: `{context} uses unsupported x-satay.integer-type `{integer_type}``
215 #[error("{context} uses unsupported x-satay.integer-type `{integer_type}`")]
216 UnsupportedSatayIntegerType {
217 context: String,
218 integer_type: String,
219 },
220
221 /// An `x-satay.integer-type` value is not a string.
222 ///
223 /// Error message: `{context}.x-satay.integer-type must be a string`
224 #[error("{context}.x-satay.integer-type must be a string")]
225 InvalidSatayIntegerType { context: String },
226
227 /// `x-satay.integer-type` was applied to a non-integer schema.
228 ///
229 /// Error message: `{context} uses x-satay.integer-type `{integer_type}` on `{kind}`; supported integer-type wire schemas are integer schemas and string schemas with x-satay.parse-as integer-range`
230 #[error(
231 "{context} uses x-satay.integer-type `{integer_type}` on `{kind}`; supported integer-type wire schemas are integer schemas and string schemas with x-satay.parse-as integer-range"
232 )]
233 SatayIntegerTypeRequiresInteger {
234 context: String,
235 integer_type: String,
236 kind: String,
237 },
238
239 /// An array schema is missing the required `items` field.
240 ///
241 /// Error message: `{context} array schema must declare `items``
242 #[error("{context} array schema must declare `items`")]
243 MissingArrayItems { context: String },
244
245 /// A schema defines an inline object instead of using a `$ref`.
246 ///
247 /// Error message: `{context} is an inline object schema; move it to components/schemas and use `$ref``
248 #[error("{context} is an inline object schema; move it to components/schemas and use `$ref`")]
249 InlineObjectSchema { context: String },
250
251 /// An object schema has no properties (i.e. acts as a map/dictionary), which is unsupported.
252 ///
253 /// Error message: `{context} is an object with neither `properties` nor a supported `additionalProperties` schema`
254 #[error(
255 "{context} is an object with neither `properties` nor a supported `additionalProperties` schema"
256 )]
257 UnsupportedMapObjectSchema { context: String },
258
259 /// A schema uses an unsupported type.
260 ///
261 /// Error message: `{context} uses unsupported schema type `{kind}``
262 #[error("{context} uses unsupported schema type `{kind}`")]
263 UnsupportedSchemaType { context: String, kind: String },
264
265 /// A schema is missing a required `type`, `$ref`, or `enum` declaration.
266 ///
267 /// Error message: `{context} must declare `type`, `$ref`, or `enum``
268 #[error("{context} must declare `type`, `$ref`, or `enum`")]
269 MissingSchemaType { context: String },
270
271 /// A JSON Schema boolean schema was used; Satay has no IR equivalent yet.
272 ///
273 /// Error message: `{context} is a boolean schema; boolean JSON Schemas are not supported yet`
274 #[error("{context} is a boolean schema; boolean JSON Schemas are not supported yet")]
275 UnsupportedBooleanSchema { context: String },
276
277 /// A schema type array contains more than one non-null type.
278 ///
279 /// Error message: `{context} declares multiple non-null schema types; Satay supports at most one plus null`
280 #[error(
281 "{context} declares multiple non-null schema types; Satay supports at most one plus null"
282 )]
283 MultipleNonNullSchemaTypesUnsupported { context: String },
284
285 /// A schema uses a composition keyword (`allOf`, `anyOf`, `oneOf`) in an unsupported context.
286 ///
287 /// Error message: `{context} uses `{keyword}`, which is not supported in this context`
288 #[error("{context} uses `{keyword}`, which is not supported in this context")]
289 UnsupportedComposition {
290 context: String,
291 keyword: &'static str,
292 },
293
294 /// A schema uses a sibling beside `$ref` that Satay cannot apply.
295 ///
296 /// Error message: `{context} uses unsupported `$ref` sibling `{keyword}``
297 #[error("{context} uses unsupported `$ref` sibling `{keyword}`")]
298 UnsupportedRefSiblingKeyword { context: String, keyword: String },
299
300 /// An `allOf` schema combines supported struct flattening with another schema keyword.
301 ///
302 /// Error message: `{context} uses `allOf` with `{keyword}`; only object branch flattening is supported`
303 #[error("{context} uses `allOf` with `{keyword}`; only object branch flattening is supported")]
304 UnsupportedAllOfSiblingKeyword { context: String, keyword: String },
305
306 /// An `allOf` branch cannot be flattened into a generated Rust struct.
307 ///
308 /// Error message: `{context}.allOf[{index}] must be a local component schema reference or object schema with properties`
309 #[error(
310 "{context}.allOf[{index}] must be a local component schema reference or object schema with properties"
311 )]
312 UnsupportedAllOfBranch { context: String, index: usize },
313
314 /// Two `allOf` branches declare the same object property.
315 ///
316 /// Error message: `{context} declares duplicate `allOf` property `{property}``
317 #[error("{context} declares duplicate `allOf` property `{property}`")]
318 DuplicateAllOfProperty { context: String, property: String },
319
320 /// `allOf` component schemas form a recursive flattening cycle.
321 ///
322 /// Error message: `{context} forms a recursive `allOf` cycle through schema `{schema}``
323 #[error("{context} forms a recursive `allOf` cycle through schema `{schema}`")]
324 RecursiveAllOf { context: String, schema: String },
325
326 /// A discriminator union branch component recursively contains its own union.
327 ///
328 /// Error message: `{context} forms a recursive discriminator cycle through branch schema `{schema}``
329 #[error("{context} forms a recursive discriminator cycle through branch schema `{schema}`")]
330 RecursiveDiscriminatorBranch { context: String, schema: String },
331
332 /// An `anyOf` schema combines a supported union with another schema keyword.
333 ///
334 /// Error message: `{context} uses `anyOf` with `{keyword}`; only annotation siblings are supported`
335 #[error("{context} uses `anyOf` with `{keyword}`; only annotation siblings are supported")]
336 UnsupportedAnyOfSiblingKeyword { context: String, keyword: String },
337
338 /// An `anyOf` branch is not a supported union branch.
339 ///
340 /// Error message: `{context}.anyOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema`
341 #[error(
342 "{context}.anyOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema"
343 )]
344 UnsupportedAnyOfBranch { context: String, index: usize },
345
346 /// A `oneOf` schema combines a supported union with another schema keyword.
347 ///
348 /// Error message: `{context} uses `oneOf` with `{keyword}`; only annotation siblings are supported`
349 #[error("{context} uses `oneOf` with `{keyword}`; only annotation siblings are supported")]
350 UnsupportedOneOfSiblingKeyword { context: String, keyword: String },
351
352 /// A `oneOf` branch is not a supported union branch.
353 ///
354 /// Error message: `{context}.oneOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema`
355 #[error(
356 "{context}.oneOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema"
357 )]
358 UnsupportedOneOfBranch { context: String, index: usize },
359
360 /// A plain `anyOf` or `oneOf` union has more than one null branch.
361 ///
362 /// Error message: `{context}.{keyword}[{index}] duplicates the union null branch`
363 #[error("{context}.{keyword}[{index}] duplicates the union null branch")]
364 DuplicateUnionNullBranch {
365 context: String,
366 keyword: &'static str,
367 index: usize,
368 },
369
370 /// An open string enum `anyOf` repeats an enum or `const` value across branches.
371 ///
372 /// Error message: `{context} declares duplicate open string enum value `{value}` across `anyOf` branches`
373 #[error(
374 "{context} declares duplicate open string enum value `{value}` across `anyOf` branches"
375 )]
376 DuplicateOpenStringEnumValue { context: String, value: String },
377
378 /// A nullable plain `anyOf` or `oneOf` union has no non-null branches.
379 ///
380 /// Error message: `{context}.{keyword} must declare at least one non-null branch`
381 #[error("{context}.{keyword} must declare at least one non-null branch")]
382 NullableUnionWithoutVariants {
383 context: String,
384 keyword: &'static str,
385 },
386
387 /// A plain `anyOf` or `oneOf` union has a branch that is statically shadowed by an earlier branch.
388 ///
389 /// Error message: `{context}.{keyword}[{index}] is shadowed by earlier branch {shadowed_by} under ordered serde untagged deserialization`
390 #[error(
391 "{context}.{keyword}[{index}] is shadowed by earlier branch {shadowed_by} under ordered serde untagged deserialization"
392 )]
393 ShadowedUnionBranch {
394 context: String,
395 keyword: &'static str,
396 index: usize,
397 shadowed_by: usize,
398 },
399
400 /// A composition schema declares no branches.
401 ///
402 /// Raised for empty `anyOf` and, today, for empty component `allOf` that is routed
403 /// through the shared empty composition-shape check.
404 ///
405 /// Error message: `{context} must declare at least one `anyOf` branch`
406 #[error("{context} must declare at least one `anyOf` branch")]
407 EmptyAnyOf { context: String },
408
409 /// `anyOf` component schemas form a recursive union cycle.
410 ///
411 /// Error message: `{context} forms a recursive `anyOf` cycle through schema `{schema}``
412 #[error("{context} forms a recursive `anyOf` cycle through schema `{schema}`")]
413 RecursiveAnyOf { context: String, schema: String },
414
415 /// A discriminator union does not use exactly one non-empty `anyOf` or `oneOf` branch list.
416 ///
417 /// Error message: `{context} discriminator unions must declare exactly one non-empty `anyOf` or `oneOf` branch list`
418 #[error(
419 "{context} discriminator unions must declare exactly one non-empty `anyOf` or `oneOf` branch list"
420 )]
421 InvalidDiscriminatorUnion { context: String },
422
423 /// A discriminator union branch is not a local component schema reference.
424 ///
425 /// Error message: `{context}.{keyword}[{index}] must be a local component schema reference when using `discriminator``
426 #[error(
427 "{context}.{keyword}[{index}] must be a local component schema reference when using `discriminator`"
428 )]
429 UnsupportedDiscriminatorBranch {
430 context: String,
431 keyword: &'static str,
432 index: usize,
433 },
434
435 /// A discriminator union branch target does not generate as an object struct.
436 ///
437 /// Error message: `{context} discriminator branch `{schema}` must be an object struct component`
438 #[error("{context} discriminator branch `{schema}` must be an object struct component")]
439 DiscriminatorBranchNotObject { context: String, schema: String },
440
441 /// A discriminator branch object contains the discriminator property.
442 ///
443 /// Error message: `{context} discriminator branch `{schema}` contains discriminator property `{property}``
444 #[error(
445 "{context} discriminator branch `{schema}` contains discriminator property `{property}`"
446 )]
447 DiscriminatorPropertyConflict {
448 context: String,
449 schema: String,
450 property: String,
451 },
452
453 /// A discriminator branch object contains an invalid embedded discriminator property.
454 ///
455 /// Error message: `{context} discriminator branch `{schema}` property `{property}` must be {expected}`
456 #[error("{context} discriminator branch `{schema}` property `{property}` must be {expected}")]
457 InvalidDiscriminatorProperty {
458 context: String,
459 schema: String,
460 property: String,
461 expected: &'static str,
462 },
463
464 /// A discriminator mapping entry targets a non-local schema or a schema outside the union branches.
465 ///
466 /// Error message: `{context}.discriminator.mapping[{value:?}] targets `{target}`, which is not a local union branch schema`
467 #[error(
468 "{context}.discriminator.mapping[{value:?}] targets `{target}`, which is not a local union branch schema"
469 )]
470 InvalidDiscriminatorMapping {
471 context: String,
472 value: String,
473 target: String,
474 },
475
476 /// Multiple discriminator mapping values target the same union branch schema.
477 ///
478 /// Error message: `{context}.discriminator.mapping maps multiple values to branch schema `{schema}``
479 #[error("{context}.discriminator.mapping maps multiple values to branch schema `{schema}`")]
480 DuplicateDiscriminatorMapping { context: String, schema: String },
481
482 /// A discriminator mapping value disagrees with a branch's embedded discriminator property value.
483 ///
484 /// Error message: `{context}.discriminator.mapping maps value `{value}` to branch schema `{schema}`, but the branch declares discriminator value `{actual}`
485 #[error(
486 "{context}.discriminator.mapping maps value `{value}` to branch schema `{schema}`, but the branch declares discriminator value `{actual}`"
487 )]
488 DiscriminatorMappingValueMismatch {
489 context: String,
490 schema: String,
491 value: String,
492 actual: String,
493 },
494
495 /// Multiple discriminator branches resolve to the same discriminator value after implicit defaults are applied.
496 ///
497 /// Error message: `{context}.discriminator resolves multiple branch schemas to value `{value}``
498 #[error("{context}.discriminator resolves multiple branch schemas to value `{value}`")]
499 DuplicateDiscriminatorValue { context: String, value: String },
500
501 // -- Schema constraint validation --
502 /// A string schema specifies a `minLength` greater than its `maxLength`.
503 ///
504 /// Error message: `{context} has minLength {min_length} greater than maxLength {max_length}`
505 #[error("{context} has minLength {min_length} greater than maxLength {max_length}")]
506 InvalidStringLengthBounds {
507 context: String,
508 min_length: u64,
509 max_length: u64,
510 },
511
512 /// A schema uses `uniqueItems`, which cannot be enforced by generated `Vec`-backed types.
513 ///
514 /// Error message: `{context} uses `uniqueItems`; generated Vec-backed types cannot enforce uniqueness yet`
515 #[error(
516 "{context} uses `uniqueItems`; generated Vec-backed types cannot enforce uniqueness yet"
517 )]
518 UniqueItemsUnsupported { context: String },
519
520 /// An array schema specifies `minItems` greater than `maxItems`.
521 ///
522 /// Error message: `{context} has minItems {min_items} greater than maxItems {max_items}`
523 #[error("{context} has minItems {min_items} greater than maxItems {max_items}")]
524 InvalidArrayLengthBounds {
525 context: String,
526 min_items: u64,
527 max_items: u64,
528 },
529
530 /// A schema uses a keyword that is not safely supported.
531 ///
532 /// Error message: `{context} uses `{keyword}`, which is not safely supported yet`
533 #[error("{context} uses `{keyword}`, which is not safely supported yet")]
534 UnsupportedKeyword {
535 context: String,
536 keyword: &'static str,
537 },
538
539 /// A schema keyword that must be a non-negative integer has an invalid value.
540 ///
541 /// Error message: `{context}.{keyword} must be a non-negative integer`
542 #[error("{context}.{keyword} must be a non-negative integer")]
543 InvalidNonNegativeIntegerKeyword {
544 context: String,
545 keyword: &'static str,
546 },
547
548 /// A schema keyword that must be a boolean has an invalid value.
549 ///
550 /// Error message: `{context}.{keyword} must be a boolean`
551 #[error("{context}.{keyword} must be a boolean")]
552 InvalidBooleanKeyword {
553 context: String,
554 keyword: &'static str,
555 },
556
557 /// An `exclusiveMinimum`/`exclusiveMaximum` keyword is present but the corresponding bound is missing.
558 ///
559 /// Error message: `{context}.{exclusive_keyword} requires `{keyword}``
560 #[error("{context}.{exclusive_keyword} requires `{keyword}`")]
561 ExclusiveLimitRequiresBound {
562 context: String,
563 exclusive_keyword: &'static str,
564 keyword: &'static str,
565 },
566
567 /// A schema keyword that must be a finite number has a non-finite value.
568 ///
569 /// Error message: `{context}.{keyword} must be a finite number`
570 #[error("{context}.{keyword} must be a finite number")]
571 InvalidFiniteNumberKeyword {
572 context: String,
573 keyword: &'static str,
574 },
575
576 /// A value expected to be an integer is not.
577 ///
578 /// Error message: `{context} must be an integer`
579 #[error("{context} must be an integer")]
580 ExpectedInteger { context: String },
581
582 /// Integer bounds (minimum/maximum) do not permit any value.
583 ///
584 /// Error message: `{context} integer bounds do not allow any value`
585 #[error("{context} integer bounds do not allow any value")]
586 EmptyIntegerBounds { context: String },
587
588 /// An exclusive integer minimum overflows `i64`.
589 ///
590 /// Error message: `exclusive integer minimum overflows`
591 #[error("exclusive integer minimum overflows")]
592 ExclusiveIntegerMinimumOverflow,
593
594 /// An exclusive integer maximum overflows `i64`.
595 ///
596 /// Error message: `exclusive integer maximum overflows`
597 #[error("exclusive integer maximum overflows")]
598 ExclusiveIntegerMaximumOverflow,
599
600 /// Number bounds (minimum/maximum) do not permit any value.
601 ///
602 /// Error message: `{context} number bounds do not allow any value`
603 #[error("{context} number bounds do not allow any value")]
604 EmptyNumberBounds { context: String },
605
606 // -- Operation, parameter, and response validation --
607 /// An operation does not declare any responses.
608 ///
609 /// Error message: `operation `{operation_id}` must declare responses`
610 #[error("operation `{operation_id}` must declare responses")]
611 MissingOperationResponses { operation_id: String },
612
613 /// A value expected to be an array is not.
614 ///
615 /// Error message: `{context} must be an array`
616 #[error("{context} must be an array")]
617 ExpectedArray { context: String },
618
619 /// A parameter uses an unsupported location (e.g. cookie) instead of path, query, or header.
620 ///
621 /// Error message: `{context} parameter `{wire_name}` is in `{location}`; only path, query, and header parameters are supported`
622 #[error(
623 "{context} parameter `{wire_name}` is in `{location}`; only path, query, and header parameters are supported"
624 )]
625 UnsupportedParameterLocation {
626 context: String,
627 wire_name: String,
628 location: String,
629 },
630
631 /// A parameter uses `content` instead of `schema`.
632 ///
633 /// Error message: `{context} parameter `{wire_name}` uses `content`; schema parameters are required`
634 #[error("{context} parameter `{wire_name}` uses `content`; schema parameters are required")]
635 ContentParameterUnsupported { context: String, wire_name: String },
636
637 /// A parameter is missing a required `schema` declaration.
638 ///
639 /// Error message: `{context} parameter `{wire_name}` must declare schema`
640 #[error("{context} parameter `{wire_name}` must declare schema")]
641 MissingParameterSchema { context: String, wire_name: String },
642
643 /// A parameter is nullable, which is not supported.
644 ///
645 /// Error message: `parameter `{wire_name}` is nullable; nullable parameters are not supported`
646 #[error("parameter `{wire_name}` is nullable; nullable parameters are not supported")]
647 NullableParameterUnsupported { wire_name: String },
648
649 /// A parameter uses `anyOf`, which is not supported for URI/header encoding yet.
650 ///
651 /// Error message: `parameter `{wire_name}` uses `anyOf`; anyOf parameters are not supported yet`
652 #[error("parameter `{wire_name}` uses `anyOf`; anyOf parameters are not supported yet")]
653 AnyOfParameterUnsupported { wire_name: String },
654
655 /// A parameter is a map or arbitrary JSON value, which has no URI/header encoding.
656 ///
657 /// Error message: `parameter `{wire_name}` is a map or JSON value; map parameters are not supported`
658 #[error("parameter `{wire_name}` is a map or JSON value; map parameters are not supported")]
659 MapParameterUnsupported { wire_name: String },
660
661 /// A path parameter is an array, which is not supported.
662 ///
663 /// Error message: `path parameter `{wire_name}` is an array; array path parameter styles are not supported`
664 #[error(
665 "path parameter `{wire_name}` is an array; array path parameter styles are not supported"
666 )]
667 ArrayPathParameterUnsupported { wire_name: String },
668
669 /// A header parameter is an array, which is not supported.
670 ///
671 /// Error message: `header parameter `{wire_name}` is an array; array header parameter styles are not supported`
672 #[error(
673 "header parameter `{wire_name}` is an array; array header parameter styles are not supported"
674 )]
675 ArrayHeaderParameterUnsupported { wire_name: String },
676
677 /// A path parameter does not set `required: true`.
678 ///
679 /// Error message: `path parameter `{wire_name}` must set required: true`
680 #[error("path parameter `{wire_name}` must set required: true")]
681 PathParameterNotRequired { wire_name: String },
682
683 /// A context is missing a required `content` declaration.
684 ///
685 /// Error message: `{context} must declare content`
686 #[error("{context} must declare content")]
687 MissingContent { context: String },
688
689 /// A context is missing the required `application/json` content type.
690 ///
691 /// Error message: `{context} must declare application/json content`
692 #[error("{context} must declare application/json content")]
693 MissingJsonContent { context: String },
694
695 /// A context's `application/json` content is missing a schema.
696 ///
697 /// Error message: `{context} application/json content must declare schema`
698 #[error("{context} application/json content must declare schema")]
699 MissingJsonSchema { context: String },
700
701 /// A response body uses the `default` status, which is not yet supported for decoding.
702 ///
703 /// Error message: `{context} contains a default response body; default response decoding is not supported yet`
704 #[error(
705 "{context} contains a default response body; default response decoding is not supported yet"
706 )]
707 DefaultResponseBodyUnsupported { context: String },
708
709 /// A response contains an invalid HTTP status code string.
710 ///
711 /// Error message: `{context} contains invalid status code `{status}``
712 #[error("{context} contains invalid status code `{status}`")]
713 InvalidStatusCode { context: String, status: String },
714
715 /// A response contains a status code outside the valid 100–599 range.
716 ///
717 /// Error message: `{context} contains out-of-range status code `{status_code}``
718 #[error("{context} contains out-of-range status code `{status_code}`")]
719 OutOfRangeStatusCode { context: String, status_code: u16 },
720
721 /// A response for a given status code is missing `application/json` content.
722 ///
723 /// Error message: `{context} {status} response must declare application/json content`
724 #[error("{context} {status} response must declare application/json content")]
725 MissingResponseJsonContent { context: String, status: String },
726
727 /// A path template contains a parameter that is never closed.
728 ///
729 /// Error message: `path `{path}` contains an unclosed parameter`
730 #[error("path `{path}` contains an unclosed parameter")]
731 UnclosedPathParameter { path: String },
732
733 /// A path template contains an empty parameter (e.g. `{}`).
734 ///
735 /// Error message: `path `{path}` contains an empty parameter`
736 #[error("path `{path}` contains an empty parameter")]
737 EmptyPathParameter { path: String },
738
739 /// A path template references a parameter that is not declared in the operation's parameters.
740 ///
741 /// Error message: `path `{path}` uses parameter `{name}` but it is not declared`
742 #[error("path `{path}` uses parameter `{name}` but it is not declared")]
743 UndeclaredPathParameter { path: String, name: String },
744
745 /// A parameter is declared for a path but never used in the path template.
746 ///
747 /// Error message: `path parameter `{name}` is declared but not used in path `{path}``
748 #[error("path parameter `{name}` is declared but not used in path `{path}`")]
749 UnusedPathParameter { path: String, name: String },
750
751 // -- Reference resolution and JSON shape validation --
752 /// A `$ref` could not be resolved because the referenced component failed validation.
753 ///
754 /// Error message: `failed to resolve reference `{reference}` in {context}: {source}`
755 #[error("failed to resolve reference `{reference}` in {context}: {source}")]
756 ResolveReference {
757 reference: String,
758 context: String,
759 #[source]
760 source: Box<ValidationError>,
761 },
762
763 /// A reference points to an external document; only local (`#`) references are supported.
764 ///
765 /// Error message: `only local references are supported`
766 #[error("only local references are supported")]
767 NonLocalReference,
768
769 /// A local reference is not a valid JSON pointer.
770 ///
771 /// Error message: `local reference must be a JSON pointer`
772 #[error("local reference must be a JSON pointer")]
773 InvalidLocalReference,
774
775 /// A JSON pointer is missing a required token segment.
776 ///
777 /// Error message: `missing `{token}``
778 #[error("missing `{token}`")]
779 MissingJsonPointerToken { token: String },
780
781 /// A `$ref` does not point to the expected `#/components/{section}/…` path.
782 ///
783 /// Error message: `reference `{reference}` must point to #/components/{section}/...`
784 #[error("reference `{reference}` must point to #/components/{section}/...")]
785 InvalidComponentReference {
786 reference: String,
787 section: &'static str,
788 },
789
790 /// A local `$ref` chain references itself.
791 ///
792 /// Error message: `circular reference `{reference}``
793 #[error("circular reference `{reference}`")]
794 CircularReference { reference: String },
795
796 /// A value expected to be an object is not.
797 ///
798 /// Error message: `{context} must be an object`
799 #[error("{context} must be an object")]
800 ExpectedObject { context: String },
801
802 /// A nested field expected to be an object is not.
803 ///
804 /// Error message: `{context}.{field} must be an object`
805 #[error("{context}.{field} must be an object")]
806 ExpectedObjectField {
807 context: String,
808 field: &'static str,
809 },
810}