1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +00:00

clean up some stuff ;; use Default::default() more often

This commit is contained in:
Dominic 2020-03-30 22:39:48 +02:00
parent 4c50ea0959
commit c508ac878d
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
3 changed files with 14 additions and 34 deletions

View file

@ -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, _>("users");
route.resource::<Auth, _>("auth");
route.get_openapi("openapi");

View file

@ -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 : ToString, Version : ToString, Url : ToString>(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()
}
}

View file

@ -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));