#![allow(
clippy::all,
clippy::pedantic,
clippy::nursery,
dead_code,
unused_imports,
unused_variables,
reason = "mechanically generated contract text: the OAS is emitted in full (every DTO, param struct and route, whether or not this workspace consumes it yet), so style and dead-code lints do not apply — the hand-written runtime and the implementing adapter carry the lint bar"
)]
#![allow(
clippy::disallowed_types,
reason = "adjudicated free-form JSON slots: serde_json::Value is workspace-banned (#1694); a generated carrier exists only where the spec leaves the slot open — `allow`, not `expect`, because a carrier may sit inside a feature-gated region and fire only under that feature"
)]
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Options {
#[serde(skip_serializing_if = "Option::is_none")]
pub solution: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub solution_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub vendor: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub restapi_specs_version: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub conformance_profile: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub endpoints: Option<Vec<String>>,
#[serde(flatten)]
pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionsParams {
#[serde(rename = "Accept")]
#[serde(skip_serializing_if = "Option::is_none")]
pub accept: Option<String>,
}
impl OptionsParams {
pub const PARAMS: &'static [crate::rest::routes::Param] = &[crate::rest::routes::Param {
name: "Accept",
location: crate::rest::routes::ParamLocation::Header,
required: false,
explode: false,
kind: crate::rest::routes::ParamKind::Enum(&["application/json"]),
identifier: None,
}];
pub fn from_request(
_matched: &crate::rest::routes::RouteMatch,
_query: Option<&str>,
headers: &http::HeaderMap,
) -> Result<Self, crate::rest::runtime::ApiError> {
Self::from_parts(headers)
}
pub(crate) fn from_parts(
headers: &http::HeaderMap,
) -> Result<Self, crate::rest::runtime::ApiError> {
Ok(Self {
accept: crate::rest::decode::header_optional(headers, "Accept")?,
})
}
}
#[derive(Debug, Clone, Default)]
pub struct OptionsOkHeaders {
pub allow: Option<String>,
pub content_type: Option<String>,
}
impl crate::rest::runtime::ResponseHeaders for OptionsOkHeaders {
fn into_header_map(self) -> Result<http::HeaderMap, crate::rest::runtime::HeaderError> {
let mut map = http::HeaderMap::new();
crate::rest::runtime::set_header(&mut map, "Allow", self.allow)?;
crate::rest::runtime::set_header(&mut map, "Content-Type", self.content_type)?;
Ok(map)
}
}
#[cfg(feature = "rest-server")]
pub mod server {
use super::*;
#[derive(Debug, Clone)]
pub enum OptionsResponse {
Ok {
body: Options,
headers: OptionsOkHeaders,
},
}
#[async_trait::async_trait]
pub trait SystemApi {
async fn options(
&self,
params: OptionsParams,
) -> Result<OptionsResponse, crate::rest::runtime::Refusal> {
Err(crate::rest::runtime::ApiError::NotImplemented.into())
}
}
pub fn router<S>(api: std::sync::Arc<S>) -> axum::Router
where
S: SystemApi + Send + Sync + 'static,
{
axum::Router::new()
.route(
"/",
axum::routing::on(axum::routing::MethodFilter::OPTIONS, handle_options::<S>),
)
.with_state(api)
}
async fn handle_options<S>(
axum::extract::State(api): axum::extract::State<std::sync::Arc<S>>,
headers: http::HeaderMap,
) -> axum::response::Response
where
S: SystemApi + Send + Sync + 'static,
{
let served: Result<axum::response::Response, crate::rest::runtime::Refusal> = async {
let params = OptionsParams::from_parts(&headers)?;
let reply: crate::rest::server::Reply = match api.options(params).await? {
OptionsResponse::Ok { body, headers } => {
let mut reply = crate::rest::server::Reply::new(http::StatusCode::OK);
reply.json(&body)?;
reply.headers(headers)?;
reply
}
};
Ok(reply.finish())
}
.await;
crate::rest::server::respond(served)
}
}
#[cfg(feature = "rest-client")]
pub mod client {
use super::*;
#[derive(Debug, Clone)]
pub enum OptionsOutcome {
Ok {
body: Options,
headers: OptionsOkHeaders,
},
}
#[derive(Debug, Clone)]
pub struct SystemClient<'c, T> {
client: &'c crate::rest::client::Client<T>,
options: crate::rest::client::CallOptions,
}
impl<'c, T: crate::rest::client::Transport> SystemClient<'c, T> {
#[must_use]
pub fn new(client: &'c crate::rest::client::Client<T>) -> Self {
Self {
client,
options: crate::rest::client::CallOptions::default(),
}
}
#[must_use]
pub fn with_options(mut self, options: crate::rest::client::CallOptions) -> Self {
self.options = options;
self
}
pub async fn options(
&self,
params: &OptionsParams,
) -> Result<OptionsOutcome, crate::rest::client::ClientError> {
let mut request =
crate::rest::client::Request::new(http::Method::OPTIONS, String::from("/"));
if let Some(value) = params.accept.as_ref() {
request.header("Accept", &value.to_string())?;
}
request.apply_options(&self.options);
let answer = self.client.execute(request).await?;
match answer.status() {
http::StatusCode::OK => Ok(OptionsOutcome::Ok {
body: answer.json()?,
headers: OptionsOkHeaders {
allow: answer.header("Allow"),
content_type: answer.header("Content-Type"),
},
}),
_ => Err(answer.into_undocumented()),
}
}
}
}
pub const ROUTES: &[(&str, &str, &str)] = &[("OPTIONS", "/", "options")];
pub const ROUTE_PARAMS: &[&[crate::rest::routes::Param]] = &[OptionsParams::PARAMS];
const _: () = assert!(
ROUTE_PARAMS.len() == ROUTES.len(),
"ROUTE_PARAMS carries one row per ROUTES entry"
);
pub const ROUTE_REQUEST_MEDIA: &[&[&str]] = &[&[]];
const _: () = assert!(
ROUTE_REQUEST_MEDIA.len() == ROUTES.len(),
"ROUTE_REQUEST_MEDIA carries one row per ROUTES entry"
);