Skip to content

Commit a057ebf

Browse files
authored
add PathItem::iter() to iterate over non-None operations (glademiller#31)
1 parent c39c9ba commit a057ebf

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/paths.rs

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ pub struct PathItem {
4444
pub extensions: IndexMap<String, serde_json::Value>,
4545
}
4646

47+
impl PathItem {
48+
pub fn iter(&self) -> impl Iterator<Item = &Operation> + '_ {
49+
vec![
50+
&self.get,
51+
&self.put,
52+
&self.post,
53+
&self.delete,
54+
&self.options,
55+
&self.head,
56+
&self.patch,
57+
&self.trace,
58+
]
59+
.into_iter()
60+
.flat_map(Option::iter)
61+
}
62+
}
63+
4764
/// Holds the relative paths to the individual endpoints and
4865
/// their operations. The path is appended to the URL from the
4966
/// Server Object in order to construct the full URL. The Paths

tests/test.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,9 @@ fn test_operation_extension_docs() {
269269
.iter()
270270
.filter_map(|(_, i)| match i {
271271
ReferenceOr::Reference { .. } => None,
272-
ReferenceOr::Item(item) => item.get.as_ref(),
272+
ReferenceOr::Item(item) => Some(item),
273273
})
274+
.flat_map(|item| item.iter())
274275
.flat_map(|o| o.extensions.iter().filter(|e| !e.0.starts_with("x-")))
275276
.collect::<Vec<_>>();
276277

0 commit comments

Comments
 (0)