Change generates_ref_schema default to true
This commit is contained in:
parent
354c3aa98f
commit
cbbc883038
1 changed files with 28 additions and 5 deletions
|
@ -21,14 +21,20 @@ pub trait MakeSchema {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generates_ref_schema() -> bool {
|
fn generates_ref_schema() -> bool {
|
||||||
// TODO default this to true as it's safer
|
true
|
||||||
// But this would mean every impl in this file needs to override it :(
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_schema(gen: &mut SchemaGenerator) -> Schema;
|
fn make_schema(gen: &mut SchemaGenerator) -> Schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! no_ref_schema {
|
||||||
|
() => {
|
||||||
|
fn generates_ref_schema() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
// TODO structs, enums, tuples
|
// TODO structs, enums, tuples
|
||||||
|
|
||||||
// TODO any other serde types other than serde_json value?
|
// TODO any other serde types other than serde_json value?
|
||||||
|
@ -44,6 +50,8 @@ pub trait MakeSchema {
|
||||||
macro_rules! simple_impl {
|
macro_rules! simple_impl {
|
||||||
($type:tt => $instance_type:tt) => {
|
($type:tt => $instance_type:tt) => {
|
||||||
impl MakeSchema for $type {
|
impl MakeSchema for $type {
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
||||||
SchemaObject {
|
SchemaObject {
|
||||||
instance_type: Some(InstanceType::$instance_type.into()),
|
instance_type: Some(InstanceType::$instance_type.into()),
|
||||||
|
@ -75,6 +83,8 @@ simple_impl!(usize => Integer);
|
||||||
simple_impl!(() => Null);
|
simple_impl!(() => Null);
|
||||||
|
|
||||||
impl MakeSchema for char {
|
impl MakeSchema for char {
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
||||||
let mut extensions = Map::new();
|
let mut extensions = Map::new();
|
||||||
extensions.insert("minLength".to_owned(), json!(1));
|
extensions.insert("minLength".to_owned(), json!(1));
|
||||||
|
@ -92,6 +102,8 @@ impl MakeSchema for char {
|
||||||
|
|
||||||
// Does not require T: MakeSchema.
|
// Does not require T: MakeSchema.
|
||||||
impl<T> MakeSchema for [T; 0] {
|
impl<T> MakeSchema for [T; 0] {
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
||||||
let mut extensions = Map::new();
|
let mut extensions = Map::new();
|
||||||
extensions.insert("maxItems".to_owned(), json!(0));
|
extensions.insert("maxItems".to_owned(), json!(0));
|
||||||
|
@ -107,8 +119,9 @@ impl<T> MakeSchema for [T; 0] {
|
||||||
macro_rules! array_impls {
|
macro_rules! array_impls {
|
||||||
($($len:tt)+) => {
|
($($len:tt)+) => {
|
||||||
$(
|
$(
|
||||||
impl<T: MakeSchema> MakeSchema for [T; $len]
|
impl<T: MakeSchema> MakeSchema for [T; $len] {
|
||||||
{
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(gen: &mut SchemaGenerator) -> Schema {
|
fn make_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||||
let mut extensions = Map::new();
|
let mut extensions = Map::new();
|
||||||
extensions.insert("minItems".to_owned(), json!($len));
|
extensions.insert("minItems".to_owned(), json!($len));
|
||||||
|
@ -140,6 +153,8 @@ macro_rules! seq_impl {
|
||||||
where
|
where
|
||||||
T: MakeSchema,
|
T: MakeSchema,
|
||||||
{
|
{
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(gen: &mut SchemaGenerator) -> Schema
|
fn make_schema(gen: &mut SchemaGenerator) -> Schema
|
||||||
{
|
{
|
||||||
SchemaObject {
|
SchemaObject {
|
||||||
|
@ -168,6 +183,8 @@ macro_rules! map_impl {
|
||||||
K: Into<String>,
|
K: Into<String>,
|
||||||
T: MakeSchema,
|
T: MakeSchema,
|
||||||
{
|
{
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(gen: &mut SchemaGenerator) -> Schema
|
fn make_schema(gen: &mut SchemaGenerator) -> Schema
|
||||||
{
|
{
|
||||||
let mut extensions = Map::new();
|
let mut extensions = Map::new();
|
||||||
|
@ -191,6 +208,8 @@ map_impl!(<K, T: Eq + core::hash::Hash, H: core::hash::BuildHasher> MakeSchema f
|
||||||
////////// OPTION //////////
|
////////// OPTION //////////
|
||||||
|
|
||||||
impl<T: MakeSchema> MakeSchema for Option<T> {
|
impl<T: MakeSchema> MakeSchema for Option<T> {
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(gen: &mut SchemaGenerator) -> Schema {
|
fn make_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||||
match gen.subschema_for::<T>() {
|
match gen.subschema_for::<T>() {
|
||||||
Schema::Bool(true) => true.into(),
|
Schema::Bool(true) => true.into(),
|
||||||
|
@ -212,6 +231,8 @@ macro_rules! deref_impl {
|
||||||
where
|
where
|
||||||
T: MakeSchema,
|
T: MakeSchema,
|
||||||
{
|
{
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(gen: &mut SchemaGenerator) -> Schema {
|
fn make_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||||
gen.subschema_for::<T>()
|
gen.subschema_for::<T>()
|
||||||
}
|
}
|
||||||
|
@ -229,6 +250,8 @@ deref_impl!(<'a, T: ToOwned> MakeSchema for std::borrow::Cow<'a, T>);
|
||||||
////////// SERDE_JSON //////////
|
////////// SERDE_JSON //////////
|
||||||
|
|
||||||
impl MakeSchema for serde_json::Value {
|
impl MakeSchema for serde_json::Value {
|
||||||
|
no_ref_schema!();
|
||||||
|
|
||||||
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
fn make_schema(_: &mut SchemaGenerator) -> Schema {
|
||||||
true.into()
|
true.into()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue