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