//! API endpoints for SpaceTraders. //! //! Generated by: //! //! {{#version}}Version of specification: `{{{.}}}`{{/version}} /// Content of a response. #[derive(Debug, Clone)] pub struct ResponseContent { /// The status of the response. /// /// The response enums for each endpoint function are already split up /// by status code so this shouldn't really be needed in practice. pub status: reqwest::StatusCode, /// The raw response body as text. /// /// This can be used to extract information from the response if the schema /// does not include the data. pub response_body: String, /// The deserialized content of the response. pub content: T, } /// Error from interacting with an API endpoint. #[derive(thiserror::Error, Debug)] pub enum Error { /// Error from `request`. #[error("error performing request: {0}")] Reqwest(#[from] reqwest::Error), /// Error from `serde_json`. #[error("error deserializing: {0}")] Serde(#[from] serde_json::Error), /// Error response from the endpoint. #[error("got error response: {} - {}", .0.status, .0.response_body)] ResponseError(ResponseContent), /// An unknown response was received. /// /// This response was not defined by the schema. #[error("got unknown response: {status} - {response_body}")] UnknownResponse { is_error: bool, status: reqwest::StatusCode, response_body: String, } } fn urlencode>(s: T) -> String { ::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect() } {{#nothing}} fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> { if let serde_json::Value::Object(object) = value { let mut params = vec![]; for (key, value) in object { match value { serde_json::Value::Object(_) => params.append(&mut parse_deep_object( &format!("{}[{}]", prefix, key), value, )), serde_json::Value::Array(array) => { for (i, value) in array.iter().enumerate() { params.append(&mut parse_deep_object( &format!("{}[{}][{}]", prefix, key, i), value, )); } }, serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())), _ => params.push((format!("{}[{}]", prefix, key), value.to_string())), } } return params; } unimplemented!("Only objects are supported with style=deepObject") } {{/nothing}} {{#apiInfo}} {{#apis}} pub mod {{{classFilename}}}; {{/apis}} {{/apiInfo}} mod configuration; pub use configuration::*;