webwire_cli/schema/
service.rs1use std::collections::HashMap;
2
3use crate::idl;
4
5use super::errors::ValidationError;
6use super::namespace::Namespace;
7use super::r#type::Type;
8use super::typemap::TypeMap;
9
10pub struct Service {
11 pub name: String,
12 pub methods: Vec<Method>,
13}
14
15pub struct Method {
16 pub name: String,
17 pub input: Option<Type>,
18 pub output: Option<Type>,
19}
20
21impl Service {
22 pub(crate) fn from_idl(
23 iservice: &idl::Service,
24 ns: &Namespace,
25 builtin_types: &HashMap<String, String>,
26 ) -> Self {
27 Self {
28 name: iservice.name.clone(),
29 methods: iservice
30 .methods
31 .iter()
32 .map(|imethod| Method {
33 name: imethod.name.clone(),
34 input: imethod
35 .input
36 .as_ref()
37 .map(|x| Type::from_idl(x, ns, &builtin_types)),
38 output: imethod
39 .output
40 .as_ref()
41 .map(|x| Type::from_idl(x, ns, &builtin_types)),
42 })
43 .collect(),
44 }
45 }
46 pub(crate) fn resolve(&mut self, type_map: &TypeMap) -> Result<(), ValidationError> {
47 for method in self.methods.iter_mut() {
48 if let Some(input) = &mut method.input {
49 input.resolve(type_map)?;
50 }
51 if let Some(output) = &mut method.output {
52 output.resolve(type_map)?;
53 }
54 }
55 Ok(())
56 }
57}