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:
parent
d9c7f4135f
commit
667009bd22
7 changed files with 388 additions and 17 deletions
44
openapi_type/tests/custom_types.rs
Normal file
44
openapi_type/tests/custom_types.rs
Normal 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"]
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue