diff --git a/example/src/main.rs b/example/src/main.rs index 97c2c39..8dfc0b4 100644 --- a/example/src/main.rs +++ b/example/src/main.rs @@ -135,7 +135,7 @@ fn main() ); gotham::start(ADDR, build_router(chain, pipelines, |route| { - route.with_openapi("Users Example", "0.0.1", format!("http://{}", ADDR), |mut route| { + route.with_openapi("Users Example".to_owned(), "0.0.1".to_owned(), format!("http://{}", ADDR), |mut route| { route.resource::("users"); route.resource::("auth"); route.get_openapi("openapi"); diff --git a/gotham_restful/src/openapi/router.rs b/gotham_restful/src/openapi/router.rs index 9f5c185..6e52db1 100644 --- a/gotham_restful/src/openapi/router.rs +++ b/gotham_restful/src/openapi/router.rs @@ -22,7 +22,7 @@ use log::error; 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, + ReferenceOr, ReferenceOr::Item, ReferenceOr::Reference, RequestBody as OARequestBody, Response, Responses, Schema, SchemaKind, SecurityScheme, Server, StatusCode, Type }; use serde::de::DeserializeOwned; @@ -38,28 +38,19 @@ pub struct OpenapiRouter(OpenAPI); impl OpenapiRouter { - pub fn new(title : Title, version : Version, server_url : Url) -> Self + pub fn new(title : String, version : String, url : String) -> Self { Self(OpenAPI { openapi: "3.0.2".to_string(), info: openapiv3::Info { - title: title.to_string(), - description: None, - terms_of_service: None, - contact: None, - license: None, - version: version.to_string() + title, version, + ..Default::default() }, servers: vec![Server { - url: server_url.to_string(), - description: None, - variables: None + url, + ..Default::default() }], - paths: Paths::new(), - components: None, - security: Vec::new(), - tags: Vec::new(), - external_docs: None + ..Default::default() }) } @@ -223,9 +214,7 @@ fn schema_to_content(types : Vec<Mime>, schema : ReferenceOr<Schema>) -> IndexMa { content.insert(ty.to_string(), MediaType { schema: Some(schema.clone()), - example: None, - examples: IndexMap::new(), - encoding: IndexMap::new() + ..Default::default() }); } content @@ -349,9 +338,6 @@ fn new_operation( Operation { tags: Vec::new(), - summary: None, - description: None, - external_documentation: None, operation_id: None, // TODO parameters: params.into_params(), request_body, @@ -361,7 +347,7 @@ fn new_operation( }, deprecated: false, security, - servers: Vec::new() + ..Default::default() } } diff --git a/gotham_restful/src/routing.rs b/gotham_restful/src/routing.rs index 5a16281..2b0181f 100644 --- a/gotham_restful/src/routing.rs +++ b/gotham_restful/src/routing.rs @@ -51,12 +51,9 @@ struct PathExtractor<ID : RefUnwindSafe + Send + 'static> #[cfg(feature = "openapi")] pub trait WithOpenapi<D> { - fn with_openapi<F, Title, Version, Url>(&mut self, title : Title, version : Version, server_url : Url, block : F) + fn with_openapi<F>(&mut self, title : String, version : String, server_url : String, block : F) where - F : FnOnce((&mut D, &mut OpenapiRouter)), - Title : ToString, - Version : ToString, - Url : ToString; + F : FnOnce((&mut D, &mut OpenapiRouter)); } /// This trait adds the `resource` method to gotham's routing. It allows you to register @@ -345,12 +342,9 @@ macro_rules! implDrawResourceRoutes { 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) + fn with_openapi<F>(&mut self, title : String, version : String, server_url : String, block : F) where - F : FnOnce((&mut Self, &mut OpenapiRouter)), - Title : ToString, - Version : ToString, - Url : ToString + F : FnOnce((&mut Self, &mut OpenapiRouter)) { let mut router = OpenapiRouter::new(title, version, server_url); block((self, &mut router));