|
1 | 1 | use indexmap::IndexMap; |
2 | 2 | use serde::{Deserialize, Serialize}; |
3 | 3 |
|
4 | | -use super::{ |
5 | | - Channel, Components, ExternalDocumentation, Info, Operation, Payload, ReferenceOr, Schema, |
6 | | - Server, Tag, |
7 | | -}; |
| 4 | +use crate::template_model::{simplify_operation, SimplifiedOperation}; |
| 5 | + |
| 6 | +use super::{Channel, Components, ExternalDocumentation, Info, ReferenceOr, Server, Tag}; |
8 | 7 |
|
9 | 8 | /// This is the root document object for the API specification. |
10 | 9 | /// It combines resource listing and API declaration together into one document. |
@@ -170,62 +169,26 @@ pub struct AsyncAPI { |
170 | 169 | pub extensions: IndexMap<String, serde_json::Value>, |
171 | 170 | } |
172 | 171 | impl AsyncAPI { |
173 | | - pub fn get_all_channels_operations(&self) -> Vec<(&String, &Operation)> { |
174 | | - self.channels |
175 | | - .iter() |
176 | | - .flat_map(|(channel_name, channel)| { |
177 | | - vec![ |
178 | | - channel |
179 | | - .publish |
180 | | - .as_ref() |
181 | | - .map(|operation| (channel_name, operation)), |
182 | | - channel |
183 | | - .subscribe |
184 | | - .as_ref() |
185 | | - .map(|operation| (channel_name, operation)), |
186 | | - ] |
187 | | - }) |
188 | | - .flatten() |
189 | | - .collect() |
190 | | - } |
191 | | - pub fn get_subscribe_channels_operations(&self) -> Vec<(&String, &Operation)> { |
| 172 | + pub fn get_subscribe_channels_operations(&self) -> Vec<(&String, SimplifiedOperation)> { |
192 | 173 | self.channels |
193 | 174 | .iter() |
194 | 175 | .filter_map(|(channel_name, channel)| { |
195 | 176 | channel |
196 | 177 | .subscribe |
197 | 178 | .as_ref() |
198 | | - .map(|operation| (channel_name, operation)) |
| 179 | + .map(|operation| (channel_name, simplify_operation(operation, channel_name))) |
199 | 180 | }) |
200 | 181 | .collect() |
201 | 182 | } |
202 | | - pub fn get_publish_channels_operations(&self) -> Vec<(&String, &Operation)> { |
| 183 | + pub fn get_publish_channels_operations(&self) -> Vec<(&String, SimplifiedOperation)> { |
203 | 184 | self.channels |
204 | 185 | .iter() |
205 | 186 | .filter_map(|(channel_name, channel)| { |
206 | 187 | channel |
207 | 188 | .publish |
208 | 189 | .as_ref() |
209 | | - .map(|operation| (channel_name, operation)) |
| 190 | + .map(|operation| (channel_name, simplify_operation(operation, channel_name))) |
210 | 191 | }) |
211 | 192 | .collect() |
212 | 193 | } |
213 | | - pub fn get_components(&self) -> Option<&Components> { |
214 | | - self.components.as_ref() |
215 | | - } |
216 | | - pub fn get_schema_from_reference(&self, message_name: &str) -> &Schema { |
217 | | - self.get_components() |
218 | | - .and_then(|components| { |
219 | | - let message_or_ref = components.messages.get(message_name).unwrap(); |
220 | | - let payload = match message_or_ref { |
221 | | - ReferenceOr::Item(message) => message.payload.as_ref().unwrap(), |
222 | | - ReferenceOr::Reference { .. } => return None, // or handle the reference case |
223 | | - }; |
224 | | - Some(match payload { |
225 | | - Payload::Schema(schema) => schema, |
226 | | - Payload::Any(_) => return None, |
227 | | - }) |
228 | | - }) |
229 | | - .unwrap() |
230 | | - } |
231 | 194 | } |
0 commit comments