Skip to content

Commit 28f397c

Browse files
author
lif
committed
Use re-exports to make depending on propolis-client less cumbersome
1 parent 183ef35 commit 28f397c

File tree

7 files changed

+48
-38
lines changed

7 files changed

+48
-38
lines changed

Cargo.lock

+8-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+19-20
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,6 @@ You'll need to add add the following to `Cargo.toml`:
2828
```diff
2929
[dependencies]
3030
+progenitor = { git = "https://github.com/oxidecomputer/progenitor" }
31-
+reqwest = { version = "0.11", features = ["json", "stream"] }
32-
+serde = { version = "1.0", features = ["derive"] }
33-
```
34-
35-
In addition, if the OpenAPI document contains string types with the `format`
36-
field set to `date` or `date-time`, include
37-
38-
```diff
39-
[dependencies]
40-
+chrono = { version = "0.4", features = ["serde"] }
41-
```
42-
43-
Similarly if there is a `format` field set to `uuid`:
44-
45-
```diff
46-
[dependencies]
47-
+uuid = { version = "1.0.0", features = ["serde", "v4"] }
4831
```
4932

5033
The macro has some additional fancy options to control the generated code:
@@ -109,11 +92,23 @@ You'll need to add add the following to `Cargo.toml`:
10992
+serde_json = "1.0"
11093
```
11194

112-
(`chrono` and `uuid` as above)
113-
11495
Note that `progenitor` is used by `build.rs`, but the generated code required
11596
`progenitor-client`.
11697

98+
In addition, if the OpenAPI document contains string types with the `format`
99+
field set to `date` or `date-time`, include
100+
101+
```diff
102+
[dependencies]
103+
+chrono = { version = "0.4", features = ["serde"] }
104+
```
105+
106+
Similarly if there is a `format` field set to `uuid`:
107+
108+
```diff
109+
[dependencies]
110+
+uuid = { version = "1.0.0", features = ["serde", "v4"] }
111+
```
117112

118113
### Static Crate
119114

@@ -139,7 +134,7 @@ For example:
139134

140135
This will produce a package in the specified directory. The output has no
141136
persistent dependency on Progenitor including the `progenitor-client` crate.
142-
Here's a excerpt from the emitted `Cargo.toml`:
137+
Here's an excerpt from the emitted `Cargo.toml`:
143138

144139
```toml
145140
[dependencies]
@@ -154,3 +149,7 @@ uuid = { version = ">=0.8.0, <2.0.0", features = ["serde", "v4"] }
154149

155150
Note that there is a dependency on `percent-encoding` which macro- and
156151
build.rs-generated clients is included from `progenitor-client`.
152+
153+
Additionally, note that `chrono` is only required if the OpenAPI document
154+
contains string types with the `format` field set to `date` or `date-time`,
155+
and `uuid` is only required if there is a `format` field set to `uuid`.

example-macro/Cargo.toml

-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,5 @@ authors = ["Adam H. Leventhal <ahl@oxidecomputer.com>"]
55
edition = "2021"
66

77
[dependencies]
8-
chrono = { version = "0.4", features = ["serde"] }
98
progenitor = { path = "../progenitor" }
10-
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "6ceb23958c8b6d7f1d8ee093f0ad73184d133d40", features = ["json", "stream"] }
11-
#reqwest = { version = "0.11", features = ["json", "stream"] }
129
schemars = { version = "0.8.10", features = ["uuid1"] }
13-
serde = { version = "1.0", features = ["derive"] }
14-
uuid = { version = "1.0", features = ["serde", "v4"] }

progenitor-client/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ bytes = "1.2.1"
1111
futures-core = "0.3.24"
1212
percent-encoding = "2.1"
1313
reqwest = { git = "https://github.com/seanmonstar/reqwest", rev = "6ceb23958c8b6d7f1d8ee093f0ad73184d133d40", features = ["json", "stream"] }
14-
#reqwest = { version = "0.11", default-features = false, features = ["json", "stream"] }
15-
serde = "1.0"
14+
chrono = { version = "0.4", features = ["serde"] }
15+
uuid = { version = "1.0.0", features = ["serde", "v4"] }
16+
serde = { version = "1.0", features = ["derive"] }
1617
serde_json = "1.0"
1718
serde_urlencoded = "0.7.1"
1819
base64 = "0.13"

progenitor-client/src/lib.rs

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ mod progenitor_client;
44

55
pub use crate::progenitor_client::*;
66

7+
pub mod deps {
8+
pub use ::chrono;
9+
pub use ::reqwest;
10+
pub use ::serde;
11+
pub use ::uuid;
12+
}
13+
714
// For stand-alone crates, rather than adding a dependency on
815
// progenitor-client, we simply dump the code right in. This means we don't
916
// need to determine the provenance of progenitor (crates.io, github, etc.)

progenitor-impl/src/lib.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ impl Generator {
127127
let mut type_settings = TypeSpaceSettings::default();
128128
type_settings
129129
.with_type_mod("types")
130-
.with_struct_builder(settings.interface == InterfaceStyle::Builder);
130+
.with_struct_builder(settings.interface == InterfaceStyle::Builder)
131+
.with_serde_crate_location(
132+
"progenitor_client::deps::serde".to_string(),
133+
);
131134
settings.extra_derives.iter().for_each(|derive| {
132135
let _ = type_settings.with_derive(derive.clone());
133136
});
@@ -225,6 +228,8 @@ impl Generator {
225228
use progenitor_client::{encode_path, RequestBuilderExt};
226229

227230
pub mod types {
231+
#[allow(unused_imports)]
232+
use super::*;
228233
use serde::{Deserialize, Serialize};
229234

230235
// This may be used by some impl Deserialize, but not all.
@@ -389,6 +394,8 @@ impl Generator {
389394
}
390395

391396
/// Render text output.
397+
// TODO: configuration for whether to use re-exports from progenitor-client
398+
// (standalone crate vs. build.rs codegen)
392399
pub fn generate_text(&mut self, spec: &OpenAPI) -> Result<String> {
393400
self.generate_text_impl(
394401
spec,

progenitor-macro/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ fn do_generate_api(item: TokenStream) -> Result<TokenStream, syn::Error> {
182182
// The progenitor_client is tautologically visible from macro
183183
// consumers.
184184
use progenitor::progenitor_client;
185+
// Re-exported such that macro consumers don't have to maintain
186+
// a matching dependency on the same reqwest version we use.
187+
use progenitor::progenitor_client::deps::*;
185188

186189
#code
187190

0 commit comments

Comments
 (0)