use std::marker::PhantomData;
use utoipa::openapi::path::{OperationBuilder, Parameter};
use utoipa::openapi::schema::Schema;
use utoipa::openapi::RefOr;
use crate::doc_responses::DocResponseBody;
use crate::doc_traits::{
DocHeaderParams, DocOperationSecurity, DocPathParams, DocPathScalar, DocQueryParams,
};
use crate::inner_schema::InnerToSchema;
pub struct QueryParamContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> QueryParamContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for QueryParamContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait QueryParamsImplementedAdhoc: Sized {
fn __collect(self) -> Vec<Parameter>;
}
impl<T: DocQueryParams + ?Sized> QueryParamsImplementedAdhoc for QueryParamContribution<T> {
fn __collect(self) -> Vec<Parameter> {
let mut op = OperationBuilder::new().build();
T::describe(&mut op);
op.parameters.unwrap_or_default()
}
}
pub trait QueryParamsMissingAdhoc: Sized {
fn __collect(self) -> Vec<Parameter>;
}
impl<T: ?Sized> QueryParamsMissingAdhoc for &QueryParamContribution<T> {
fn __collect(self) -> Vec<Parameter> {
Vec::new()
}
}
pub struct PathParamContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> PathParamContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for PathParamContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait PathParamsImplementedAdhoc: Sized {
fn __collect(self, path_param_names: &[&'static str]) -> Vec<Parameter>;
}
impl<T: DocPathParams + ?Sized> PathParamsImplementedAdhoc for PathParamContribution<T> {
fn __collect(self, path_param_names: &[&'static str]) -> Vec<Parameter> {
let mut op = OperationBuilder::new().build();
T::describe(&mut op, path_param_names);
op.parameters.unwrap_or_default()
}
}
pub trait PathParamsMissingAdhoc: Sized {
fn __collect(self, path_param_names: &[&'static str]) -> Vec<Parameter>;
}
impl<T: ?Sized> PathParamsMissingAdhoc for &PathParamContribution<T> {
fn __collect(self, _path_param_names: &[&'static str]) -> Vec<Parameter> {
Vec::new()
}
}
pub struct PathScalarContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> PathScalarContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for PathScalarContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait PathScalarImplementedAdhoc: Sized {
fn __collect(self, path_param_names: &[&'static str]) -> Vec<Parameter>;
}
impl<T: DocPathScalar + ?Sized> PathScalarImplementedAdhoc for PathScalarContribution<T> {
fn __collect(self, path_param_names: &[&'static str]) -> Vec<Parameter> {
let mut op = OperationBuilder::new().build();
T::describe_scalar(&mut op, path_param_names);
op.parameters.unwrap_or_default()
}
}
pub trait PathScalarMissingAdhoc: Sized {
fn __collect(self, path_param_names: &[&'static str]) -> Vec<Parameter>;
}
impl<T: ?Sized> PathScalarMissingAdhoc for &PathScalarContribution<T> {
fn __collect(self, _path_param_names: &[&'static str]) -> Vec<Parameter> {
Vec::new()
}
}
pub struct HeaderParamContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> HeaderParamContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for HeaderParamContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait HeaderParamsImplementedAdhoc: Sized {
fn __collect(self) -> Vec<Parameter>;
}
impl<T: DocHeaderParams + ?Sized> HeaderParamsImplementedAdhoc for HeaderParamContribution<T> {
fn __collect(self) -> Vec<Parameter> {
let mut op = OperationBuilder::new().build();
T::describe(&mut op);
op.parameters.unwrap_or_default()
}
}
pub trait HeaderParamsMissingAdhoc: Sized {
fn __collect(self) -> Vec<Parameter>;
}
impl<T: ?Sized> HeaderParamsMissingAdhoc for &HeaderParamContribution<T> {
fn __collect(self) -> Vec<Parameter> {
Vec::new()
}
}
pub struct InnerSchemaContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> InnerSchemaContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for InnerSchemaContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait InnerSchemaImplementedAdhoc: Sized {
fn __collect(self, out: &mut Vec<(String, RefOr<Schema>)>);
}
impl<T: InnerToSchema + ?Sized> InnerSchemaImplementedAdhoc for InnerSchemaContribution<T> {
fn __collect(self, out: &mut Vec<(String, RefOr<Schema>)>) {
T::inner_schemas(out);
}
}
pub trait InnerSchemaMissingAdhoc: Sized {
fn __collect(self, _out: &mut Vec<(String, RefOr<Schema>)>);
}
impl<T: ?Sized> InnerSchemaMissingAdhoc for &InnerSchemaContribution<T> {
fn __collect(self, _out: &mut Vec<(String, RefOr<Schema>)>) {}
}
pub struct BareSchemaContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> BareSchemaContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for BareSchemaContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait BareSchemaImplementedAdhoc: Sized {
fn __collect(self, out: &mut Vec<(String, RefOr<Schema>)>);
}
impl<T: utoipa::ToSchema + ?Sized> BareSchemaImplementedAdhoc for BareSchemaContribution<T> {
fn __collect(self, out: &mut Vec<(String, RefOr<Schema>)>) {
<T as utoipa::ToSchema>::schemas(out);
}
}
pub trait BareSchemaMissingAdhoc: Sized {
fn __collect(self, _out: &mut Vec<(String, RefOr<Schema>)>);
}
impl<T: ?Sized> BareSchemaMissingAdhoc for &BareSchemaContribution<T> {
fn __collect(self, _out: &mut Vec<(String, RefOr<Schema>)>) {}
}
pub struct GenericArgSchemaContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> GenericArgSchemaContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for GenericArgSchemaContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait GenericArgSchemaImplementedAdhoc: Sized {
fn __collect(self, out: &mut Vec<(String, RefOr<Schema>)>);
}
impl<T> GenericArgSchemaImplementedAdhoc for GenericArgSchemaContribution<T>
where
T: utoipa::PartialSchema + utoipa::ToSchema,
{
fn __collect(self, out: &mut Vec<(String, RefOr<Schema>)>) {
crate::doc_responses::register_named_schema::<T>(out);
}
}
pub trait GenericArgSchemaMissingAdhoc: Sized {
fn __collect(self, _out: &mut Vec<(String, RefOr<Schema>)>);
}
impl<T: ?Sized> GenericArgSchemaMissingAdhoc for &GenericArgSchemaContribution<T> {
fn __collect(self, _out: &mut Vec<(String, RefOr<Schema>)>) {}
}
pub struct OpSecurityContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> OpSecurityContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for OpSecurityContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait OpSecurityImplementedAdhoc: Sized {
fn __describe(self, op: &mut utoipa::openapi::path::Operation);
}
impl<T: DocOperationSecurity + ?Sized> OpSecurityImplementedAdhoc for OpSecurityContribution<T> {
fn __describe(self, op: &mut utoipa::openapi::path::Operation) {
T::describe(op);
}
}
pub trait OpSecurityMissingAdhoc: Sized {
fn __describe(self, op: &mut utoipa::openapi::path::Operation);
}
impl<T: ?Sized> OpSecurityMissingAdhoc for &OpSecurityContribution<T> {
fn __describe(self, _op: &mut utoipa::openapi::path::Operation) {}
}
pub struct ResponseBodyContribution<T: ?Sized>(PhantomData<T>);
impl<T: ?Sized> ResponseBodyContribution<T> {
pub const fn new() -> Self {
Self(PhantomData)
}
}
impl<T: ?Sized> Default for ResponseBodyContribution<T> {
fn default() -> Self {
Self::new()
}
}
pub trait ResponseBodyImplementedAdhoc: Sized {
fn __describe(
self,
op: &mut utoipa::openapi::path::Operation,
schemas: &mut Vec<(String, RefOr<Schema>)>,
);
}
impl<T: DocResponseBody + ?Sized> ResponseBodyImplementedAdhoc for ResponseBodyContribution<T> {
fn __describe(
self,
op: &mut utoipa::openapi::path::Operation,
schemas: &mut Vec<(String, RefOr<Schema>)>,
) {
T::describe(op, schemas);
}
}
pub trait ResponseBodyMissingAdhoc: Sized {
fn __describe(
self,
op: &mut utoipa::openapi::path::Operation,
schemas: &mut Vec<(String, RefOr<Schema>)>,
);
}
impl<T: ?Sized> ResponseBodyMissingAdhoc for &ResponseBodyContribution<T> {
fn __describe(
self,
_op: &mut utoipa::openapi::path::Operation,
_schemas: &mut Vec<(String, RefOr<Schema>)>,
) {
}
}