2022-09-11 00:15:14 +00:00
|
|
|
# Positional Generation
|
2022-02-08 16:59:38 +00:00
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
When the "positional" style is specified, Progenitor generates methods
|
|
|
|
according to operations within an OpenAPI document. Each takes the following
|
|
|
|
general form:
|
2022-02-08 16:59:38 +00:00
|
|
|
|
|
|
|
```rust
|
|
|
|
impl Client {
|
|
|
|
pub async fn operation_name<'a>(
|
|
|
|
&'a self,
|
2022-09-11 00:15:14 +00:00
|
|
|
// Path parameters (if any) come first and are always mandatory
|
|
|
|
path_parameter_1: String,
|
|
|
|
path_parameter_2: u32,
|
|
|
|
// Query parameters (if any) come next and may be optional
|
|
|
|
query_parameter_1: String,
|
|
|
|
query_parameter_2: Option<u32>,
|
|
|
|
// A body parameter (if specified) comes last
|
|
|
|
body: &types::ThisOperationBody,
|
2022-02-08 16:59:38 +00:00
|
|
|
) -> Result<
|
|
|
|
ResponseValue<types::SuccessResponseType>,
|
2022-09-11 00:15:14 +00:00
|
|
|
Error<types::ErrorResponseType>,
|
2022-02-08 16:59:38 +00:00
|
|
|
> {
|
2022-09-11 00:15:14 +00:00
|
|
|
// ...
|
|
|
|
}
|
2022-02-08 16:59:38 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
For more info on the `ResponseValue<T>` and `Error<E>` types, see
|
2022-02-24 05:07:30 +00:00
|
|
|
[progenitor_client](./progenitor-client.md).
|
2022-02-08 16:59:38 +00:00
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
Note that methods are `async` so must be `await`ed to get the response value.
|
2022-02-08 16:59:38 +00:00
|
|
|
|
|
|
|
### Dropshot Paginated Operations
|
|
|
|
|
2022-09-11 00:15:14 +00:00
|
|
|
Dropshot defines a mechanism for pagination. If that mechanism is used for a
|
|
|
|
particular operation, Progenitor will generate an additional method that
|
|
|
|
produces a `Stream`. Consumers can iterate over all items in the paginated
|
2022-02-08 16:59:38 +00:00
|
|
|
collection without manually fetching individual pages.
|
|
|
|
|
|
|
|
Here's the signature for a typical generated method:
|
|
|
|
|
|
|
|
```rust
|
|
|
|
pub fn operation_name_stream<'a>(
|
|
|
|
&'a self,
|
|
|
|
// Specific parameters...
|
|
|
|
limit: Option<std::num::NonZeroU32>,
|
|
|
|
) -> impl futures::Stream<
|
|
|
|
Item = Result<types::SuccessResponseType, Error<types::ErrorResponseType>>
|
|
|
|
> + Unpin + '_ {
|
2022-09-11 00:15:14 +00:00
|
|
|
// ...
|
|
|
|
}
|
2022-02-08 16:59:38 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
A typical consumer of this method might look like this:
|
|
|
|
|
|
|
|
```rust
|
|
|
|
let mut stream = client.operation_name_stream(None);
|
|
|
|
loop {
|
|
|
|
match stream.try_next().await {
|
|
|
|
Ok(Some(item)) => println!("item {:?}", item),
|
|
|
|
Ok(None) => {
|
|
|
|
println!("done.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Err(_) => {
|
|
|
|
println!("error!");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|