mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-23 04:52:28 +00:00
clean up some stuff ;; use Default::default() more often
This commit is contained in:
parent
4c50ea0959
commit
c508ac878d
3 changed files with 14 additions and 34 deletions
|
@ -135,7 +135,7 @@ fn main()
|
||||||
);
|
);
|
||||||
|
|
||||||
gotham::start(ADDR, build_router(chain, pipelines, |route| {
|
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::<Users, _>("users");
|
||||||
route.resource::<Auth, _>("auth");
|
route.resource::<Auth, _>("auth");
|
||||||
route.get_openapi("openapi");
|
route.get_openapi("openapi");
|
||||||
|
|
|
@ -22,7 +22,7 @@ use log::error;
|
||||||
use mime::{Mime, APPLICATION_JSON, TEXT_PLAIN};
|
use mime::{Mime, APPLICATION_JSON, TEXT_PLAIN};
|
||||||
use openapiv3::{
|
use openapiv3::{
|
||||||
APIKeyLocation, Components, MediaType, OpenAPI, Operation, Parameter, ParameterData, ParameterSchemaOrContent, PathItem,
|
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
|
SchemaKind, SecurityScheme, Server, StatusCode, Type
|
||||||
};
|
};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
@ -38,28 +38,19 @@ pub struct OpenapiRouter(OpenAPI);
|
||||||
|
|
||||||
impl OpenapiRouter
|
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 {
|
Self(OpenAPI {
|
||||||
openapi: "3.0.2".to_string(),
|
openapi: "3.0.2".to_string(),
|
||||||
info: openapiv3::Info {
|
info: openapiv3::Info {
|
||||||
title: title.to_string(),
|
title, version,
|
||||||
description: None,
|
..Default::default()
|
||||||
terms_of_service: None,
|
|
||||||
contact: None,
|
|
||||||
license: None,
|
|
||||||
version: version.to_string()
|
|
||||||
},
|
},
|
||||||
servers: vec![Server {
|
servers: vec![Server {
|
||||||
url: server_url.to_string(),
|
url,
|
||||||
description: None,
|
..Default::default()
|
||||||
variables: None
|
|
||||||
}],
|
}],
|
||||||
paths: Paths::new(),
|
..Default::default()
|
||||||
components: None,
|
|
||||||
security: Vec::new(),
|
|
||||||
tags: Vec::new(),
|
|
||||||
external_docs: None
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -223,9 +214,7 @@ fn schema_to_content(types : Vec<Mime>, schema : ReferenceOr<Schema>) -> IndexMa
|
||||||
{
|
{
|
||||||
content.insert(ty.to_string(), MediaType {
|
content.insert(ty.to_string(), MediaType {
|
||||||
schema: Some(schema.clone()),
|
schema: Some(schema.clone()),
|
||||||
example: None,
|
..Default::default()
|
||||||
examples: IndexMap::new(),
|
|
||||||
encoding: IndexMap::new()
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
content
|
content
|
||||||
|
@ -349,9 +338,6 @@ fn new_operation(
|
||||||
|
|
||||||
Operation {
|
Operation {
|
||||||
tags: Vec::new(),
|
tags: Vec::new(),
|
||||||
summary: None,
|
|
||||||
description: None,
|
|
||||||
external_documentation: None,
|
|
||||||
operation_id: None, // TODO
|
operation_id: None, // TODO
|
||||||
parameters: params.into_params(),
|
parameters: params.into_params(),
|
||||||
request_body,
|
request_body,
|
||||||
|
@ -361,7 +347,7 @@ fn new_operation(
|
||||||
},
|
},
|
||||||
deprecated: false,
|
deprecated: false,
|
||||||
security,
|
security,
|
||||||
servers: Vec::new()
|
..Default::default()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,12 +51,9 @@ struct PathExtractor<ID : RefUnwindSafe + Send + 'static>
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
pub trait WithOpenapi<D>
|
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
|
where
|
||||||
F : FnOnce((&mut D, &mut OpenapiRouter)),
|
F : FnOnce((&mut D, &mut OpenapiRouter));
|
||||||
Title : ToString,
|
|
||||||
Version : ToString,
|
|
||||||
Url : ToString;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This trait adds the `resource` method to gotham's routing. It allows you to register
|
/// 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,
|
C : PipelineHandleChain<P> + Copy + Send + Sync + 'static,
|
||||||
P : RefUnwindSafe + 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
|
where
|
||||||
F : FnOnce((&mut Self, &mut OpenapiRouter)),
|
F : FnOnce((&mut Self, &mut OpenapiRouter))
|
||||||
Title : ToString,
|
|
||||||
Version : ToString,
|
|
||||||
Url : ToString
|
|
||||||
{
|
{
|
||||||
let mut router = OpenapiRouter::new(title, version, server_url);
|
let mut router = OpenapiRouter::new(title, version, server_url);
|
||||||
block((self, &mut router));
|
block((self, &mut router));
|
||||||
|
|
Loading…
Add table
Reference in a new issue