From 4eb8cd6c21907fc416c8ba1b5c45be3ac5a4c656 Mon Sep 17 00:00:00 2001 From: Adam Leventhal Date: Wed, 29 Mar 2023 23:02:17 -0700 Subject: [PATCH] make the OpenAPI info.version field accessible through the generated client (#400) --- progenitor-impl/src/lib.rs | 35 +++++++++++++++---- .../tests/output/buildomat-builder-tagged.out | 14 ++++++-- .../tests/output/buildomat-builder.out | 14 ++++++-- .../tests/output/buildomat-positional.out | 14 ++++++-- .../tests/output/keeper-builder-tagged.out | 14 ++++++-- .../tests/output/keeper-builder.out | 14 ++++++-- .../tests/output/keeper-positional.out | 14 ++++++-- .../tests/output/nexus-builder-tagged.out | 14 ++++++-- .../tests/output/nexus-builder.out | 14 ++++++-- .../tests/output/nexus-positional.out | 14 ++++++-- .../output/param-overrides-builder-tagged.out | 14 ++++++-- .../tests/output/param-overrides-builder.out | 14 ++++++-- .../output/param-overrides-positional.out | 14 ++++++-- .../output/propolis-server-builder-tagged.out | 14 ++++++-- .../tests/output/propolis-server-builder.out | 14 ++++++-- .../output/propolis-server-positional.out | 14 ++++++-- .../output/test_default_params_builder.out | 14 ++++++-- .../output/test_default_params_positional.out | 14 ++++++-- .../tests/output/test_freeform_response.out | 14 ++++++-- .../tests/output/test_renamed_parameters.out | 14 ++++++-- 20 files changed, 256 insertions(+), 45 deletions(-) diff --git a/progenitor-impl/src/lib.rs b/progenitor-impl/src/lib.rs index 90cd354..331c3b1 100644 --- a/progenitor-impl/src/lib.rs +++ b/progenitor-impl/src/lib.rs @@ -289,12 +289,25 @@ impl Generator { } }); - let client_docstring = if let Some(description) = &spec.info.description - { - format!("Client for {}\n\n{}", spec.info.title, description) - } else { - format!("Client for {}", spec.info.title) + let client_docstring = { + let mut s = format!("Client for {}", spec.info.title); + + if let Some(ss) = &spec.info.description { + s.push_str("\n\n"); + s.push_str(ss); + } + if let Some(ss) = &spec.info.terms_of_service { + s.push_str("\n\n"); + s.push_str(ss); + } + + s.push_str(&format!("\n\nVersion: {}", &spec.info.version)); + + s }; + + let version_str = &spec.info.version; + let file = quote! { // Re-export ResponseValue and Error since those are used by the // public interface of Client. @@ -359,16 +372,24 @@ impl Generator { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + #version_str + } + #maybe_inner } diff --git a/progenitor-impl/tests/output/buildomat-builder-tagged.out b/progenitor-impl/tests/output/buildomat-builder-tagged.out index 9bf441d..abb253f 100644 --- a/progenitor-impl/tests/output/buildomat-builder-tagged.out +++ b/progenitor-impl/tests/output/buildomat-builder-tagged.out @@ -1577,6 +1577,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for Buildomat +/// +///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -1611,15 +1613,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "1.0" + } } impl Client { diff --git a/progenitor-impl/tests/output/buildomat-builder.out b/progenitor-impl/tests/output/buildomat-builder.out index d54248b..8204f13 100644 --- a/progenitor-impl/tests/output/buildomat-builder.out +++ b/progenitor-impl/tests/output/buildomat-builder.out @@ -1577,6 +1577,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for Buildomat +/// +///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -1611,15 +1613,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "1.0" + } } impl Client { diff --git a/progenitor-impl/tests/output/buildomat-positional.out b/progenitor-impl/tests/output/buildomat-positional.out index d386e9f..c67f751 100644 --- a/progenitor-impl/tests/output/buildomat-positional.out +++ b/progenitor-impl/tests/output/buildomat-positional.out @@ -252,6 +252,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for Buildomat +/// +///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -286,15 +288,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "1.0" + } } impl Client { diff --git a/progenitor-impl/tests/output/keeper-builder-tagged.out b/progenitor-impl/tests/output/keeper-builder-tagged.out index 8984a93..10c5f5f 100644 --- a/progenitor-impl/tests/output/keeper-builder-tagged.out +++ b/progenitor-impl/tests/output/keeper-builder-tagged.out @@ -902,6 +902,8 @@ pub mod types { ///Client for Keeper API /// ///report execution of cron jobs through a mechanism other than mail +/// +///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -936,15 +938,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "1.0" + } } impl Client { diff --git a/progenitor-impl/tests/output/keeper-builder.out b/progenitor-impl/tests/output/keeper-builder.out index 3d3e0d3..2d95b36 100644 --- a/progenitor-impl/tests/output/keeper-builder.out +++ b/progenitor-impl/tests/output/keeper-builder.out @@ -902,6 +902,8 @@ pub mod types { ///Client for Keeper API /// ///report execution of cron jobs through a mechanism other than mail +/// +///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -936,15 +938,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "1.0" + } } impl Client { diff --git a/progenitor-impl/tests/output/keeper-positional.out b/progenitor-impl/tests/output/keeper-positional.out index 447b237..7524b0e 100644 --- a/progenitor-impl/tests/output/keeper-positional.out +++ b/progenitor-impl/tests/output/keeper-positional.out @@ -141,6 +141,8 @@ pub mod types { ///Client for Keeper API /// ///report execution of cron jobs through a mechanism other than mail +/// +///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -175,15 +177,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "1.0" + } } impl Client { diff --git a/progenitor-impl/tests/output/nexus-builder-tagged.out b/progenitor-impl/tests/output/nexus-builder-tagged.out index 7ff5fa0..0201241 100644 --- a/progenitor-impl/tests/output/nexus-builder-tagged.out +++ b/progenitor-impl/tests/output/nexus-builder-tagged.out @@ -17034,6 +17034,8 @@ pub mod types { ///Client for Oxide Region API /// ///API for interacting with the Oxide control plane +/// +///Version: 0.0.1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -17068,15 +17070,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "0.0.1" + } } pub trait ClientDisksExt { diff --git a/progenitor-impl/tests/output/nexus-builder.out b/progenitor-impl/tests/output/nexus-builder.out index 303a8d5..8feaaca 100644 --- a/progenitor-impl/tests/output/nexus-builder.out +++ b/progenitor-impl/tests/output/nexus-builder.out @@ -17090,6 +17090,8 @@ pub mod types { ///Client for Oxide Region API /// ///API for interacting with the Oxide control plane +/// +///Version: 0.0.1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -17124,15 +17126,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "0.0.1" + } } impl Client { diff --git a/progenitor-impl/tests/output/nexus-positional.out b/progenitor-impl/tests/output/nexus-positional.out index a380cb2..352fbda 100644 --- a/progenitor-impl/tests/output/nexus-positional.out +++ b/progenitor-impl/tests/output/nexus-positional.out @@ -5862,6 +5862,8 @@ pub mod types { ///Client for Oxide Region API /// ///API for interacting with the Oxide control plane +/// +///Version: 0.0.1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -5896,15 +5898,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "0.0.1" + } } impl Client { diff --git a/progenitor-impl/tests/output/param-overrides-builder-tagged.out b/progenitor-impl/tests/output/param-overrides-builder-tagged.out index 99feb55..99fd722 100644 --- a/progenitor-impl/tests/output/param-overrides-builder-tagged.out +++ b/progenitor-impl/tests/output/param-overrides-builder-tagged.out @@ -13,6 +13,8 @@ pub mod types { ///Client for Parameter override test /// ///Minimal API for testing parameter overrides +/// +///Version: v1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -47,15 +49,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "v1" + } } impl Client { diff --git a/progenitor-impl/tests/output/param-overrides-builder.out b/progenitor-impl/tests/output/param-overrides-builder.out index f7ca2df..cfd115a 100644 --- a/progenitor-impl/tests/output/param-overrides-builder.out +++ b/progenitor-impl/tests/output/param-overrides-builder.out @@ -13,6 +13,8 @@ pub mod types { ///Client for Parameter override test /// ///Minimal API for testing parameter overrides +/// +///Version: v1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -47,15 +49,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "v1" + } } impl Client { diff --git a/progenitor-impl/tests/output/param-overrides-positional.out b/progenitor-impl/tests/output/param-overrides-positional.out index 3153bdf..f267620 100644 --- a/progenitor-impl/tests/output/param-overrides-positional.out +++ b/progenitor-impl/tests/output/param-overrides-positional.out @@ -13,6 +13,8 @@ pub mod types { ///Client for Parameter override test /// ///Minimal API for testing parameter overrides +/// +///Version: v1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -47,15 +49,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "v1" + } } impl Client { diff --git a/progenitor-impl/tests/output/propolis-server-builder-tagged.out b/progenitor-impl/tests/output/propolis-server-builder-tagged.out index 9fcbd46..baccd47 100644 --- a/progenitor-impl/tests/output/propolis-server-builder-tagged.out +++ b/progenitor-impl/tests/output/propolis-server-builder-tagged.out @@ -1955,6 +1955,8 @@ pub mod types { ///Client for Oxide Propolis Server API /// ///API for interacting with the Propolis hypervisor frontend. +/// +///Version: 0.0.1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -1989,15 +1991,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "0.0.1" + } } impl Client { diff --git a/progenitor-impl/tests/output/propolis-server-builder.out b/progenitor-impl/tests/output/propolis-server-builder.out index 2dd901e..6786c13 100644 --- a/progenitor-impl/tests/output/propolis-server-builder.out +++ b/progenitor-impl/tests/output/propolis-server-builder.out @@ -1961,6 +1961,8 @@ pub mod types { ///Client for Oxide Propolis Server API /// ///API for interacting with the Propolis hypervisor frontend. +/// +///Version: 0.0.1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -1995,15 +1997,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "0.0.1" + } } impl Client { diff --git a/progenitor-impl/tests/output/propolis-server-positional.out b/progenitor-impl/tests/output/propolis-server-positional.out index 38c0aff..5c341b1 100644 --- a/progenitor-impl/tests/output/propolis-server-positional.out +++ b/progenitor-impl/tests/output/propolis-server-positional.out @@ -608,6 +608,8 @@ pub mod types { ///Client for Oxide Propolis Server API /// ///API for interacting with the Propolis hypervisor frontend. +/// +///Version: 0.0.1 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -642,15 +644,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "0.0.1" + } } impl Client { diff --git a/progenitor-impl/tests/output/test_default_params_builder.out b/progenitor-impl/tests/output/test_default_params_builder.out index 429604c..9b81b93 100644 --- a/progenitor-impl/tests/output/test_default_params_builder.out +++ b/progenitor-impl/tests/output/test_default_params_builder.out @@ -226,6 +226,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for pagination-demo +/// +///Version: 9000 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -260,15 +262,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "9000" + } } impl Client { diff --git a/progenitor-impl/tests/output/test_default_params_positional.out b/progenitor-impl/tests/output/test_default_params_positional.out index 3544fe7..d2214f9 100644 --- a/progenitor-impl/tests/output/test_default_params_positional.out +++ b/progenitor-impl/tests/output/test_default_params_positional.out @@ -56,6 +56,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for pagination-demo +/// +///Version: 9000 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -90,15 +92,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "9000" + } } impl Client { diff --git a/progenitor-impl/tests/output/test_freeform_response.out b/progenitor-impl/tests/output/test_freeform_response.out index 6da1a6d..8b1bc28 100644 --- a/progenitor-impl/tests/output/test_freeform_response.out +++ b/progenitor-impl/tests/output/test_freeform_response.out @@ -25,6 +25,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for pagination-demo +/// +///Version: 9000 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -59,15 +61,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "9000" + } } impl Client { diff --git a/progenitor-impl/tests/output/test_renamed_parameters.out b/progenitor-impl/tests/output/test_renamed_parameters.out index 05fa9f5..de59f25 100644 --- a/progenitor-impl/tests/output/test_renamed_parameters.out +++ b/progenitor-impl/tests/output/test_renamed_parameters.out @@ -25,6 +25,8 @@ pub mod types { #[derive(Clone, Debug)] ///Client for pagination-demo +/// +///Version: 9000 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, @@ -59,15 +61,23 @@ impl Client { } } - /// Return the base URL to which requests are made. + /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } - /// Return the internal `reqwest::Client` used to make requests. + /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } + + /// Get the version of this API. + /// + /// This string is pulled directly from the source OpenAPI + /// document and may be in any format the API selects. + pub fn api_version(&self) -> &'static str { + "9000" + } } impl Client {