@@ -32,6 +32,8 @@ pub use self::{error::Error, spec::Spec};
32
32
pub type OpenApiV3Spec = spec:: Spec ;
33
33
34
34
/// Try deserializing an OpenAPI spec (YAML or JSON) from a file, giving the path.
35
+ ///
36
+ /// If the `yaml` feature flag is disabled only `JSON` specs are supported
35
37
pub fn from_path < P > ( path : P ) -> Result < OpenApiV3Spec , Error >
36
38
where
37
39
P : AsRef < Path > ,
@@ -40,19 +42,38 @@ where
40
42
}
41
43
42
44
/// Try deserializing an OpenAPI spec (YAML or JSON) from a [`Read`] type.
45
+ ///
46
+ /// If the `yaml` feature flag is disabled only `JSON` specs are supported
43
47
pub fn from_reader < R > ( read : R ) -> Result < OpenApiV3Spec , Error >
44
48
where
45
49
R : Read ,
46
50
{
47
- Ok ( serde_yaml:: from_reader :: < R , OpenApiV3Spec > ( read) ?)
51
+ #[ cfg( feature = "yaml_spec" ) ]
52
+ {
53
+ Ok ( serde_yaml:: from_reader :: < R , OpenApiV3Spec > ( read) ?)
54
+ }
55
+ #[ cfg( not( feature = "yaml_spec" ) ) ]
56
+ {
57
+ Ok ( serde_json:: from_reader :: < R , OpenApiV3Spec > ( read) ?)
58
+ }
48
59
}
49
60
50
61
/// Try deserializing an OpenAPI spec (YAML or JSON) from string.
62
+ ///
63
+ /// If the `yaml` feature flag is disabled only `JSON` specs are supported
51
64
pub fn from_str ( val : impl AsRef < str > ) -> Result < OpenApiV3Spec , Error > {
52
- Ok ( serde_yaml:: from_str :: < OpenApiV3Spec > ( val. as_ref ( ) ) ?)
65
+ #[ cfg( feature = "yaml_spec" ) ]
66
+ {
67
+ Ok ( serde_yaml:: from_str :: < OpenApiV3Spec > ( val. as_ref ( ) ) ?)
68
+ }
69
+ #[ cfg( not( feature = "yaml_spec" ) ) ]
70
+ {
71
+ Ok ( serde_json:: from_str :: < OpenApiV3Spec > ( val. as_ref ( ) ) ?)
72
+ }
53
73
}
54
74
55
75
/// Try serializing to a YAML string.
76
+ #[ cfg( feature = "yaml_spec" ) ]
56
77
pub fn to_yaml ( spec : & OpenApiV3Spec ) -> Result < String , Error > {
57
78
Ok ( serde_yaml:: to_string ( spec) ?)
58
79
}
0 commit comments