Skip to main content

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