Skip to content

Commit

Permalink
Make the API documentation compile
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanUkhov committed Oct 3, 2024
1 parent b6fac32 commit a72a918
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
10 changes: 5 additions & 5 deletions etc/api/type-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ cargo:
keywords: [protocol, web, api]
doc_base_url: https://docs.rs
dependencies:
- hyper = "^ 0.14"
- http = "^0.2"
- tokio = "^1.0"
- tower-service = "^0.3.1"
- url = "= 1.7"
- http = "1"
- hyper = "1"
- tokio = "1"
- tower-service = "0.3"
- url = "2"
10 changes: 5 additions & 5 deletions etc/api/type-cli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ cargo:
is_executable: YES
doc_base_url: http://byron.github.io/google-apis-rs
dependencies:
- clap = "^2.0"
- http = "^0.2"
- hyper = { version = "0.14", features = ["full"] }
- tokio = { version = "^ 1.0", features = ["full"] }
- tower-service = "^0.3.1"
- clap = "2"
- http = "1"
- hyper = { version = "1", features = ["full"] }
- tokio = { version = "1", features = ["full"] }
- tower-service = "0.3"
5 changes: 5 additions & 0 deletions google-apis-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub trait Connection:
{
}

impl<T> Connection for T where
T: hyper_util::client::legacy::connect::Connect + Clone + Send + Sync + 'static
{
}

pub enum Retry {
/// Signal you don't want to retry
Abort,
Expand Down
17 changes: 9 additions & 8 deletions src/generator/templates/Cargo.toml.mako
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,19 @@ path = "src/main.rs"
% endif
[dependencies]
anyhow = "^ 1.0"
hyper-rustls = "0.25.0"
anyhow = "1"
hyper-rustls = "0.27"
hyper-util = "0.1"
## Must match the one hyper uses, otherwise there are duplicate similarly named `Mime` structs
mime = "^ 0.3.0"
serde = { version = "^ 1.0", features = ["derive"] }
utoipa = { version = "^4.2", optional = true }
serde_json = "^ 1.0"
mime = "0.3"
itertools = "0.13"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
utoipa = { version = "4", optional = true }
% if cargo.get('is_executable', False):
google-clis-common = { path = "../../google-clis-common", version = "6.0" }
google-clis-common = { path = "../../google-clis-common", version = "6" }
% else:
google-apis-common = { path = "../../google-apis-common", version = "6.0.3" }
google-apis-common = { path = "../../google-apis-common", version = "6" }
% endif
% for dep in cargo.get('dependencies', list()):
${dep}
Expand Down
17 changes: 10 additions & 7 deletions src/generator/templates/api/lib.rs.mako
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,19 @@ ${lib.docs(c)}
</%block>

// Re-export the hyper and hyper_rustls crate, they are required to build the hub
pub use hyper;
pub use hyper_rustls;
pub extern crate hyper;
pub extern crate hyper_rustls;
pub extern crate hyper_util;

pub extern crate google_apis_common as client;
pub use client::chrono;
pub mod api;

// Re-export the hub type and some basic client structs
pub use api::${hub_type};
pub use client::chrono;
pub use client::{Result, Error, Delegate, FieldMask};

// Re-export the yup_oauth2 crate, that is required to call some methods of the hub and the client
#[cfg(feature = "yup-oauth2")]
pub use client::oauth2;
pub use client::oauth2;

pub mod api;
// Re-export the hub type and some basic client structs
pub use api::${hub_type};
26 changes: 19 additions & 7 deletions src/generator/templates/api/lib/lib.mako
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ To use this library, you would put the following lines into your `Cargo.toml` fi
```toml
[dependencies]
${util.crate_name()} = "*"
serde = "^1.0"
serde_json = "^1.0"
serde = "1"
serde_json = "1"
```
${'##'} A complete example
Expand Down Expand Up @@ -250,7 +250,7 @@ generated `openapi` spec would be invalid.
###############################################################################################
<%def name="test_hub(hub_type, comments=True)">\
use std::default::Default;
use ${util.library_name()}::{${hub_type}, oauth2, hyper, hyper_rustls, chrono, FieldMask};
use ${util.library_name()}::{${hub_type}, oauth2, hyper, hyper_rustls, hyper_util, chrono, FieldMask};
% if comments:
// Get an ApplicationSecret instance by some means. It contains the `client_id` and
Expand All @@ -265,10 +265,22 @@ let secret: oauth2::ApplicationSecret = Default::default();
// retrieve them from storage.
% endif
let auth = oauth2::InstalledFlowAuthenticator::builder(
secret,
oauth2::InstalledFlowReturnMethod::HTTPRedirect,
).build().await.unwrap();
let mut hub = ${hub_type}::new(hyper::Client::builder().build(hyper_rustls::HttpsConnectorBuilder::new().with_native_roots().unwrap().https_or_http().enable_http1().build()), auth);\
secret,
oauth2::InstalledFlowReturnMethod::HTTPRedirect,
).build().await.unwrap();
let client = hyper_util::client::legacy::Client::builder(
hyper_util::rt::TokioExecutor::new()
)
.build(
hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.unwrap()
.https_or_http()
.enable_http1()
.build()
);
let mut hub = ${hub_type}::new(client, auth);\
</%def>

## You will still have to set the filter for your comment type - either nothing, or rust_doc_comment !
Expand Down

0 comments on commit a72a918

Please sign in to comment.