1
0
Fork 0
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:
Dominic 2019-10-20 16:19:01 +02:00
parent 0863d41084
commit eb091be81b
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 32 additions and 1 deletions

View file

@ -476,6 +476,7 @@ implOpenapiRouter!(ScopeBuilder);
#[cfg(test)]
mod test
{
use crate::ResourceResult;
use super::*;
#[derive(OpenapiType)]
@ -521,4 +522,24 @@ mod test
let json = serde_json::to_string(&params).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));
}
#[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"}}"#);
}
}

View file

@ -2,7 +2,7 @@ use crate::{ResponseBody, StatusCode};
#[cfg(feature = "openapi")]
use crate::{OpenapiSchema, OpenapiType};
use hyper::Body;
use mime::{Mime, APPLICATION_JSON};
use mime::{Mime, APPLICATION_JSON, STAR_STAR};
#[cfg(feature = "openapi")]
use openapiv3::{SchemaKind, StringFormat, StringType, Type, VariantOrUnknownOrEmpty};
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())))
}
fn accepted_types() -> Option<Vec<Mime>>
{
Some(vec![STAR_STAR])
}
#[cfg(feature = "openapi")]
fn schema() -> OpenapiSchema
{
@ -315,6 +320,11 @@ where
}
}
fn accepted_types() -> Option<Vec<Mime>>
{
<Raw<T> as ResourceResult>::accepted_types()
}
#[cfg(feature = "openapi")]
fn schema() -> OpenapiSchema
{