File: doc_comments.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 (34 lines) | stat: -rw-r--r-- 875 bytes parent folder | download
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
#![cfg(feature = "derive")]
use schemars::{schema_for, JsonSchema};

/// # My Amazing Struct
/// This struct shows off generating a schema with
/// a custom title and description.
#[derive(JsonSchema)]
pub struct MyStruct {
    /// # My Amazing Integer
    pub my_int: i32,
    /// This bool has a description, but no title.
    pub my_bool: bool,
    /// # A Nullable Enum
    /// This enum might be set, or it might not.
    pub my_nullable_enum: Option<MyEnum>,
}

/// # My Amazing Enum
#[derive(JsonSchema)]
pub enum MyEnum {
    /// A wrapper around a `String`
    StringNewType(String),
    /// A struct-like enum variant which contains
    /// some floats
    StructVariant {
        /// The floats themselves
        floats: Vec<f32>,
    },
}

fn main() {
    let schema = schema_for!(MyStruct);
    println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}