diff --git a/.github/workflows/typos.yml b/.github/workflows/typos.yml new file mode 100644 index 0000000..46f5458 --- /dev/null +++ b/.github/workflows/typos.yml @@ -0,0 +1,16 @@ +name: Typos + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + typos: + name: Check for typos + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: crate-ci/typos@v1.19.0 diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 0000000..bc31e69 --- /dev/null +++ b/.typos.toml @@ -0,0 +1,9 @@ +[default] +extend-ignore-re = [ + "ff32ba0", +] + +[files] +extend-exclude = [ + "crates/aide/res/**/*.js", +] diff --git a/crates/aide/Cargo.toml b/crates/aide/Cargo.toml index 774e06a..10613d7 100644 --- a/crates/aide/Cargo.toml +++ b/crates/aide/Cargo.toml @@ -17,7 +17,6 @@ serde_json = "1" thiserror = "1" tracing = "0" aide-macros = { version = "0.7.0", path = "../aide-macros", optional = true } -derive_more = "0.99.17" bytes = { version = "1", optional = true } http = { version = "1.0.0", optional = true } diff --git a/crates/aide/src/axum/mod.rs b/crates/aide/src/axum/mod.rs index b9cef20..df51617 100644 --- a/crates/aide/src/axum/mod.rs +++ b/crates/aide/src/axum/mod.rs @@ -713,7 +713,7 @@ mod private { pub trait Sealed {} } -/// A trait that extens [`axum::handler::Handler`] with API operation +/// A trait that extends [`axum::handler::Handler`] with API operation /// details. /// /// Just like axum's `Handler`, it is automatically implemented diff --git a/crates/aide/src/gen.rs b/crates/aide/src/gen.rs index 7b79914..20deafa 100644 --- a/crates/aide/src/gen.rs +++ b/crates/aide/src/gen.rs @@ -76,7 +76,7 @@ pub fn infer_responses(infer: bool) { }); } -/// Output all theoretically possbile error responses +/// Output all theoretically possible error responses /// including framework-specific ones. /// /// This is disabled by default. diff --git a/crates/aide/src/helpers/no_api.rs b/crates/aide/src/helpers/no_api.rs index 1dd934f..b9ab1d6 100644 --- a/crates/aide/src/helpers/no_api.rs +++ b/crates/aide/src/helpers/no_api.rs @@ -1,9 +1,11 @@ -use derive_more::{AsMut, AsRef, Deref, DerefMut, From}; +use std::ops::{Deref, DerefMut}; + use serde::{Deserialize, Serialize}; use crate::{OperationInput, OperationOutput}; -/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a default empty documentation. +/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a default empty documentation. +/// /// For types that already implement [`OperationInput`] or [`OperationOutput`] it overrides the documentation and hides it. /// ```ignore /// pub async fn my_sqlx_tx_endpoint( @@ -11,23 +13,7 @@ use crate::{OperationInput, OperationOutput}; /// ) -> NoApi> // Hides the API of the return type /// # {} /// ``` -#[derive( - Copy, - Clone, - Debug, - Ord, - PartialOrd, - Eq, - PartialEq, - Hash, - Serialize, - Deserialize, - Deref, - DerefMut, - AsRef, - AsMut, - From, -)] +#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] pub struct NoApi(pub T); impl NoApi { @@ -37,6 +23,38 @@ impl NoApi { } } +impl Deref for NoApi { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for NoApi { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef for NoApi { + fn as_ref(&self) -> &T { + &self.0 + } +} + +impl AsMut for NoApi { + fn as_mut(&mut self) -> &mut T { + &mut self.0 + } +} + +impl From for NoApi { + fn from(value: T) -> Self { + Self(value) + } +} + impl OperationInput for NoApi {} impl OperationOutput for NoApi { diff --git a/crates/aide/src/helpers/use_api.rs b/crates/aide/src/helpers/use_api.rs index a98c447..2e56762 100644 --- a/crates/aide/src/helpers/use_api.rs +++ b/crates/aide/src/helpers/use_api.rs @@ -1,6 +1,8 @@ -use std::marker::PhantomData; +use std::{ + marker::PhantomData, + ops::{Deref, DerefMut}, +}; -use derive_more::{AsMut, AsRef, Deref, DerefMut}; use serde::{Deserialize, Serialize}; use crate::gen::GenContext; @@ -24,37 +26,10 @@ impl IntoApi for T { } /// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with the api documentation of [A]. +/// /// For types that already implement [`OperationInput`] or [`OperationOutput`] it overrides the documentation with the provided one. -#[derive( - Copy, - Clone, - Debug, - Ord, - PartialOrd, - Eq, - PartialEq, - Hash, - Serialize, - Deserialize, - Deref, - DerefMut, - AsRef, - AsMut, -)] -pub struct UseApi( - #[as_ref] - #[as_mut] - #[deref] - #[deref_mut] - pub T, - pub PhantomData, -); - -impl From for UseApi { - fn from(value: T) -> Self { - Self(value, Default::default()) - } -} +#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct UseApi(pub T, pub PhantomData); impl UseApi { /// Unwraps [Self] into its inner type @@ -63,6 +38,38 @@ impl UseApi { } } +impl Deref for UseApi { + type Target = T; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for UseApi { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef for UseApi { + fn as_ref(&self) -> &T { + &self.0 + } +} + +impl AsMut for UseApi { + fn as_mut(&mut self) -> &mut T { + &mut self.0 + } +} + +impl From for UseApi { + fn from(value: T) -> Self { + Self(value, Default::default()) + } +} + impl OperationInput for UseApi where A: OperationInput, diff --git a/crates/aide/src/helpers/with_api.rs b/crates/aide/src/helpers/with_api.rs index 6d269b2..a1641fb 100644 --- a/crates/aide/src/helpers/with_api.rs +++ b/crates/aide/src/helpers/with_api.rs @@ -1,6 +1,8 @@ -use std::marker::PhantomData; +use std::{ + marker::PhantomData, + ops::{Deref, DerefMut}, +}; -use derive_more::{AsMut, AsRef, Deref, DerefMut}; use serde::{Deserialize, Serialize}; use crate::gen::GenContext; @@ -8,6 +10,7 @@ use crate::openapi::{Operation, Response}; use crate::{OperationInput, OperationOutput}; /// Trait that allows implementing a custom Api definition for any type. +/// /// Two approaches are possible: /// /// 1. Simple Type override for concrete types @@ -58,37 +61,16 @@ use crate::{OperationInput, OperationOutput}; /// } /// ``` pub trait ApiOverride { - /// The type that is being overriden + /// The type that is being overridden type Target; } -/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a provided documentation. +/// Allows non [`OperationInput`] or [`OperationOutput`] types to be used in aide handlers with a provided documentation. +/// /// For types that already implement [`OperationInput`] or [`OperationOutput`] it overrides the documentation with the provided one. /// See [`ApiOverride`] on how to implement such an override -#[derive( - Copy, - Clone, - Debug, - Ord, - PartialOrd, - Eq, - PartialEq, - Hash, - Serialize, - Deserialize, - Deref, - DerefMut, - AsRef, - AsMut, -)] -pub struct WithApi( - #[as_ref] - #[as_mut] - #[deref] - #[deref_mut] - pub T::Target, - pub PhantomData, -) +#[derive(Copy, Clone, Debug, Ord, PartialOrd, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct WithApi(pub T::Target, pub PhantomData) where T: ApiOverride; @@ -102,6 +84,44 @@ where } } +impl Deref for WithApi +where + T: ApiOverride, +{ + type Target = T::Target; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for WithApi +where + T: ApiOverride, +{ + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef for WithApi +where + T: ApiOverride, +{ + fn as_ref(&self) -> &T::Target { + &self.0 + } +} + +impl AsMut for WithApi +where + T: ApiOverride, +{ + fn as_mut(&mut self) -> &mut T::Target { + &mut self.0 + } +} + impl OperationInput for WithApi where T: OperationInput + ApiOverride, diff --git a/crates/axum-jsonschema/src/lib.rs b/crates/axum-jsonschema/src/lib.rs index 917cd1f..be19ee0 100644 --- a/crates/axum-jsonschema/src/lib.rs +++ b/crates/axum-jsonschema/src/lib.rs @@ -185,7 +185,7 @@ impl From for JsonSchemaErrorResponse { error: "deserialization failed".to_string(), extra: AdditionalError::Deserialization(DeserializationResponse { deserialization_error: VecDeque::from([PathError { - // keys and index seperated by a '/' + // keys and index separated by a '/' // enum is ignored because it doesn't exist in json instance_location: std::iter::once(String::new()) .chain(s.path().iter().map(|s| match s {