@@ -23,8 +23,9 @@ pub mod cli;
2323
2424use indexmap:: IndexMap ;
2525
26- use clients_schema:: { Availabilities , Flavor , IndexedModel , Stability , Visibility } ;
26+ use clients_schema:: { Availabilities , Availability , Flavor , IndexedModel , Stability , Visibility } ;
2727use openapiv3:: { Components , OpenAPI } ;
28+ use serde_json:: Value ;
2829use clients_schema:: transform:: ExpandConfig ;
2930use crate :: components:: TypesAndComponents ;
3031
@@ -151,31 +152,35 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
151152
152153pub fn availability_as_extensions ( availabilities : & Option < Availabilities > , flavor : & Option < Flavor > ) -> IndexMap < String , serde_json:: Value > {
153154 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 > ) {
154160 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) ) ;
161177 }
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) ) ;
175181 }
176182 }
177183 }
178184 }
179185 }
180- result
181186}
0 commit comments