cat_gateway/service/common/responses/
code_412_precondition_failed.rs1use poem_openapi::{
4 types::{Example, ToJSON},
5 Object,
6};
7
8use crate::service::{common, common::types::array_types::impl_array_types};
9
10#[derive(Object, Debug, Clone)]
12#[oai(example)]
13pub(crate) struct PreconditionFailed {
14 detail: ContentErrorDetailList,
19}
20
21impl PreconditionFailed {
22 pub(crate) fn new(errors: Vec<poem::Error>) -> Self {
24 let mut detail = vec![];
25 for error in errors {
26 detail.push(ContentErrorDetail::new(&error));
27 }
28
29 Self {
30 detail: detail.into(),
31 }
32 }
33}
34
35impl Example for PreconditionFailed {
36 fn example() -> Self {
38 Self {
39 detail: Example::example(),
40 }
41 }
42}
43
44impl_array_types!(
46 ContentErrorDetailList,
47 ContentErrorDetail,
48 Some(poem_openapi::registry::MetaSchema {
49 example: Self::example().to_json(),
50 min_items: Some(1),
51 max_items: Some(1000),
52 items: Some(Box::new(ContentErrorDetail::schema_ref())),
53 ..poem_openapi::registry::MetaSchema::ANY
54 })
55);
56
57impl Example for ContentErrorDetailList {
58 fn example() -> Self {
59 Self(vec![Example::example()])
60 }
61}
62
63#[derive(Object, Debug, Clone)]
66#[oai(example)]
67pub(crate) struct ContentErrorDetail {
70 #[oai(skip_serializing_if_is_none)]
72 loc: Option<common::types::generic::error_list::ErrorList>,
73 #[oai(skip_serializing_if_is_none)]
75 msg: Option<common::types::generic::error_msg::ErrorMessage>,
76 #[oai(rename = "type", skip_serializing_if_is_none)]
78 err_type: Option<common::types::generic::error_msg::ErrorMessage>,
79}
80
81impl Example for ContentErrorDetail {
82 fn example() -> Self {
84 Self {
85 loc: Some(vec!["body".into()].into()),
86 msg: Some("Value is not a valid dict.".into()),
87 err_type: Some("type_error.dict".into()),
88 }
89 }
90}
91
92impl ContentErrorDetail {
93 pub(crate) fn new(error: &poem::Error) -> Self {
95 Self {
97 loc: None,
98 msg: Some(error.to_string().into()),
99 err_type: None,
100 }
101 }
102}