1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

apply clippy suggestions

This commit is contained in:
Dominic 2019-10-13 23:36:10 +02:00
parent 286466fcc9
commit 4429fced3b
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
7 changed files with 62 additions and 78 deletions

View file

@ -60,11 +60,10 @@ impl OpenapiRouter
/// modify the path and add it back after the modification
fn remove_path(&mut self, path : &str) -> PathItem
{
if let Some(Item(item)) = self.0.paths.swap_remove(path)
{
return item;
match self.0.paths.swap_remove(path) {
Some(Item(item)) => item,
_ => PathItem::default()
}
return PathItem::default()
}
fn add_path<Path : ToString>(&mut self, path : Path, item : PathItem)
@ -78,11 +77,11 @@ impl OpenapiRouter
match &mut self.0.components {
Some(comp) => {
comp.schemas.insert(name, Item(schema.to_schema()));
comp.schemas.insert(name, Item(schema.into_schema()));
},
None => {
let mut comp = Components::default();
comp.schemas.insert(name, Item(schema.to_schema()));
comp.schemas.insert(name, Item(schema.into_schema()));
self.0.components = Some(comp);
}
};
@ -103,17 +102,17 @@ impl OpenapiRouter
fn add_schema<T : OpenapiType>(&mut self) -> ReferenceOr<Schema>
{
let mut schema = T::to_schema();
if let Some(name) = schema.name.clone()
{
let reference = Reference { reference: format!("#/components/schemas/{}", name) };
self.add_schema_impl(name, schema);
reference
}
else
{
self.add_schema_dependencies(&mut schema.dependencies);
Item(schema.to_schema())
let mut schema = T::schema();
match schema.name.clone() {
Some(name) => {
let reference = Reference { reference: format!("#/components/schemas/{}", name) };
self.add_schema_impl(name, schema);
reference
},
None => {
self.add_schema_dependencies(&mut schema.dependencies);
Item(schema.into_schema())
}
}
}
}
@ -211,7 +210,7 @@ impl<'a> OperationParams<'a>
description: None,
required: true,
deprecated: None,
format: ParameterSchemaOrContent::Schema(Item(String::to_schema().to_schema())),
format: ParameterSchemaOrContent::Schema(Item(String::schema().into_schema())),
example: None,
examples: IndexMap::new()
},

View file

@ -32,7 +32,7 @@ impl OpenapiSchema
}
}
pub fn to_schema(self) -> Schema
pub fn into_schema(self) -> Schema
{
Schema {
schema_data: SchemaData {
@ -54,12 +54,12 @@ impl OpenapiSchema
pub trait OpenapiType
{
fn to_schema() -> OpenapiSchema;
fn schema() -> OpenapiSchema;
}
impl OpenapiType for ()
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
OpenapiSchema::new(SchemaKind::Type(Type::Object(ObjectType::default())))
}
@ -67,7 +67,7 @@ impl OpenapiType for ()
impl OpenapiType for bool
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
OpenapiSchema::new(SchemaKind::Type(Type::Boolean{}))
}
@ -77,7 +77,7 @@ macro_rules! int_types {
($($int_ty:ty),*) => {$(
impl OpenapiType for $int_ty
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
OpenapiSchema::new(SchemaKind::Type(Type::Integer(IntegerType::default())))
}
@ -91,7 +91,7 @@ macro_rules! num_types {
($($num_ty:ty),*) => {$(
impl OpenapiType for $num_ty
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
OpenapiSchema::new(SchemaKind::Type(Type::Number(NumberType::default())))
}
@ -105,7 +105,7 @@ macro_rules! str_types {
($($str_ty:ty),*) => {$(
impl OpenapiType for $str_ty
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
OpenapiSchema::new(SchemaKind::Type(Type::String(StringType::default())))
}
@ -131,9 +131,9 @@ str_types!(String, &str);
impl<T : OpenapiType> OpenapiType for Option<T>
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
let schema = T::to_schema();
let schema = T::schema();
let mut dependencies = schema.dependencies.clone();
let schema = match schema.name.clone() {
Some(name) => {
@ -155,20 +155,19 @@ impl<T : OpenapiType> OpenapiType for Option<T>
impl<T : OpenapiType> OpenapiType for Vec<T>
{
fn to_schema() -> OpenapiSchema
fn schema() -> OpenapiSchema
{
let schema = T::to_schema();
let schema = T::schema();
let mut dependencies = schema.dependencies.clone();
let items = if let Some(name) = schema.name.clone()
let items = match schema.name.clone()
{
let reference = Reference { reference: format!("#/components/schemas/{}", name) };
dependencies.insert(name, schema);
reference
}
else
{
Item(Box::new(schema.to_schema()))
Some(name) => {
let reference = Reference { reference: format!("#/components/schemas/{}", name) };
dependencies.insert(name, schema);
reference
},
None => Item(Box::new(schema.into_schema()))
};
OpenapiSchema {