1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-05-09 16:10:42 +00:00

copy OpenapiType implementations and fix codegen reference

This commit is contained in:
Dominic 2021-03-08 16:33:38 +01:00
parent d9c7f4135f
commit 667009bd22
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
7 changed files with 388 additions and 17 deletions

View file

@ -0,0 +1,44 @@
#![allow(dead_code)]
use openapi_type::OpenapiType;
macro_rules! test_type {
($ty:ty = $json:tt) => {
paste::paste! {
#[test]
fn [< $ty:lower >]() {
let schema = <$ty as OpenapiType>::schema();
let schema = openapi_type::OpenapiSchema::into_schema(schema);
let schema_json = serde_json::to_value(&schema).unwrap();
let expected = serde_json::json!($json);
assert_eq!(schema_json, expected);
}
}
};
}
#[derive(OpenapiType)]
struct UnitStruct;
test_type!(UnitStruct = {
"type": "object",
"title": "UnitStruct",
"additionalProperties": false
});
#[derive(OpenapiType)]
struct SimpleStruct {
foo: String,
bar: isize
}
test_type!(SimpleStruct = {
"type": "object",
"title": "SimpleStruct",
"properties": {
"foo": {
"type": "string"
},
"bar": {
"type": "integer"
}
},
"required": ["foo", "bar"]
});