@@ -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
@@ -157,30 +158,37 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
157
158
}
158
159
}
159
160
160
- pub fn availability_as_extensions ( availabilities : & Option < Availabilities > ) -> IndexMap < String , serde_json:: Value > {
161
+ pub fn availability_as_extensions ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > ) -> IndexMap < String , serde_json:: Value > {
161
162
let mut result = IndexMap :: new ( ) ;
163
+ convert_availabilities ( availabilities, flavor, & mut result) ;
164
+ result
165
+ }
162
166
167
+ pub fn convert_availabilities ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > , result : & mut IndexMap < String , Value > ) {
163
168
if let Some ( avails) = availabilities {
164
- // We may have several availabilities, but since generally exists only on stateful (stack)
165
- for ( _, availability) in avails {
166
- if let Some ( stability) = & availability. stability {
167
- match stability {
169
+ if let Some ( flav) = flavor {
170
+ if let Some ( availability) = avails. get ( flav) {
171
+ let Availability { since, stability, ..} = & availability;
172
+ let stab = stability. clone ( ) . unwrap_or ( Stability :: Stable ) ;
173
+ let mut since_str = "" . to_string ( ) ;
174
+ if let Some ( since) = since {
175
+ since_str = format ! ( "; Added in {since}" ) ;
176
+ }
177
+ match stab {
168
178
Stability :: Beta => {
169
- result. insert ( "x-beta" . to_string ( ) , serde_json:: Value :: Bool ( true ) ) ;
179
+ let beta_since = format ! ( "Beta{since_str}" ) ;
180
+ result. insert ( "x-state" . to_string ( ) , Value :: String ( beta_since) ) ;
170
181
}
171
182
Stability :: Experimental => {
172
- result. insert ( "x-state" . to_string ( ) , serde_json:: Value :: String ( "Technical preview" . to_string ( ) ) ) ;
183
+ let exp_since = format ! ( "Technical preview{since_str}" ) ;
184
+ result. insert ( "x-state" . to_string ( ) , Value :: String ( exp_since) ) ;
173
185
}
174
- Stability :: Stable => {
175
- if let Some ( since) = & availability. since {
176
- let stable_since = "Added in " . to_string ( ) + since;
177
- result. insert ( "x-state" . to_string ( ) , serde_json:: Value :: String ( stable_since) ) ;
178
- }
186
+ Stability :: Stable => {
187
+ let stable_since = format ! ( "Generally available{since_str}" ) ;
188
+ result. insert ( "x-state" . to_string ( ) , Value :: String ( stable_since) ) ;
179
189
}
180
190
}
181
191
}
182
192
}
183
193
}
184
-
185
- result
186
194
}
0 commit comments