@@ -23,8 +23,9 @@ pub mod cli;
23
23
24
24
use indexmap:: IndexMap ;
25
25
26
- use clients_schema:: { Availabilities , Flavor , IndexedModel , Stability , Visibility } ;
26
+ use clients_schema:: { Availabilities , Availability , Flavor , IndexedModel , Stability , Visibility } ;
27
27
use openapiv3:: { Components , OpenAPI } ;
28
+ use serde_json:: Value ;
28
29
use clients_schema:: transform:: ExpandConfig ;
29
30
use crate :: components:: TypesAndComponents ;
30
31
@@ -151,31 +152,35 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
151
152
152
153
pub fn availability_as_extensions ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > ) -> IndexMap < String , serde_json:: Value > {
153
154
let mut result = IndexMap :: new ( ) ;
155
+ convert_availabilities ( availabilities, flavor, & mut result) ;
156
+ result
157
+ }
158
+
159
+ pub fn convert_availabilities ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > , result : & mut IndexMap < String , Value > ) {
154
160
if let Some ( avails) = availabilities {
155
- if let Some ( flavor) = flavor {
156
- if let Some ( availability) = avails. get ( flavor) {
157
- if let Some ( stability) = & availability. stability {
158
- let mut since_str = "" . to_string ( ) ;
159
- if let Some ( since) = & availability. since {
160
- since_str = "; Added in " . to_string ( ) + since;
161
+ if let Some ( flav) = flavor {
162
+ if let Some ( availability) = avails. get ( flav) {
163
+ let Availability { since, stability, ..} = & availability;
164
+ let stab = stability. clone ( ) . unwrap_or ( Stability :: Stable ) ;
165
+ let mut since_str = "" . to_string ( ) ;
166
+ if let Some ( since) = since {
167
+ since_str = "; Added in " . to_string ( ) + since;
168
+ }
169
+ match stab {
170
+ Stability :: Beta => {
171
+ let beta_since = "Beta" . to_string ( ) + & since_str;
172
+ result. insert ( "x-state" . to_string ( ) , Value :: String ( beta_since) ) ;
173
+ }
174
+ Stability :: Experimental => {
175
+ let exp_since = "Technical preview" . to_string ( ) + & since_str;
176
+ result. insert ( "x-state" . to_string ( ) , Value :: String ( exp_since) ) ;
161
177
}
162
- match stability {
163
- Stability :: Beta => {
164
- let beta_since = "Beta" . to_string ( ) + & since_str;
165
- result. insert ( "x-state" . to_string ( ) , serde_json:: Value :: String ( beta_since) ) ;
166
- }
167
- Stability :: Experimental => {
168
- let exp_since = "Technical preview" . to_string ( ) + & since_str;
169
- result. insert ( "x-state" . to_string ( ) , serde_json:: Value :: String ( exp_since) ) ;
170
- }
171
- Stability :: Stable => {
172
- let stable_since = "Generally available" . to_string ( ) + & since_str;
173
- result. insert ( "x-state" . to_string ( ) , serde_json:: Value :: String ( stable_since) ) ;
174
- }
178
+ Stability :: Stable => {
179
+ let stable_since = "Generally available" . to_string ( ) + & since_str;
180
+ result. insert ( "x-state" . to_string ( ) , Value :: String ( stable_since) ) ;
175
181
}
176
182
}
177
183
}
178
184
}
179
185
}
180
- result
181
186
}
0 commit comments