Skip to content

Commit 26abdce

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

20 files changed

+666
-76
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-impl/tests/output/buildomat-builder-tagged.out

+21
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
use progenitor_client::{encode_path, RequestBuilderExt};
33
pub use progenitor_client::{generate_websocket_key, ByteStream, Error, ResponseValue};
44
pub mod types {
5+
#[allow(unused_imports)]
6+
use super::*;
57
use serde::{Deserialize, Serialize};
68
#[allow(unused_imports)]
79
use std::convert::TryFrom;
810
#[derive(Clone, Debug, Deserialize, Serialize)]
11+
#[serde(crate = "progenitor_client::deps::serde")]
912
pub struct Task {
1013
pub id: String,
1114
pub name: String,
@@ -21,6 +24,7 @@ pub mod types {
2124
}
2225

2326
#[derive(Clone, Debug, Deserialize, Serialize)]
27+
#[serde(crate = "progenitor_client::deps::serde")]
2428
pub struct TaskEvent {
2529
pub payload: String,
2630
pub seq: u32,
@@ -35,6 +39,7 @@ pub mod types {
3539
}
3640

3741
#[derive(Clone, Debug, Deserialize, Serialize)]
42+
#[serde(crate = "progenitor_client::deps::serde")]
3843
pub struct TaskOutput {
3944
pub id: String,
4045
pub path: String,
@@ -48,6 +53,7 @@ pub mod types {
4853
}
4954

5055
#[derive(Clone, Debug, Deserialize, Serialize)]
56+
#[serde(crate = "progenitor_client::deps::serde")]
5157
pub struct TaskSubmit {
5258
pub name: String,
5359
#[serde(default, skip_serializing_if = "Vec::is_empty")]
@@ -62,6 +68,7 @@ pub mod types {
6268
}
6369

6470
#[derive(Clone, Debug, Deserialize, Serialize)]
71+
#[serde(crate = "progenitor_client::deps::serde")]
6572
pub struct TaskSubmitResult {
6673
pub id: String,
6774
}
@@ -73,6 +80,7 @@ pub mod types {
7380
}
7481

7582
#[derive(Clone, Debug, Deserialize, Serialize)]
83+
#[serde(crate = "progenitor_client::deps::serde")]
7684
pub struct UploadedChunk {
7785
pub id: String,
7886
}
@@ -84,6 +92,7 @@ pub mod types {
8492
}
8593

8694
#[derive(Clone, Debug, Deserialize, Serialize)]
95+
#[serde(crate = "progenitor_client::deps::serde")]
8796
pub struct UserCreate {
8897
pub name: String,
8998
}
@@ -95,6 +104,7 @@ pub mod types {
95104
}
96105

97106
#[derive(Clone, Debug, Deserialize, Serialize)]
107+
#[serde(crate = "progenitor_client::deps::serde")]
98108
pub struct UserCreateResult {
99109
pub id: String,
100110
pub name: String,
@@ -108,6 +118,7 @@ pub mod types {
108118
}
109119

110120
#[derive(Clone, Debug, Deserialize, Serialize)]
121+
#[serde(crate = "progenitor_client::deps::serde")]
111122
pub struct WhoamiResult {
112123
pub id: String,
113124
pub name: String,
@@ -120,6 +131,7 @@ pub mod types {
120131
}
121132

122133
#[derive(Clone, Debug, Deserialize, Serialize)]
134+
#[serde(crate = "progenitor_client::deps::serde")]
123135
pub struct Worker {
124136
pub deleted: bool,
125137
pub id: String,
@@ -138,6 +150,7 @@ pub mod types {
138150
}
139151

140152
#[derive(Clone, Debug, Deserialize, Serialize)]
153+
#[serde(crate = "progenitor_client::deps::serde")]
141154
pub struct WorkerAddOutput {
142155
pub chunks: Vec<String>,
143156
pub path: String,
@@ -151,6 +164,7 @@ pub mod types {
151164
}
152165

153166
#[derive(Clone, Debug, Deserialize, Serialize)]
167+
#[serde(crate = "progenitor_client::deps::serde")]
154168
pub struct WorkerAppendTask {
155169
pub payload: String,
156170
pub stream: String,
@@ -164,6 +178,7 @@ pub mod types {
164178
}
165179

166180
#[derive(Clone, Debug, Deserialize, Serialize)]
181+
#[serde(crate = "progenitor_client::deps::serde")]
167182
pub struct WorkerBootstrap {
168183
pub bootstrap: String,
169184
pub token: String,
@@ -176,6 +191,7 @@ pub mod types {
176191
}
177192

178193
#[derive(Clone, Debug, Deserialize, Serialize)]
194+
#[serde(crate = "progenitor_client::deps::serde")]
179195
pub struct WorkerBootstrapResult {
180196
pub id: String,
181197
}
@@ -187,6 +203,7 @@ pub mod types {
187203
}
188204

189205
#[derive(Clone, Debug, Deserialize, Serialize)]
206+
#[serde(crate = "progenitor_client::deps::serde")]
190207
pub struct WorkerCompleteTask {
191208
pub failed: bool,
192209
}
@@ -198,6 +215,7 @@ pub mod types {
198215
}
199216

200217
#[derive(Clone, Debug, Deserialize, Serialize)]
218+
#[serde(crate = "progenitor_client::deps::serde")]
201219
pub struct WorkerPingResult {
202220
pub poweroff: bool,
203221
#[serde(default, skip_serializing_if = "Option::is_none")]
@@ -211,6 +229,7 @@ pub mod types {
211229
}
212230

213231
#[derive(Clone, Debug, Deserialize, Serialize)]
232+
#[serde(crate = "progenitor_client::deps::serde")]
214233
pub struct WorkerPingTask {
215234
pub id: String,
216235
pub output_rules: Vec<String>,
@@ -224,6 +243,7 @@ pub mod types {
224243
}
225244

226245
#[derive(Clone, Debug, Deserialize, Serialize)]
246+
#[serde(crate = "progenitor_client::deps::serde")]
227247
pub struct WorkerTask {
228248
pub id: String,
229249
pub name: String,
@@ -237,6 +257,7 @@ pub mod types {
237257
}
238258

239259
#[derive(Clone, Debug, Deserialize, Serialize)]
260+
#[serde(crate = "progenitor_client::deps::serde")]
240261
pub struct WorkersResult {
241262
pub workers: Vec<Worker>,
242263
}

0 commit comments

Comments
 (0)