predawn_schema/
schemars_transform.rs

1use bytes::{BufMut, BytesMut};
2use openapiv3::Schema;
3use schemars::{schema::RootSchema, schema_for, JsonSchema};
4
5pub fn schemars_transform<T: ?Sized + JsonSchema>() -> Result<Schema, serde_json::Error> {
6    fn inner_transform(schema: RootSchema) -> Result<Schema, serde_json::Error> {
7        let mut buf = BytesMut::with_capacity(128).writer();
8        serde_json::to_writer(&mut buf, &schema)?;
9        serde_json::from_slice(&buf.into_inner())
10    }
11
12    inner_transform(schema_for!(T))
13}