-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0a8191
commit 665ca4f
Showing
12 changed files
with
163 additions
and
229 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
use openapiv3::Operation; | ||
use openapiv3::{Operation, Parameter, RefOr, Schema}; | ||
|
||
pub struct OperationRegister { | ||
// module_path: &'static str, | ||
pub name: &'static str, | ||
pub constructor: &'static (dyn Sync + Send + Fn() -> Operation), | ||
} | ||
|
||
pub trait OaParameter { | ||
fn body_schema() -> Option<RefOr<Schema>> { | ||
None | ||
} | ||
fn parameter_schemas() -> Vec<RefOr<Schema>> { | ||
Vec::new() | ||
} | ||
fn parameters() -> Vec<RefOr<Parameter>> { | ||
Vec::new() | ||
} | ||
} | ||
|
||
impl<T, E> OaParameter for Result<T, E> | ||
where | ||
T: OaParameter, | ||
{ | ||
fn body_schema() -> Option<RefOr<Schema>> { | ||
T::body_schema() | ||
} | ||
} | ||
|
||
inventory::collect!(OperationRegister); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,54 @@ | ||
use openapiv3 as oa; | ||
use openapiv3::{ReferenceOr, Schema}; | ||
use openapiv3::{RefOr, Schema, SchemaKind, Type}; | ||
|
||
use crate::OaSchema; | ||
use crate::{OaParameter, OaSchema}; | ||
|
||
impl<T: OaSchema> OaSchema for actix_web::web::Json<T> { | ||
fn schema() -> Schema { | ||
panic!("Call body_schema() for Json, not schema().") | ||
} | ||
|
||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
impl<T: OaSchema> OaParameter for actix_web::web::Json<T> { | ||
fn body_schema() -> Option<RefOr<Schema>> { | ||
T::body_schema() | ||
} | ||
} | ||
|
||
impl<T> OaSchema for actix_web::web::Data<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Data, not schema()."); | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
None | ||
} | ||
} | ||
|
||
impl OaSchema for actix_web::HttpRequest { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for HttpRequest, not schema()."); | ||
} | ||
} | ||
|
||
impl OaSchema for actix_web::HttpResponse { | ||
fn schema() -> Schema { | ||
panic!("Call body_schema() for HttpResponse, not schema()."); | ||
Schema::new_any() | ||
} | ||
} | ||
|
||
impl<T: OaSchema> OaSchema for actix_web::web::Path<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Path, not schema()."); | ||
} | ||
impl<T> OaParameter for actix_web::web::Data<T> {} | ||
impl OaParameter for actix_web::HttpRequest {} | ||
|
||
fn parameters() -> Vec<ReferenceOr<oa::Parameter>> { | ||
T::parameters() | ||
} | ||
|
||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
None | ||
impl<T: OaParameter> OaParameter for actix_web::web::Path<T> { | ||
fn parameters() -> Vec<RefOr<oa::Parameter>> { | ||
T::parameter_schemas() | ||
.into_iter() | ||
.map(|s| RefOr::Item(oa::Parameter::path("path", s))) | ||
.collect() | ||
} | ||
} | ||
|
||
impl<T: OaSchema> OaSchema for actix_web::web::Query<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Query, not schema()."); | ||
} | ||
|
||
fn parameters() -> Vec<ReferenceOr<oa::Parameter>> { | ||
T::parameters() | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
None | ||
impl<T: OaParameter> OaParameter for actix_web::web::Query<T> { | ||
fn parameters() -> Vec<RefOr<oa::Parameter>> { | ||
T::parameter_schemas() | ||
.into_iter() | ||
.flat_map(|s| s.into_item()) | ||
.flat_map(|s| match s.kind { | ||
SchemaKind::Type(Type::Object(o)) => { Some(o.properties) } | ||
_ => None | ||
}) | ||
.flatten() | ||
.map(|(k, v)| RefOr::Item(oa::Parameter::query(k, v))) | ||
.collect() | ||
} | ||
} | ||
|
||
#[cfg(feature = "qs")] | ||
impl<T: OaSchema> OaSchema for serde_qs::actix::QsQuery<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for QsQuery, not schema()."); | ||
} | ||
|
||
fn parameters() -> Vec<ReferenceOr<oa::Parameter>> { | ||
let p = oa::Parameter::query("query", T::schema_ref()); | ||
vec![ReferenceOr::Item(p)] | ||
impl<T: OaParameter> OaParameter for serde_qs::actix::QsQuery<T> { | ||
fn parameters() -> Vec<RefOr<oa::Parameter>> { | ||
T::parameter_schemas() | ||
.into_iter() | ||
.map(|s| RefOr::Item(oa::Parameter::query("query", s))) | ||
.collect() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,56 @@ | ||
use openapiv3::{ReferenceOr, Schema}; | ||
use openapiv3::{RefOr, Schema, SchemaKind, Type}; | ||
use openapiv3 as oa; | ||
|
||
use crate::{impl_parameters, OaSchema}; | ||
|
||
impl<T: OaSchema> OaSchema for axum::extract::Json<T> { | ||
fn schema() -> Schema { | ||
panic!("Call body_schema() for Json, not schema().") | ||
} | ||
|
||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
T::body_schema() | ||
} | ||
} | ||
|
||
impl<T> OaSchema for axum::extract::Extension<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Extension, not schema().") | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
} | ||
|
||
impl<T> OaSchema for axum::extract::State<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for State, not schema().") | ||
} | ||
|
||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
None | ||
} | ||
} | ||
use crate::{OaParameter, OaSchema}; | ||
|
||
impl<T> OaSchema for http::Response<T> { | ||
fn schema() -> Schema { | ||
Schema::new_any() | ||
} | ||
} | ||
|
||
impl<T> OaSchema for http::Request<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Request, not schema().") | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
} | ||
|
||
impl<T> OaSchema for axum::extract::ConnectInfo<T> { | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for ConnectInfo, not schema().") | ||
} | ||
} | ||
|
||
impl OaSchema for http::HeaderMap { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for HeaderMap, not schema().") | ||
impl<T: OaSchema> OaParameter for axum::extract::Json<T> { | ||
fn body_schema() -> Option<RefOr<Schema>> { | ||
T::body_schema() | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
} | ||
impl<T> OaParameter for axum::extract::Extension<T> {} | ||
impl<T> OaParameter for axum::extract::State<T> {} | ||
impl<T> OaParameter for http::Request<T> {} | ||
impl<T> OaParameter for axum::extract::ConnectInfo<T> {} | ||
impl OaParameter for http::HeaderMap {} | ||
impl OaParameter for http::request::Parts {} | ||
|
||
impl<T: OaSchema> OaSchema for axum::extract::Query<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Query, not schema().") | ||
} | ||
|
||
fn parameters() -> Vec<ReferenceOr<oa::Parameter>> { | ||
let p = oa::Parameter::query("query", T::schema_ref()); | ||
vec![ReferenceOr::Item(p)] | ||
impl<T: OaParameter> OaParameter for axum::extract::Query<T> { | ||
fn parameters() -> Vec<RefOr<oa::Parameter>> { | ||
T::parameter_schemas() | ||
.into_iter() | ||
.flat_map(|s| s.into_item()) | ||
.flat_map(|s| match s.kind { | ||
SchemaKind::Type(Type::Object(o)) => { Some(o.properties) } | ||
_ => None | ||
}) | ||
.flatten() | ||
.map(|(k, v)| RefOr::Item(oa::Parameter::query(k, v))) | ||
.collect() | ||
} | ||
|
||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
} | ||
|
||
impl<T: OaSchema> OaSchema for axum::extract::Path<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Path, not schema()."); | ||
} | ||
|
||
fn parameters() -> Vec<ReferenceOr<oa::Parameter>> { | ||
let p = oa::Parameter::path("path", T::schema_ref()); | ||
vec![ReferenceOr::Item(p)] | ||
impl<T: OaParameter> OaParameter for axum::extract::Path<T> { | ||
fn parameters() -> Vec<RefOr<oa::Parameter>> { | ||
T::parameter_schemas() | ||
.into_iter() | ||
.map(|s| RefOr::Item(oa::Parameter::path("path", s))) | ||
.collect() | ||
} | ||
|
||
fn body_schema() -> Option<ReferenceOr<Schema>> { | ||
None | ||
} | ||
} | ||
|
||
impl OaSchema for http::request::Parts { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for Parts, not schema().") | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
} | ||
|
||
#[cfg(feature = "qs")] | ||
impl<T: OaSchema> OaSchema for serde_qs::axum::QsQuery<T> { | ||
fn schema() -> Schema { | ||
panic!("Call parameters() for QsQuery, not schema().") | ||
} | ||
|
||
fn parameters() -> Vec<ReferenceOr<oa::Parameter>> { | ||
let p = oa::Parameter::query("query", T::schema_ref()); | ||
vec![ReferenceOr::Item(p)] | ||
} | ||
fn body_schema() -> Option<ReferenceOr<Schema>> { None } | ||
} | ||
|
||
impl_parameters!(axum::extract::Path, A1); | ||
impl_parameters!(axum::extract::Path, A1, A2); | ||
impl_parameters!(axum::extract::Path, A1, A2, A3); | ||
impl<T: OaParameter> OaParameter for serde_qs::axum::QsQuery<T> { | ||
fn parameters() -> Vec<RefOr<oa::Parameter>> { | ||
T::parameter_schemas() | ||
.into_iter() | ||
.map(|s| RefOr::Item(oa::Parameter::query("query", s))) | ||
.collect() | ||
} | ||
} |
Oops, something went wrong.