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 /// A schema has a `required` field that is not an array.
109 ///
110 /// Error message: `{context} has a non-array `required` field`
111 #[error("{context} has a non-array `required` field")]
112 NonArrayRequired { context: String },
113
114 /// A schema `required` array contains a non-string element.
115 ///
116 /// Error message: `{context} has a non-string required field name`
117 #[error("{context} has a non-string required field name")]
118 NonStringRequiredField { context: String },
119
120 /// An integer schema uses an unsupported format.
121 ///
122 /// Error message: `{context} uses unsupported integer format `{format}``
123 #[error("{context} uses unsupported integer format `{format}`")]
124 UnsupportedIntegerFormat { context: String, format: String },
125
126 /// A number schema uses an unsupported format.
127 ///
128 /// Error message: `{context} uses unsupported number format `{format}``
129 #[error("{context} uses unsupported number format `{format}`")]
130 UnsupportedNumberFormat { context: String, format: String },
131
132 /// An `x-satay.parse-as` value is not a supported target type.
133 ///
134 /// Error message: `{context} uses unsupported x-satay.parse-as `{parse_as}``
135 #[error("{context} uses unsupported x-satay.parse-as `{parse_as}`")]
136 UnsupportedSatayParseAs { context: String, parse_as: String },
137
138 /// An `x-satay.parse-as` value is not a string.
139 ///
140 /// Error message: `{context}.x-satay.parse-as must be a string`
141 #[error("{context}.x-satay.parse-as must be a string")]
142 InvalidSatayParseAs { context: String },
143
144 /// `x-satay.parse-as` was applied to an unsupported wire schema.
145 ///
146 /// 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`
147 #[error(
148 "{context} uses x-satay.parse-as `{parse_as}` on `{kind}`; supported parse-as wire schemas are string schemas, plus integer schemas for bool"
149 )]
150 SatayParseAsRequiresString {
151 context: String,
152 parse_as: String,
153 kind: String,
154 },
155
156 /// An `x-satay.integer-type` value is not a supported Rust integer type.
157 ///
158 /// Error message: `{context} uses unsupported x-satay.integer-type `{integer_type}``
159 #[error("{context} uses unsupported x-satay.integer-type `{integer_type}`")]
160 UnsupportedSatayIntegerType {
161 context: String,
162 integer_type: String,
163 },
164
165 /// An `x-satay.integer-type` value is not a string.
166 ///
167 /// Error message: `{context}.x-satay.integer-type must be a string`
168 #[error("{context}.x-satay.integer-type must be a string")]
169 InvalidSatayIntegerType { context: String },
170
171 /// `x-satay.integer-type` was applied to a non-integer schema.
172 ///
173 /// 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`
174 #[error(
175 "{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"
176 )]
177 SatayIntegerTypeRequiresInteger {
178 context: String,
179 integer_type: String,
180 kind: String,
181 },
182
183 /// An array schema is missing the required `items` field.
184 ///
185 /// Error message: `{context} array schema must declare `items``
186 #[error("{context} array schema must declare `items`")]
187 MissingArrayItems { context: String },
188
189 /// A schema defines an inline object instead of using a `$ref`.
190 ///
191 /// Error message: `{context} is an inline object schema; move it to components/schemas and use `$ref``
192 #[error("{context} is an inline object schema; move it to components/schemas and use `$ref`")]
193 InlineObjectSchema { context: String },
194
195 /// An object schema has no properties (i.e. acts as a map/dictionary), which is unsupported.
196 ///
197 /// Error message: `{context} is an object with neither `properties` nor a supported `additionalProperties` schema`
198 #[error(
199 "{context} is an object with neither `properties` nor a supported `additionalProperties` schema"
200 )]
201 UnsupportedMapObjectSchema { context: String },
202
203 /// A schema uses an unsupported type.
204 ///
205 /// Error message: `{context} uses unsupported schema type `{kind}``
206 #[error("{context} uses unsupported schema type `{kind}`")]
207 UnsupportedSchemaType { context: String, kind: String },
208
209 /// A schema is missing a required `type`, `$ref`, or `enum` declaration.
210 ///
211 /// Error message: `{context} must declare `type`, `$ref`, or `enum``
212 #[error("{context} must declare `type`, `$ref`, or `enum`")]
213 MissingSchemaType { context: String },
214
215 /// A JSON Schema boolean schema was used; Satay has no IR equivalent yet.
216 ///
217 /// Error message: `{context} is a boolean schema; boolean JSON Schemas are not supported yet`
218 #[error("{context} is a boolean schema; boolean JSON Schemas are not supported yet")]
219 UnsupportedBooleanSchema { context: String },
220
221 /// A schema type array contains more than one non-null type.
222 ///
223 /// Error message: `{context} declares multiple non-null schema types; Satay supports at most one plus null`
224 #[error(
225 "{context} declares multiple non-null schema types; Satay supports at most one plus null"
226 )]
227 MultipleNonNullSchemaTypesUnsupported { context: String },
228
229 /// A schema uses a composition keyword (`allOf`, `anyOf`, `oneOf`) in an unsupported context.
230 ///
231 /// Error message: `{context} uses `{keyword}`, which is not supported in this context`
232 #[error("{context} uses `{keyword}`, which is not supported in this context")]
233 UnsupportedComposition {
234 context: String,
235 keyword: &'static str,
236 },
237
238 /// An `allOf` schema combines supported struct flattening with another schema keyword.
239 ///
240 /// Error message: `{context} uses `allOf` with `{keyword}`; only object branch flattening is supported`
241 #[error("{context} uses `allOf` with `{keyword}`; only object branch flattening is supported")]
242 UnsupportedAllOfSiblingKeyword { context: String, keyword: String },
243
244 /// An `allOf` branch cannot be flattened into a generated Rust struct.
245 ///
246 /// Error message: `{context}.allOf[{index}] must be a local component schema reference or object schema with properties`
247 #[error(
248 "{context}.allOf[{index}] must be a local component schema reference or object schema with properties"
249 )]
250 UnsupportedAllOfBranch { context: String, index: usize },
251
252 /// Two `allOf` branches declare the same object property.
253 ///
254 /// Error message: `{context} declares duplicate `allOf` property `{property}``
255 #[error("{context} declares duplicate `allOf` property `{property}`")]
256 DuplicateAllOfProperty { context: String, property: String },
257
258 /// `allOf` component schemas form a recursive flattening cycle.
259 ///
260 /// Error message: `{context} forms a recursive `allOf` cycle through schema `{schema}``
261 #[error("{context} forms a recursive `allOf` cycle through schema `{schema}`")]
262 RecursiveAllOf { context: String, schema: String },
263
264 /// A discriminator union branch component recursively contains its own union.
265 ///
266 /// Error message: `{context} forms a recursive discriminator cycle through branch schema `{schema}``
267 #[error("{context} forms a recursive discriminator cycle through branch schema `{schema}`")]
268 RecursiveDiscriminatorBranch { context: String, schema: String },
269
270 /// An `anyOf` schema combines a supported union with another schema keyword.
271 ///
272 /// Error message: `{context} uses `anyOf` with `{keyword}`; only annotation siblings are supported`
273 #[error("{context} uses `anyOf` with `{keyword}`; only annotation siblings are supported")]
274 UnsupportedAnyOfSiblingKeyword { context: String, keyword: String },
275
276 /// An `anyOf` branch is not a supported union branch.
277 ///
278 /// Error message: `{context}.anyOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema`
279 #[error(
280 "{context}.anyOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema"
281 )]
282 UnsupportedAnyOfBranch { context: String, index: usize },
283
284 /// A `oneOf` schema combines a supported union with another schema keyword.
285 ///
286 /// Error message: `{context} uses `oneOf` with `{keyword}`; only annotation siblings are supported`
287 #[error("{context} uses `oneOf` with `{keyword}`; only annotation siblings are supported")]
288 UnsupportedOneOfSiblingKeyword { context: String, keyword: String },
289
290 /// A `oneOf` branch is not a supported union branch.
291 ///
292 /// Error message: `{context}.oneOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema`
293 #[error(
294 "{context}.oneOf[{index}] must be a local component schema reference, inline string enum, inline primitive schema, or null schema"
295 )]
296 UnsupportedOneOfBranch { context: String, index: usize },
297
298 /// A plain `anyOf` or `oneOf` union has more than one null branch.
299 ///
300 /// Error message: `{context}.{keyword}[{index}] duplicates the union null branch`
301 #[error("{context}.{keyword}[{index}] duplicates the union null branch")]
302 DuplicateUnionNullBranch {
303 context: String,
304 keyword: &'static str,
305 index: usize,
306 },
307
308 /// A nullable plain `anyOf` or `oneOf` union has no non-null branches.
309 ///
310 /// Error message: `{context}.{keyword} must declare at least one non-null branch`
311 #[error("{context}.{keyword} must declare at least one non-null branch")]
312 NullableUnionWithoutVariants {
313 context: String,
314 keyword: &'static str,
315 },
316
317 /// A plain `anyOf` or `oneOf` union has a branch that is statically shadowed by an earlier branch.
318 ///
319 /// Error message: `{context}.{keyword}[{index}] is shadowed by earlier branch {shadowed_by} under ordered serde untagged deserialization`
320 #[error(
321 "{context}.{keyword}[{index}] is shadowed by earlier branch {shadowed_by} under ordered serde untagged deserialization"
322 )]
323 ShadowedUnionBranch {
324 context: String,
325 keyword: &'static str,
326 index: usize,
327 shadowed_by: usize,
328 },
329
330 /// A composition schema declares no branches.
331 ///
332 /// Raised for empty `anyOf` and, today, for empty component `allOf` that is routed
333 /// through the shared empty composition-shape check.
334 ///
335 /// Error message: `{context} must declare at least one `anyOf` branch`
336 #[error("{context} must declare at least one `anyOf` branch")]
337 EmptyAnyOf { context: String },
338
339 /// `anyOf` component schemas form a recursive union cycle.
340 ///
341 /// Error message: `{context} forms a recursive `anyOf` cycle through schema `{schema}``
342 #[error("{context} forms a recursive `anyOf` cycle through schema `{schema}`")]
343 RecursiveAnyOf { context: String, schema: String },
344
345 /// A discriminator union does not use exactly one non-empty `anyOf` or `oneOf` branch list.
346 ///
347 /// Error message: `{context} discriminator unions must declare exactly one non-empty `anyOf` or `oneOf` branch list`
348 #[error(
349 "{context} discriminator unions must declare exactly one non-empty `anyOf` or `oneOf` branch list"
350 )]
351 InvalidDiscriminatorUnion { context: String },
352
353 /// A discriminator union branch is not a local component schema reference.
354 ///
355 /// Error message: `{context}.{keyword}[{index}] must be a local component schema reference when using `discriminator``
356 #[error(
357 "{context}.{keyword}[{index}] must be a local component schema reference when using `discriminator`"
358 )]
359 UnsupportedDiscriminatorBranch {
360 context: String,
361 keyword: &'static str,
362 index: usize,
363 },
364
365 /// A discriminator union branch target does not generate as an object struct.
366 ///
367 /// Error message: `{context} discriminator branch `{schema}` must be an object struct component`
368 #[error("{context} discriminator branch `{schema}` must be an object struct component")]
369 DiscriminatorBranchNotObject { context: String, schema: String },
370
371 /// A discriminator branch object contains the discriminator property.
372 ///
373 /// Error message: `{context} discriminator branch `{schema}` contains discriminator property `{property}``
374 #[error(
375 "{context} discriminator branch `{schema}` contains discriminator property `{property}`"
376 )]
377 DiscriminatorPropertyConflict {
378 context: String,
379 schema: String,
380 property: String,
381 },
382
383 /// A discriminator branch object contains an invalid embedded discriminator property.
384 ///
385 /// Error message: `{context} discriminator branch `{schema}` property `{property}` must be {expected}`
386 #[error("{context} discriminator branch `{schema}` property `{property}` must be {expected}")]
387 InvalidDiscriminatorProperty {
388 context: String,
389 schema: String,
390 property: String,
391 expected: &'static str,
392 },
393
394 /// A discriminator mapping entry targets a non-local schema or a schema outside the union branches.
395 ///
396 /// Error message: `{context}.discriminator.mapping[{value:?}] targets `{target}`, which is not a local union branch schema`
397 #[error(
398 "{context}.discriminator.mapping[{value:?}] targets `{target}`, which is not a local union branch schema"
399 )]
400 InvalidDiscriminatorMapping {
401 context: String,
402 value: String,
403 target: String,
404 },
405
406 /// Multiple discriminator mapping values target the same union branch schema.
407 ///
408 /// Error message: `{context}.discriminator.mapping maps multiple values to branch schema `{schema}``
409 #[error("{context}.discriminator.mapping maps multiple values to branch schema `{schema}`")]
410 DuplicateDiscriminatorMapping { context: String, schema: String },
411
412 /// A discriminator mapping value disagrees with a branch's embedded discriminator property value.
413 ///
414 /// Error message: `{context}.discriminator.mapping maps value `{value}` to branch schema `{schema}`, but the branch declares discriminator value `{actual}`
415 #[error(
416 "{context}.discriminator.mapping maps value `{value}` to branch schema `{schema}`, but the branch declares discriminator value `{actual}`"
417 )]
418 DiscriminatorMappingValueMismatch {
419 context: String,
420 schema: String,
421 value: String,
422 actual: String,
423 },
424
425 /// Multiple discriminator branches resolve to the same discriminator value after implicit defaults are applied.
426 ///
427 /// Error message: `{context}.discriminator resolves multiple branch schemas to value `{value}``
428 #[error("{context}.discriminator resolves multiple branch schemas to value `{value}`")]
429 DuplicateDiscriminatorValue { context: String, value: String },
430
431 // -- Schema constraint validation --
432 /// A string schema specifies a `minLength` greater than its `maxLength`.
433 ///
434 /// Error message: `{context} has minLength {min_length} greater than maxLength {max_length}`
435 #[error("{context} has minLength {min_length} greater than maxLength {max_length}")]
436 InvalidStringLengthBounds {
437 context: String,
438 min_length: u64,
439 max_length: u64,
440 },
441
442 /// A schema uses `uniqueItems`, which cannot be enforced by generated `Vec`-backed types.
443 ///
444 /// Error message: `{context} uses `uniqueItems`; generated Vec-backed types cannot enforce uniqueness yet`
445 #[error(
446 "{context} uses `uniqueItems`; generated Vec-backed types cannot enforce uniqueness yet"
447 )]
448 UniqueItemsUnsupported { context: String },
449
450 /// An array schema specifies `minItems` greater than `maxItems`.
451 ///
452 /// Error message: `{context} has minItems {min_items} greater than maxItems {max_items}`
453 #[error("{context} has minItems {min_items} greater than maxItems {max_items}")]
454 InvalidArrayLengthBounds {
455 context: String,
456 min_items: u64,
457 max_items: u64,
458 },
459
460 /// A schema uses a keyword that is not safely supported.
461 ///
462 /// Error message: `{context} uses `{keyword}`, which is not safely supported yet`
463 #[error("{context} uses `{keyword}`, which is not safely supported yet")]
464 UnsupportedKeyword {
465 context: String,
466 keyword: &'static str,
467 },
468
469 /// A schema keyword that must be a non-negative integer has an invalid value.
470 ///
471 /// Error message: `{context}.{keyword} must be a non-negative integer`
472 #[error("{context}.{keyword} must be a non-negative integer")]
473 InvalidNonNegativeIntegerKeyword {
474 context: String,
475 keyword: &'static str,
476 },
477
478 /// A schema keyword that must be a boolean has an invalid value.
479 ///
480 /// Error message: `{context}.{keyword} must be a boolean`
481 #[error("{context}.{keyword} must be a boolean")]
482 InvalidBooleanKeyword {
483 context: String,
484 keyword: &'static str,
485 },
486
487 /// An `exclusiveMinimum`/`exclusiveMaximum` keyword is present but the corresponding bound is missing.
488 ///
489 /// Error message: `{context}.{exclusive_keyword} requires `{keyword}``
490 #[error("{context}.{exclusive_keyword} requires `{keyword}`")]
491 ExclusiveLimitRequiresBound {
492 context: String,
493 exclusive_keyword: &'static str,
494 keyword: &'static str,
495 },
496
497 /// A schema keyword that must be a finite number has a non-finite value.
498 ///
499 /// Error message: `{context}.{keyword} must be a finite number`
500 #[error("{context}.{keyword} must be a finite number")]
501 InvalidFiniteNumberKeyword {
502 context: String,
503 keyword: &'static str,
504 },
505
506 /// A value expected to be an integer is not.
507 ///
508 /// Error message: `{context} must be an integer`
509 #[error("{context} must be an integer")]
510 ExpectedInteger { context: String },
511
512 /// Integer bounds (minimum/maximum) do not permit any value.
513 ///
514 /// Error message: `{context} integer bounds do not allow any value`
515 #[error("{context} integer bounds do not allow any value")]
516 EmptyIntegerBounds { context: String },
517
518 /// An exclusive integer minimum overflows `i64`.
519 ///
520 /// Error message: `exclusive integer minimum overflows`
521 #[error("exclusive integer minimum overflows")]
522 ExclusiveIntegerMinimumOverflow,
523
524 /// An exclusive integer maximum overflows `i64`.
525 ///
526 /// Error message: `exclusive integer maximum overflows`
527 #[error("exclusive integer maximum overflows")]
528 ExclusiveIntegerMaximumOverflow,
529
530 /// Number bounds (minimum/maximum) do not permit any value.
531 ///
532 /// Error message: `{context} number bounds do not allow any value`
533 #[error("{context} number bounds do not allow any value")]
534 EmptyNumberBounds { context: String },
535
536 // -- Operation, parameter, and response validation --
537 /// An operation does not declare any responses.
538 ///
539 /// Error message: `operation `{operation_id}` must declare responses`
540 #[error("operation `{operation_id}` must declare responses")]
541 MissingOperationResponses { operation_id: String },
542
543 /// A value expected to be an array is not.
544 ///
545 /// Error message: `{context} must be an array`
546 #[error("{context} must be an array")]
547 ExpectedArray { context: String },
548
549 /// A parameter uses an unsupported location (e.g. cookie) instead of path, query, or header.
550 ///
551 /// Error message: `{context} parameter `{wire_name}` is in `{location}`; only path, query, and header parameters are supported`
552 #[error(
553 "{context} parameter `{wire_name}` is in `{location}`; only path, query, and header parameters are supported"
554 )]
555 UnsupportedParameterLocation {
556 context: String,
557 wire_name: String,
558 location: String,
559 },
560
561 /// A parameter uses `content` instead of `schema`.
562 ///
563 /// Error message: `{context} parameter `{wire_name}` uses `content`; schema parameters are required`
564 #[error("{context} parameter `{wire_name}` uses `content`; schema parameters are required")]
565 ContentParameterUnsupported { context: String, wire_name: String },
566
567 /// A parameter is missing a required `schema` declaration.
568 ///
569 /// Error message: `{context} parameter `{wire_name}` must declare schema`
570 #[error("{context} parameter `{wire_name}` must declare schema")]
571 MissingParameterSchema { context: String, wire_name: String },
572
573 /// A parameter is nullable, which is not supported.
574 ///
575 /// Error message: `parameter `{wire_name}` is nullable; nullable parameters are not supported`
576 #[error("parameter `{wire_name}` is nullable; nullable parameters are not supported")]
577 NullableParameterUnsupported { wire_name: String },
578
579 /// A parameter uses `anyOf`, which is not supported for URI/header encoding yet.
580 ///
581 /// Error message: `parameter `{wire_name}` uses `anyOf`; anyOf parameters are not supported yet`
582 #[error("parameter `{wire_name}` uses `anyOf`; anyOf parameters are not supported yet")]
583 AnyOfParameterUnsupported { wire_name: String },
584
585 /// A parameter is a map or arbitrary JSON value, which has no URI/header encoding.
586 ///
587 /// Error message: `parameter `{wire_name}` is a map or JSON value; map parameters are not supported`
588 #[error("parameter `{wire_name}` is a map or JSON value; map parameters are not supported")]
589 MapParameterUnsupported { wire_name: String },
590
591 /// A path parameter is an array, which is not supported.
592 ///
593 /// Error message: `path parameter `{wire_name}` is an array; array path parameter styles are not supported`
594 #[error(
595 "path parameter `{wire_name}` is an array; array path parameter styles are not supported"
596 )]
597 ArrayPathParameterUnsupported { wire_name: String },
598
599 /// A header parameter is an array, which is not supported.
600 ///
601 /// Error message: `header parameter `{wire_name}` is an array; array header parameter styles are not supported`
602 #[error(
603 "header parameter `{wire_name}` is an array; array header parameter styles are not supported"
604 )]
605 ArrayHeaderParameterUnsupported { wire_name: String },
606
607 /// A path parameter does not set `required: true`.
608 ///
609 /// Error message: `path parameter `{wire_name}` must set required: true`
610 #[error("path parameter `{wire_name}` must set required: true")]
611 PathParameterNotRequired { wire_name: String },
612
613 /// A context is missing a required `content` declaration.
614 ///
615 /// Error message: `{context} must declare content`
616 #[error("{context} must declare content")]
617 MissingContent { context: String },
618
619 /// A context is missing the required `application/json` content type.
620 ///
621 /// Error message: `{context} must declare application/json content`
622 #[error("{context} must declare application/json content")]
623 MissingJsonContent { context: String },
624
625 /// A context's `application/json` content is missing a schema.
626 ///
627 /// Error message: `{context} application/json content must declare schema`
628 #[error("{context} application/json content must declare schema")]
629 MissingJsonSchema { context: String },
630
631 /// A response body uses the `default` status, which is not yet supported for decoding.
632 ///
633 /// Error message: `{context} contains a default response body; default response decoding is not supported yet`
634 #[error(
635 "{context} contains a default response body; default response decoding is not supported yet"
636 )]
637 DefaultResponseBodyUnsupported { context: String },
638
639 /// A response contains an invalid HTTP status code string.
640 ///
641 /// Error message: `{context} contains invalid status code `{status}``
642 #[error("{context} contains invalid status code `{status}`")]
643 InvalidStatusCode { context: String, status: String },
644
645 /// A response contains a status code outside the valid 100–599 range.
646 ///
647 /// Error message: `{context} contains out-of-range status code `{status_code}``
648 #[error("{context} contains out-of-range status code `{status_code}`")]
649 OutOfRangeStatusCode { context: String, status_code: u16 },
650
651 /// A response for a given status code is missing `application/json` content.
652 ///
653 /// Error message: `{context} {status} response must declare application/json content`
654 #[error("{context} {status} response must declare application/json content")]
655 MissingResponseJsonContent { context: String, status: String },
656
657 /// A path template contains a parameter that is never closed.
658 ///
659 /// Error message: `path `{path}` contains an unclosed parameter`
660 #[error("path `{path}` contains an unclosed parameter")]
661 UnclosedPathParameter { path: String },
662
663 /// A path template contains an empty parameter (e.g. `{}`).
664 ///
665 /// Error message: `path `{path}` contains an empty parameter`
666 #[error("path `{path}` contains an empty parameter")]
667 EmptyPathParameter { path: String },
668
669 /// A path template references a parameter that is not declared in the operation's parameters.
670 ///
671 /// Error message: `path `{path}` uses parameter `{name}` but it is not declared`
672 #[error("path `{path}` uses parameter `{name}` but it is not declared")]
673 UndeclaredPathParameter { path: String, name: String },
674
675 /// A parameter is declared for a path but never used in the path template.
676 ///
677 /// Error message: `path parameter `{name}` is declared but not used in path `{path}``
678 #[error("path parameter `{name}` is declared but not used in path `{path}`")]
679 UnusedPathParameter { path: String, name: String },
680
681 // -- Reference resolution and JSON shape validation --
682 /// A `$ref` could not be resolved because the referenced component failed validation.
683 ///
684 /// Error message: `failed to resolve reference `{reference}` in {context}: {source}`
685 #[error("failed to resolve reference `{reference}` in {context}: {source}")]
686 ResolveReference {
687 reference: String,
688 context: String,
689 #[source]
690 source: Box<ValidationError>,
691 },
692
693 /// A reference points to an external document; only local (`#`) references are supported.
694 ///
695 /// Error message: `only local references are supported`
696 #[error("only local references are supported")]
697 NonLocalReference,
698
699 /// A local reference is not a valid JSON pointer.
700 ///
701 /// Error message: `local reference must be a JSON pointer`
702 #[error("local reference must be a JSON pointer")]
703 InvalidLocalReference,
704
705 /// A JSON pointer is missing a required token segment.
706 ///
707 /// Error message: `missing `{token}``
708 #[error("missing `{token}`")]
709 MissingJsonPointerToken { token: String },
710
711 /// A `$ref` does not point to the expected `#/components/{section}/…` path.
712 ///
713 /// Error message: `reference `{reference}` must point to #/components/{section}/...`
714 #[error("reference `{reference}` must point to #/components/{section}/...")]
715 InvalidComponentReference {
716 reference: String,
717 section: &'static str,
718 },
719
720 /// A local `$ref` chain references itself.
721 ///
722 /// Error message: `circular reference `{reference}``
723 #[error("circular reference `{reference}`")]
724 CircularReference { reference: String },
725
726 /// A value expected to be an object is not.
727 ///
728 /// Error message: `{context} must be an object`
729 #[error("{context} must be an object")]
730 ExpectedObject { context: String },
731
732 /// A nested field expected to be an object is not.
733 ///
734 /// Error message: `{context}.{field} must be an object`
735 #[error("{context}.{field} must be an object")]
736 ExpectedObjectField {
737 context: String,
738 field: &'static str,
739 },
740}