mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-19 22:44:38 +00:00
add some openapi tests
This commit is contained in:
parent
0863d41084
commit
eb091be81b
2 changed files with 32 additions and 1 deletions
|
@ -476,6 +476,7 @@ implOpenapiRouter!(ScopeBuilder);
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test
|
mod test
|
||||||
{
|
{
|
||||||
|
use crate::ResourceResult;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(OpenapiType)]
|
#[derive(OpenapiType)]
|
||||||
|
@ -521,4 +522,24 @@ mod test
|
||||||
let json = serde_json::to_string(¶ms).unwrap();
|
let json = serde_json::to_string(¶ms).unwrap();
|
||||||
assert_eq!(json, format!(r#"[{{"in":"path","name":"{}","required":true,"schema":{{"type":"string"}},"style":"simple"}},{{"in":"query","name":"id","required":true,"schema":{{"type":"integer"}},"style":"form"}}]"#, name));
|
assert_eq!(json, format!(r#"[{{"in":"path","name":"{}","required":true,"schema":{{"type":"string"}},"style":"simple"}},{{"in":"query","name":"id","required":true,"schema":{{"type":"integer"}},"style":"form"}}]"#, name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_content_schema_to_content()
|
||||||
|
{
|
||||||
|
let types = NoContent::accepted_types();
|
||||||
|
let schema = <NoContent as OpenapiType>::schema();
|
||||||
|
let content = schema_to_content(types.unwrap_or_default(), Item(schema.into_schema()));
|
||||||
|
assert!(content.is_empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn raw_schema_to_content()
|
||||||
|
{
|
||||||
|
let types = Raw::<&str>::accepted_types();
|
||||||
|
let schema = <Raw<&str> as OpenapiType>::schema();
|
||||||
|
let content = schema_to_content(types.unwrap_or_default(), Item(schema.into_schema()));
|
||||||
|
assert_eq!(content.len(), 1);
|
||||||
|
let json = serde_json::to_string(&content.values().nth(0).unwrap()).unwrap();
|
||||||
|
assert_eq!(json, r#"{"schema":{"type":"string","format":"binary"}}"#);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use crate::{ResponseBody, StatusCode};
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
use crate::{OpenapiSchema, OpenapiType};
|
use crate::{OpenapiSchema, OpenapiType};
|
||||||
use hyper::Body;
|
use hyper::Body;
|
||||||
use mime::{Mime, APPLICATION_JSON};
|
use mime::{Mime, APPLICATION_JSON, STAR_STAR};
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};
|
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
@ -289,6 +289,11 @@ impl<T : Into<Body>> ResourceResult for Raw<T>
|
||||||
Ok(Response::new(StatusCode::OK, self.raw, Some(self.mime.clone())))
|
Ok(Response::new(StatusCode::OK, self.raw, Some(self.mime.clone())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn accepted_types() -> Option<Vec<Mime>>
|
||||||
|
{
|
||||||
|
Some(vec![STAR_STAR])
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
fn schema() -> OpenapiSchema
|
fn schema() -> OpenapiSchema
|
||||||
{
|
{
|
||||||
|
@ -315,6 +320,11 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn accepted_types() -> Option<Vec<Mime>>
|
||||||
|
{
|
||||||
|
<Raw<T> as ResourceResult>::accepted_types()
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
fn schema() -> OpenapiSchema
|
fn schema() -> OpenapiSchema
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue