Fix build warnings from tests
Deriving `Debug` is no longer enough to suppress warnings about unused fields
This commit is contained in:
parent
29d2455bb3
commit
043d794e39
30 changed files with 188 additions and 136 deletions
|
@ -3,7 +3,8 @@ use chrono::prelude::*;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct ChronoTypes {
|
||||
weekday: Weekday,
|
||||
date_time: DateTime<Utc>,
|
||||
|
|
|
@ -5,9 +5,10 @@ use util::*;
|
|||
#[allow(unused_imports)]
|
||||
use std as schemars;
|
||||
|
||||
#[derive(Debug, not_schemars::JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(not_schemars::JsonSchema)]
|
||||
#[schemars(crate = "not_schemars")]
|
||||
pub struct Struct {
|
||||
struct Struct {
|
||||
/// This is a document
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
|
|
|
@ -24,41 +24,44 @@ where
|
|||
ser.collect_str(&format_args!("i:{} b:{}", value.my_int, value.my_bool))
|
||||
}
|
||||
|
||||
#[derive(Default, JsonSchema, Debug)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(Default, JsonSchema)]
|
||||
#[serde(default)]
|
||||
pub struct MyStruct {
|
||||
pub my_int: i32,
|
||||
pub my_bool: bool,
|
||||
struct MyStruct {
|
||||
my_int: i32,
|
||||
my_bool: bool,
|
||||
#[serde(serialize_with = "custom_serialize")]
|
||||
pub my_struct2: MyStruct2,
|
||||
my_struct2: MyStruct2,
|
||||
#[serde(
|
||||
serialize_with = "custom_serialize",
|
||||
skip_serializing_if = "is_default"
|
||||
)]
|
||||
pub my_struct2_default_skipped: MyStruct2,
|
||||
pub not_serialize: NotSerialize,
|
||||
my_struct2_default_skipped: MyStruct2,
|
||||
not_serialize: NotSerialize,
|
||||
}
|
||||
|
||||
#[derive(Default, JsonSchema, Debug, PartialEq)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(Default, JsonSchema, PartialEq)]
|
||||
#[serde(default = "ten_and_true")]
|
||||
pub struct MyStruct2 {
|
||||
struct MyStruct2 {
|
||||
#[serde(default = "six")]
|
||||
pub my_int: i32,
|
||||
pub my_bool: bool,
|
||||
my_int: i32,
|
||||
my_bool: bool,
|
||||
}
|
||||
|
||||
#[derive(Default, JsonSchema, Debug)]
|
||||
pub struct NotSerialize;
|
||||
#[derive(Default, JsonSchema)]
|
||||
struct NotSerialize;
|
||||
|
||||
#[test]
|
||||
fn schema_default_values() -> TestResult {
|
||||
test_default_generated_schema::<MyStruct>("default")
|
||||
}
|
||||
|
||||
#[derive(JsonSchema, Debug)]
|
||||
pub struct StructWithGenericDefaults {
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct StructWithGenericDefaults {
|
||||
#[serde(default = "Vec::new")]
|
||||
pub a_vec: Vec<String>,
|
||||
a_vec: Vec<String>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -4,9 +4,10 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[deprecated]
|
||||
pub struct DeprecatedStruct {
|
||||
struct DeprecatedStruct {
|
||||
foo: i32,
|
||||
#[deprecated]
|
||||
deprecated_field: bool,
|
||||
|
@ -17,9 +18,10 @@ fn deprecated_struct() -> TestResult {
|
|||
test_default_generated_schema::<DeprecatedStruct>("deprecated-struct")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[deprecated]
|
||||
pub enum DeprecatedEnum {
|
||||
enum DeprecatedEnum {
|
||||
Unit,
|
||||
#[deprecated]
|
||||
DeprecatedUnitVariant,
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
use schemars::{gen::SchemaGenerator, JsonSchema};
|
||||
use std::ptr;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Struct {
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Struct {
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::{gen::SchemaSettings, JsonSchema};
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
/**
|
||||
*
|
||||
* # This is the struct's title
|
||||
|
@ -10,24 +11,25 @@ use util::*;
|
|||
* This is the struct's description.
|
||||
*
|
||||
*/
|
||||
pub struct MyStruct {
|
||||
struct MyStruct {
|
||||
/// # An integer
|
||||
pub my_int: i32,
|
||||
pub my_undocumented_bool: bool,
|
||||
my_int: i32,
|
||||
my_undocumented_bool: bool,
|
||||
/// A unit struct instance
|
||||
pub my_unit: MyUnitStruct,
|
||||
my_unit: MyUnitStruct,
|
||||
}
|
||||
|
||||
/// # A Unit
|
||||
///
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct MyUnitStruct;
|
||||
#[derive(JsonSchema)]
|
||||
struct MyUnitStruct;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[doc = " # This is the enum's title "]
|
||||
#[doc = " This is "]
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[doc = " the enum's description."]
|
||||
pub enum MyEnum {
|
||||
enum MyEnum {
|
||||
UndocumentedUnit,
|
||||
/// This comment is not included in the generated schema :(
|
||||
DocumentedUnit,
|
||||
|
@ -69,16 +71,17 @@ fn doc_comments_enum() -> TestResult {
|
|||
|
||||
/// # OverrideDocs struct
|
||||
/// This description should be overridden
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(description = "New description")]
|
||||
pub struct OverrideDocs {
|
||||
struct OverrideDocs {
|
||||
/// # Overridden
|
||||
#[schemars(title = "My integer", description = "This is an i32")]
|
||||
pub my_int: i32,
|
||||
my_int: i32,
|
||||
/// # Overridden
|
||||
/// Also overridden
|
||||
#[schemars(title = "", description = "")]
|
||||
pub my_undocumented_bool: bool,
|
||||
my_undocumented_bool: bool,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -5,18 +5,20 @@ use util::*;
|
|||
// Ensure that schemars_derive uses the full path to std::string::String
|
||||
pub struct String;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct UnitStruct;
|
||||
#[derive(JsonSchema)]
|
||||
struct UnitStruct;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Struct {
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Struct {
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(rename_all = "camelCase")]
|
||||
pub enum External {
|
||||
enum External {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -36,9 +38,10 @@ fn enum_external_tag() -> TestResult {
|
|||
test_default_generated_schema::<External>("enum-external")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "typeProperty")]
|
||||
pub enum Internal {
|
||||
enum Internal {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -57,9 +60,10 @@ fn enum_internal_tag() -> TestResult {
|
|||
test_default_generated_schema::<Internal>("enum-internal")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(untagged)]
|
||||
pub enum Untagged {
|
||||
enum Untagged {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -78,9 +82,10 @@ fn enum_untagged() -> TestResult {
|
|||
test_default_generated_schema::<Untagged>("enum-untagged")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "t", content = "c")]
|
||||
pub enum Adjacent {
|
||||
enum Adjacent {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -100,9 +105,10 @@ fn enum_adjacent_tagged() -> TestResult {
|
|||
test_default_generated_schema::<Adjacent>("enum-adjacent-tagged")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "typeProperty")]
|
||||
pub enum SimpleInternal {
|
||||
enum SimpleInternal {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
|
|
|
@ -5,20 +5,22 @@ use util::*;
|
|||
// Ensure that schemars_derive uses the full path to std::string::String
|
||||
pub struct String;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct UnitStruct;
|
||||
#[derive(JsonSchema)]
|
||||
struct UnitStruct;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Struct {
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Struct {
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
}
|
||||
|
||||
// Outer container should always have additionalProperties: false
|
||||
// `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(rename_all = "camelCase", deny_unknown_fields)]
|
||||
pub enum External {
|
||||
enum External {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -39,9 +41,10 @@ fn enum_external_tag() -> TestResult {
|
|||
}
|
||||
|
||||
// Only `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "typeProperty", deny_unknown_fields)]
|
||||
pub enum Internal {
|
||||
enum Internal {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -61,9 +64,10 @@ fn enum_internal_tag() -> TestResult {
|
|||
}
|
||||
|
||||
// Only `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(untagged, deny_unknown_fields)]
|
||||
pub enum Untagged {
|
||||
enum Untagged {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -83,9 +87,10 @@ fn enum_untagged() -> TestResult {
|
|||
}
|
||||
|
||||
// Outer container and `Struct` variant should have additionalProperties: false
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "t", content = "c", deny_unknown_fields)]
|
||||
pub enum Adjacent {
|
||||
enum Adjacent {
|
||||
UnitOne,
|
||||
StringMap(Map<&'static str, &'static str>),
|
||||
UnitStructNewType(UnitStruct),
|
||||
|
@ -105,9 +110,10 @@ fn enum_adjacent_tagged() -> TestResult {
|
|||
test_default_generated_schema::<Adjacent>("enum-adjacent-tagged-duf")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "typeProperty", deny_unknown_fields)]
|
||||
pub enum SimpleInternal {
|
||||
enum SimpleInternal {
|
||||
A,
|
||||
B,
|
||||
C,
|
||||
|
|
|
@ -3,9 +3,9 @@ use schemars::JsonSchema;
|
|||
use serde::Serialize;
|
||||
use util::*;
|
||||
|
||||
#[derive(Default, Debug, JsonSchema, Serialize)]
|
||||
#[derive(Default, JsonSchema, Serialize)]
|
||||
#[schemars(example = "Struct::default", example = "null")]
|
||||
pub struct Struct {
|
||||
struct Struct {
|
||||
#[schemars(example = "eight", example = "null")]
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
|
|
|
@ -3,7 +3,8 @@ use schemars::JsonSchema;
|
|||
use std::ffi::{OsStr, OsString};
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct OsStrings {
|
||||
owned: OsString,
|
||||
borrowed: &'static OsStr,
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Flat {
|
||||
f: f32,
|
||||
b: bool,
|
||||
|
@ -12,7 +13,8 @@ struct Flat {
|
|||
v: Vec<i32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(rename = "Flat")]
|
||||
struct Deep1 {
|
||||
f: f32,
|
||||
|
@ -21,8 +23,8 @@ struct Deep1 {
|
|||
v: Vec<i32>,
|
||||
}
|
||||
|
||||
#[allow(clippy::option_option)]
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(clippy::option_option, dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Deep2 {
|
||||
b: bool,
|
||||
#[serde(flatten)]
|
||||
|
@ -31,12 +33,14 @@ struct Deep2 {
|
|||
deep4: Box<Option<Option<Box<Deep4>>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Deep3 {
|
||||
s: &'static str,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Deep4 {
|
||||
#[serde(default)]
|
||||
os: &'static str,
|
||||
|
|
|
@ -3,7 +3,8 @@ use indexmap::{IndexMap, IndexSet};
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct IndexMapTypes {
|
||||
map: IndexMap<i32, bool>,
|
||||
set: IndexSet<isize>,
|
||||
|
|
|
@ -3,14 +3,16 @@ use schemars::gen::SchemaSettings;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct MyJob {
|
||||
pub spec: MyJobSpec,
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyJob {
|
||||
spec: MyJobSpec,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct MyJobSpec {
|
||||
pub replicas: u32,
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyJobSpec {
|
||||
replicas: u32,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -20,15 +22,17 @@ fn struct_normal() -> TestResult {
|
|||
test_generated_schema::<MyJob>("inline-subschemas", settings)
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct RecursiveOuter {
|
||||
pub direct: Option<Box<RecursiveOuter>>,
|
||||
pub indirect: Option<Box<RecursiveInner>>,
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct RecursiveOuter {
|
||||
direct: Option<Box<RecursiveOuter>>,
|
||||
indirect: Option<Box<RecursiveInner>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct RecursiveInner {
|
||||
pub recursive: RecursiveOuter,
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct RecursiveInner {
|
||||
recursive: RecursiveOuter,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -6,7 +6,8 @@ macro_rules! build_struct {
|
|||
(
|
||||
$id:ident { $($t:tt)* }
|
||||
) => {
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct $id {
|
||||
x: u8,
|
||||
$($t)*
|
||||
|
@ -53,9 +54,9 @@ macro_rules! build_enum {
|
|||
}
|
||||
|
||||
build_enum!(
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
OuterEnum {
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
InnerStruct {
|
||||
x: i32
|
||||
}
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyStruct {
|
||||
unsigned: u32,
|
||||
nonzero_unsigned: std::num::NonZeroU32,
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct MyStruct {
|
||||
camel_case: i32,
|
||||
|
|
|
@ -3,7 +3,8 @@ use schemars::JsonSchema;
|
|||
use std::ops::{Bound, Range, RangeInclusive};
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyStruct {
|
||||
range: Range<usize>,
|
||||
inclusive: RangeInclusive<f64>,
|
||||
|
|
|
@ -6,14 +6,14 @@ use serde::Serialize;
|
|||
use util::*;
|
||||
|
||||
mod other_crate {
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Default)]
|
||||
pub struct Duration {
|
||||
pub secs: i64,
|
||||
pub nanos: i32,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema, Serialize)]
|
||||
#[derive(JsonSchema, Serialize)]
|
||||
#[serde(remote = "Duration")]
|
||||
struct DurationDef {
|
||||
secs: i64,
|
||||
|
@ -27,7 +27,7 @@ where
|
|||
ser.collect_str(&format_args!("{}.{:09}s", value.secs, value.nanos))
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema, Serialize)]
|
||||
#[derive(JsonSchema, Serialize)]
|
||||
struct Process {
|
||||
command_line: String,
|
||||
#[serde(with = "DurationDef")]
|
||||
|
|
|
@ -5,10 +5,9 @@ use serde::Serialize;
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use util::*;
|
||||
|
||||
#[allow(dead_code)]
|
||||
enum Or<A, B> {
|
||||
#[allow(dead_code)]
|
||||
A(A),
|
||||
#[allow(dead_code)]
|
||||
B(B),
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,14 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyStruct {
|
||||
foo: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Container {
|
||||
result1: Result<MyStruct, Vec<String>>,
|
||||
result2: Result<bool, ()>,
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyStruct<T, U, V, W> {
|
||||
t: T,
|
||||
u: U,
|
||||
|
@ -11,7 +12,8 @@ struct MyStruct<T, U, V, W> {
|
|||
inner: MySimpleStruct,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MySimpleStruct {
|
||||
foo: i32,
|
||||
}
|
||||
|
@ -21,7 +23,8 @@ fn default_name_multiple_type_params() -> TestResult {
|
|||
test_default_generated_schema::<MyStruct<i32, (), bool, Vec<String>>>("schema-name-default")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(rename = "a-new-name-{W}-{T}-{T}")]
|
||||
#[schemars(rename_all = "camelCase")]
|
||||
struct MyRenamedStruct<T, U, V, W> {
|
||||
|
@ -32,7 +35,8 @@ struct MyRenamedStruct<T, U, V, W> {
|
|||
inner: MySimpleRenamedStruct,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(rename = "this-attribute-is-ignored")]
|
||||
#[schemars(rename = "another-new-name")]
|
||||
struct MySimpleRenamedStruct {
|
||||
|
|
|
@ -9,7 +9,7 @@ fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Sche
|
|||
#[derive(Debug)]
|
||||
pub struct DoesntImplementJsonSchema;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(rename_all = "camelCase")]
|
||||
pub enum External {
|
||||
Struct {
|
||||
|
@ -30,7 +30,7 @@ fn enum_external_tag() -> TestResult {
|
|||
test_default_generated_schema::<External>("schema_with-enum-external")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "typeProperty")]
|
||||
pub enum Internal {
|
||||
Struct {
|
||||
|
@ -47,7 +47,7 @@ fn enum_internal_tag() -> TestResult {
|
|||
test_default_generated_schema::<Internal>("schema_with-enum-internal")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(untagged)]
|
||||
pub enum Untagged {
|
||||
Struct {
|
||||
|
@ -68,7 +68,7 @@ fn enum_untagged() -> TestResult {
|
|||
test_default_generated_schema::<Untagged>("schema_with-enum-untagged")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(tag = "t", content = "c")]
|
||||
pub enum Adjacent {
|
||||
Struct {
|
||||
|
|
|
@ -6,11 +6,11 @@ fn schema_fn(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Sche
|
|||
<bool>::json_schema(gen)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct DoesntImplementJsonSchema;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Struct {
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Struct {
|
||||
#[schemars(schema_with = "schema_fn")]
|
||||
foo: DoesntImplementJsonSchema,
|
||||
bar: i32,
|
||||
|
@ -23,7 +23,7 @@ fn struct_normal() -> TestResult {
|
|||
test_default_generated_schema::<Struct>("schema_with-struct")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Tuple(
|
||||
#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema,
|
||||
i32,
|
||||
|
@ -35,7 +35,7 @@ fn struct_tuple() -> TestResult {
|
|||
test_default_generated_schema::<Tuple>("schema_with-tuple")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Newtype(#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema);
|
||||
|
||||
#[test]
|
||||
|
@ -43,7 +43,7 @@ fn struct_newtype() -> TestResult {
|
|||
test_default_generated_schema::<Newtype>("schema_with-newtype")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(transparent)]
|
||||
pub struct TransparentNewtype(#[schemars(schema_with = "schema_fn")] DoesntImplementJsonSchema);
|
||||
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyStruct {
|
||||
#[schemars(skip)]
|
||||
skipped1: i32,
|
||||
|
@ -20,7 +21,7 @@ fn skip_struct_fields() -> TestResult {
|
|||
test_default_generated_schema::<MyStruct>("skip_struct_fields")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
struct TupleStruct(
|
||||
#[schemars(skip)] i32,
|
||||
#[serde(skip)] bool,
|
||||
|
@ -34,7 +35,7 @@ fn skip_tuple_fields() -> TestResult {
|
|||
test_default_generated_schema::<TupleStruct>("skip_tuple_fields")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub enum MyEnum {
|
||||
#[schemars(skip)]
|
||||
Skipped1(i32),
|
||||
|
|
|
@ -5,8 +5,9 @@ use util::*;
|
|||
// Ensure that schemars_derive uses the full path to std::string::String
|
||||
pub struct String;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
pub struct Struct {
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct Struct {
|
||||
foo: i32,
|
||||
bar: bool,
|
||||
baz: Option<&'static str>,
|
||||
|
@ -17,7 +18,7 @@ fn struct_normal() -> TestResult {
|
|||
test_default_generated_schema::<Struct>("struct-normal")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Tuple(i32, bool, Option<&'static str>);
|
||||
|
||||
#[test]
|
||||
|
@ -25,7 +26,7 @@ fn struct_tuple() -> TestResult {
|
|||
test_default_generated_schema::<Tuple>("struct-tuple")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Newtype(i32);
|
||||
|
||||
#[test]
|
||||
|
@ -33,7 +34,7 @@ fn struct_newtype() -> TestResult {
|
|||
test_default_generated_schema::<Newtype>("struct-newtype")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Unit;
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -2,7 +2,8 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub struct Struct {
|
||||
foo: i32,
|
||||
|
|
|
@ -3,7 +3,8 @@ use schemars::JsonSchema;
|
|||
use std::time::{Duration, SystemTime};
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct MyStruct {
|
||||
duration: Duration,
|
||||
time: SystemTime,
|
||||
|
|
|
@ -2,23 +2,25 @@ mod util;
|
|||
use schemars::JsonSchema;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct OuterStruct {
|
||||
inner: TransparentStruct,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
#[serde(transparent)]
|
||||
pub struct TransparentStruct {
|
||||
#[serde(with = "TransparentNewType")]
|
||||
inner: (),
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
#[schemars(transparent)]
|
||||
pub struct TransparentNewType(Option<InnerStruct>);
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct InnerStruct(String, i32);
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -3,7 +3,8 @@ use schemars::JsonSchema;
|
|||
use url::Url;
|
||||
use util::*;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
struct UrlTypes {
|
||||
url: Url,
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ static STARTS_WITH_HELLO: &'static str = r"^[Hh]ello\b";
|
|||
const MIN: u32 = 1;
|
||||
const MAX: u32 = 1000;
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct {
|
||||
#[validate(range(min = 0.01, max = 100))]
|
||||
min_max: f32,
|
||||
|
@ -47,7 +48,8 @@ pub struct Struct {
|
|||
required_flattened: Option<Inner>,
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Inner {
|
||||
x: i32,
|
||||
}
|
||||
|
@ -57,7 +59,8 @@ fn validate() -> TestResult {
|
|||
test_default_generated_schema::<Struct>("validate")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[allow(dead_code)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Struct2 {
|
||||
#[schemars(range(min = 0.01, max = 100))]
|
||||
min_max: f32,
|
||||
|
@ -101,7 +104,7 @@ fn validate_schemars_attrs() -> TestResult {
|
|||
test_default_generated_schema::<Struct>("validate_schemars_attrs")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct Tuple(
|
||||
#[validate(range(max = 10))] u8,
|
||||
#[validate(required)] Option<bool>,
|
||||
|
@ -112,7 +115,7 @@ fn validate_tuple() -> TestResult {
|
|||
test_default_generated_schema::<Tuple>("validate_tuple")
|
||||
}
|
||||
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[derive(JsonSchema)]
|
||||
pub struct NewType(#[validate(range(max = 10))] u8);
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue