197 lines
5.3 KiB
Plaintext
197 lines
5.3 KiB
Plaintext
#[allow(unused_imports)]
|
|
use progenitor_client::{encode_path, RequestBuilderExt};
|
|
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
|
#[allow(unused_imports)]
|
|
use reqwest::header::{HeaderMap, HeaderValue};
|
|
pub mod types {
|
|
use serde::{Deserialize, Serialize};
|
|
#[allow(unused_imports)]
|
|
use std::convert::TryFrom;
|
|
///BodyWithDefaults
|
|
///
|
|
/// <details><summary>JSON schema</summary>
|
|
///
|
|
/// ```json
|
|
///{
|
|
/// "type": "object",
|
|
/// "required": [
|
|
/// "s"
|
|
/// ],
|
|
/// "properties": {
|
|
/// "forty-two": {
|
|
/// "default": 42,
|
|
/// "type": "integer",
|
|
/// "format": "uint32",
|
|
/// "minimum": 0.0
|
|
/// },
|
|
/// "s": {
|
|
/// "type": "string"
|
|
/// },
|
|
/// "something": {
|
|
/// "default": true,
|
|
/// "type": [
|
|
/// "boolean",
|
|
/// "null"
|
|
/// ]
|
|
/// },
|
|
/// "yes": {
|
|
/// "default": false,
|
|
/// "type": "boolean"
|
|
/// }
|
|
/// }
|
|
///}
|
|
/// ```
|
|
/// </details>
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct BodyWithDefaults {
|
|
#[serde(rename = "forty-two", default = "defaults::default_u64::<u32, 42>")]
|
|
pub forty_two: u32,
|
|
pub s: String,
|
|
#[serde(default = "defaults::body_with_defaults_something")]
|
|
pub something: Option<bool>,
|
|
#[serde(default)]
|
|
pub yes: bool,
|
|
}
|
|
|
|
impl From<&BodyWithDefaults> for BodyWithDefaults {
|
|
fn from(value: &BodyWithDefaults) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
///Error information from a response.
|
|
///
|
|
/// <details><summary>JSON schema</summary>
|
|
///
|
|
/// ```json
|
|
///{
|
|
/// "description": "Error information from a response.",
|
|
/// "type": "object",
|
|
/// "required": [
|
|
/// "message",
|
|
/// "request_id"
|
|
/// ],
|
|
/// "properties": {
|
|
/// "error_code": {
|
|
/// "type": "string"
|
|
/// },
|
|
/// "message": {
|
|
/// "type": "string"
|
|
/// },
|
|
/// "request_id": {
|
|
/// "type": "string"
|
|
/// }
|
|
/// }
|
|
///}
|
|
/// ```
|
|
/// </details>
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct Error {
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
pub error_code: Option<String>,
|
|
pub message: String,
|
|
pub request_id: String,
|
|
}
|
|
|
|
impl From<&Error> for Error {
|
|
fn from(value: &Error) -> Self {
|
|
value.clone()
|
|
}
|
|
}
|
|
|
|
pub mod defaults {
|
|
pub(super) fn default_u64<T, const V: u64>() -> T
|
|
where
|
|
T: std::convert::TryFrom<u64>,
|
|
<T as std::convert::TryFrom<u64>>::Error: std::fmt::Debug,
|
|
{
|
|
T::try_from(V).unwrap()
|
|
}
|
|
|
|
pub(super) fn body_with_defaults_something() -> Option<bool> {
|
|
Some(true)
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug)]
|
|
///Client for pagination-demo
|
|
///
|
|
///Version: 9000
|
|
pub struct Client {
|
|
pub(crate) baseurl: String,
|
|
pub(crate) client: reqwest::Client,
|
|
}
|
|
|
|
impl Client {
|
|
/// Create a new client.
|
|
///
|
|
/// `baseurl` is the base URL provided to the internal
|
|
/// `reqwest::Client`, and should include a scheme and hostname,
|
|
/// as well as port and a path stem if applicable.
|
|
pub fn new(baseurl: &str) -> Self {
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
let client = {
|
|
let dur = std::time::Duration::from_secs(15);
|
|
reqwest::ClientBuilder::new()
|
|
.connect_timeout(dur)
|
|
.timeout(dur)
|
|
};
|
|
#[cfg(target_arch = "wasm32")]
|
|
let client = reqwest::ClientBuilder::new();
|
|
Self::new_with_client(baseurl, client.build().unwrap())
|
|
}
|
|
|
|
/// Construct a new client with an existing `reqwest::Client`,
|
|
/// allowing more control over its configuration.
|
|
///
|
|
/// `baseurl` is the base URL provided to the internal
|
|
/// `reqwest::Client`, and should include a scheme and hostname,
|
|
/// as well as port and a path stem if applicable.
|
|
pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self {
|
|
Self {
|
|
baseurl: baseurl.to_string(),
|
|
client,
|
|
}
|
|
}
|
|
|
|
/// Get the base URL to which requests are made.
|
|
pub fn baseurl(&self) -> &String {
|
|
&self.baseurl
|
|
}
|
|
|
|
/// 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 {
|
|
///Sends a `POST` request to `/`
|
|
pub async fn default_params<'a>(
|
|
&'a self,
|
|
body: &'a types::BodyWithDefaults,
|
|
) -> Result<ResponseValue<ByteStream>, Error<ByteStream>> {
|
|
let url = format!("{}/", self.baseurl,);
|
|
let request = self.client.post(url).json(&body).build()?;
|
|
let result = self.client.execute(request).await;
|
|
let response = result?;
|
|
match response.status().as_u16() {
|
|
200..=299 => Ok(ResponseValue::stream(response)),
|
|
_ => Err(Error::ErrorResponse(ResponseValue::stream(response))),
|
|
}
|
|
}
|
|
}
|
|
|
|
pub mod prelude {
|
|
pub use super::Client;
|
|
}
|