File: schema_name.rs

package info (click to toggle)
rust-schemars 0.8.22-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,312 kB
  • sloc: makefile: 2
file content (77 lines) | stat: -rw-r--r-- 1,727 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
mod util;
use schemars::JsonSchema;
use util::*;

#[allow(dead_code)]
#[derive(JsonSchema)]
struct MyStruct<T, U, V, W> {
    t: T,
    u: U,
    v: V,
    w: W,
    inner: MySimpleStruct,
}

#[allow(dead_code)]
#[derive(JsonSchema)]
struct MySimpleStruct {
    foo: i32,
}

#[test]
fn default_name_multiple_type_params() -> TestResult {
    test_default_generated_schema::<MyStruct<i32, (), bool, Vec<String>>>("schema-name-default")
}

#[allow(dead_code)]
#[derive(JsonSchema)]
#[serde(rename = "a-new-name-{W}-{T}-{T}")]
#[schemars(rename_all = "camelCase")]
struct MyRenamedStruct<T, U, V, W> {
    t: T,
    u: U,
    v: V,
    w: W,
    inner: MySimpleRenamedStruct,
}

#[allow(dead_code)]
#[derive(JsonSchema)]
#[serde(rename = "this-attribute-is-ignored")]
#[schemars(rename = "another-new-name")]
struct MySimpleRenamedStruct {
    foo: i32,
}

#[test]
fn overriden_with_rename_multiple_type_params() -> TestResult {
    test_default_generated_schema::<MyRenamedStruct<i32, (), bool, Vec<String>>>(
        "schema-name-custom",
    )
}

#[allow(dead_code)]
#[derive(JsonSchema)]
#[schemars(rename = "const-generics-{BAR}-")]
struct ConstGenericStruct<const FOO: usize, const BAR: char> {
    foo: i32,
}

#[test]
fn overriden_with_rename_const_generics() -> TestResult {
    test_default_generated_schema::<ConstGenericStruct<42, 'z'>>("schema-name-const-generics")
}

#[allow(dead_code)]
#[derive(JsonSchema)]
struct MixedGenericStruct<T, const FOO: usize, const BAR: char> {
    generic: T,
    foo: i32,
}

#[test]
fn default_name_mixed_generics() -> TestResult {
    test_default_generated_schema::<MixedGenericStruct<MyStruct<i32, (), bool, Vec<String>>, 42, 'z'>>(
        "schema-name-mixed-generics",
    )
}