1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 12:42:28 +00:00

start moving openapi into its own crate

This commit is contained in:
Dominic 2020-03-30 22:30:04 +02:00
parent 91f7b09fbf
commit 1f0be034be
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
15 changed files with 93 additions and 74 deletions

View file

@ -4,9 +4,11 @@
members = [
"gotham_restful",
"gotham_restful_derive",
"gotham_restful_openapi",
"example"
]
[patch.crates-io]
gotham_restful = { path = "./gotham_restful" }
gotham_restful_derive = { path = "./gotham_restful_derive" }
gotham_restful_openapi = { path = "./gotham_restful_openapi" }

View file

@ -17,13 +17,9 @@ gitlab = { repository = "msrd0/gotham-restful", branch = "master" }
fake = "2.2"
gotham = "0.4"
gotham_derive = "0.4"
gotham_restful = { version = "0.0.3", features = ["auth", "openapi"] }
gotham_restful = { version = "0.0.3", features = ["auth"] }
gotham_restful_openapi = "0.0.1"
hyper = "0.12"
log = "0.4"
log4rs = { version = "0.8", features = ["console_appender"], default-features = false }
serde = "1"
[dev-dependencies]
fake = "2.2"
log = "0.4"
log4rs = { version = "0.8", features = ["console_appender"], default-features = false }

View file

@ -23,7 +23,7 @@ futures = "0.1.29"
gotham = "0.4"
gotham_derive = "0.4"
gotham_middleware_diesel = { version = "0.1", optional = true }
gotham_restful_derive = { version = "0.0.2" }
gotham_restful_derive = "0.0.2"
hyper = "0.12.35"
indexmap = { version = "1.3.0", optional = true }
jsonwebtoken = { version = "6.0.1", optional = true }
@ -42,7 +42,6 @@ default = []
auth = ["gotham_restful_derive/auth", "base64", "cookie", "jsonwebtoken"]
errorlog = []
database = ["gotham_restful_derive/database", "gotham_middleware_diesel"]
openapi = ["gotham_restful_derive/openapi", "indexmap", "log", "openapiv3"]
[package.metadata.docs.rs]
all-features = true

View file

@ -128,11 +128,6 @@ pub mod export
#[cfg(feature = "database")]
pub use gotham_middleware_diesel::Repo;
#[cfg(feature = "openapi")]
pub use indexmap::IndexMap;
#[cfg(feature = "openapi")]
pub use openapiv3 as openapi;
}
#[cfg(feature = "auth")]
@ -147,14 +142,6 @@ pub use auth::{
StaticAuthHandler
};
#[cfg(feature = "openapi")]
mod openapi;
#[cfg(feature = "openapi")]
pub use openapi::{
router::GetOpenapi,
types::{OpenapiSchema, OpenapiType}
};
mod resource;
pub use resource::{
Resource,
@ -181,8 +168,6 @@ pub use result::{
mod routing;
pub use routing::{DrawResources, DrawResourceRoutes};
#[cfg(feature = "openapi")]
pub use routing::WithOpenapi;
mod types;
pub use types::*;

View file

@ -1,3 +0,0 @@
pub mod router;
pub mod types;

View file

@ -49,23 +49,6 @@ struct PathExtractor<ID : RefUnwindSafe + Send + 'static>
id : ID
}
/// This trait adds the `with_openapi` method to gotham's routing. It turns the default
/// router into one that will only allow RESTful resources, but record them and generate
/// an OpenAPI specification on request.
#[cfg(feature = "openapi")]
pub trait WithOpenapi<C, P>
where
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P : RefUnwindSafe + Send + Sync + 'static
{
fn with_openapi<F, Title, Version, Url>(&mut self, title : Title, version : Version, server_url : Url, block : F)
where
F : FnOnce(OpenapiRouter<C, P>),
Title : ToString,
Version : ToString,
Url : ToString;
}
/// This trait adds the `resource` method to gotham's routing. It allows you to register
/// any RESTful `Resource` with a path.
pub trait DrawResources<C, P>
@ -346,25 +329,6 @@ impl From<Option<Vec<Mime>>> for MaybeMatchContentTypeHeader
}
}
#[cfg(feature = "openapi")]
impl<C, P, T> WithOpenapi<C, P> for T
where
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P : RefUnwindSafe + Send + Sync + 'static,
T : DrawRoutes<C, P>
{
fn with_openapi<F, Title, Version, Url>(&mut self, title : Title, version : Version, server_url : Url, block : F)
where
F : FnOnce(OpenapiRouter<C, P>),
Title : ToString,
Version : ToString,
Url : ToString
{
let router = OpenapiRouter::new(self, OpenapiBuilder::new(title, version, server_url));
block(router);
}
}
impl<C, P, T> DrawResources<C, P> for T
where
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,

View file

@ -1,5 +1,3 @@
#[cfg(feature = "openapi")]
use crate::OpenapiType;
use crate::result::ResourceError;
use hyper::Chunk;

View file

@ -0,0 +1,33 @@
# -*- eval: (cargo-minor-mode 1) -*-
[package]
name = "gotham_restful_openapi"
version = "0.0.1"
authors = ["Dominic Meiser <git@msrd0.de>"]
edition = "2018"
description = "RESTful additions for Gotham - OpenAPI Support"
keywords = ["gotham", "rest", "restful", "openapi", "swagger"]
license = "EPL-2.0 OR Apache-2.0"
readme = "README.md"
repository = "https://gitlab.com/msrd0/gotham-restful"
[badges]
gitlab = { repository = "msrd0/gotham-restful", branch = "master" }
codecov = { repository = "msrd0/gotham-restful", branch = "master", service = "gitlab" }
[dependencies]
futures = "0.1.29"
gotham = "0.4"
gotham_derive = "0.4"
gotham_restful = "0.0.3"
gotham_restful_derive = { version = "0.0.2", features = ["openapi"] }
hyper = "0.12.35"
indexmap = "1.3.0"
log = "0.4.8"
mime = "0.3.16"
openapiv3 = "0.3"
serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.45"
[dev-dependencies]
thiserror = "1"

View file

@ -0,0 +1 @@
../LICENSE-Apache

View file

@ -0,0 +1 @@
../LICENSE-EPL

View file

@ -0,0 +1 @@
../LICENSE.md

View file

@ -0,0 +1 @@
../README.md

View file

@ -0,0 +1,14 @@
mod router;
pub use router::GetOpenapi;
mod types;
pub use types::{OpenapiType, OpenapiSchema};
/// Not public API
#[doc(hidden)]
pub mod export
{
pub use indexmap::IndexMap;
pub use openapiv3 as openapi;
}

View file

@ -1,12 +1,4 @@
use crate::{
resource::*,
result::*,
routing::*,
OpenapiSchema,
OpenapiType,
RequestBody,
ResourceType
};
use crate::types::*;
use futures::future::ok;
use gotham::{
extractor::QueryStringExtractor,
@ -22,6 +14,7 @@ use gotham::{
},
state::State
};
use gotham_restful::*;
use hyper::Body;
use indexmap::IndexMap;
use log::error;
@ -29,11 +22,45 @@ use mime::{Mime, APPLICATION_JSON, TEXT_PLAIN};
use openapiv3::{
APIKeyLocation, Components, MediaType, OpenAPI, Operation, Parameter, ParameterData, ParameterSchemaOrContent, PathItem,
Paths, ReferenceOr, ReferenceOr::Item, ReferenceOr::Reference, RequestBody as OARequestBody, Response, Responses, Schema,
SchemaKind, SecurityScheme, Server, StatusCode, Type
SchemaKind, SecurityRequirement, SecurityScheme, Server, StatusCode, Type
};
use serde::de::DeserializeOwned;
use std::panic::RefUnwindSafe;
/// This trait adds the `with_openapi` method to gotham's routing. It turns the default
/// router into one that will only allow RESTful resources, but record them and generate
/// an OpenAPI specification on request.
pub trait WithOpenapi<C, P>
where
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P : RefUnwindSafe + Send + Sync + 'static
{
fn with_openapi<F, Title, Version, Url>(&mut self, title : Title, version : Version, server_url : Url, block : F)
where
F : FnOnce(OpenapiRouter<C, P>),
Title : ToString,
Version : ToString,
Url : ToString;
}
impl<C, P, T> WithOpenapi<C, P> for T
where
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
P : RefUnwindSafe + Send + Sync + 'static,
T : DrawRoutes<C, P>
{
fn with_openapi<F, Title, Version, Url>(&mut self, title : Title, version : Version, server_url : Url, block : F)
where
F : FnOnce(OpenapiRouter<C, P>),
Title : ToString,
Version : ToString,
Url : ToString
{
let router = OpenapiRouter::new(self, OpenapiBuilder::new(title, version, server_url));
block(router);
}
}
/// A helper struct for `OpenapiRouter` to build the OpenAPI specification.
pub struct OpenapiBuilder(OpenAPI);