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
|
#![cfg(feature = "derive")]
mod util;
use schemars::gen::SchemaSettings;
use schemars::JsonSchema;
use serde_json::Value;
use std::collections::BTreeMap;
use util::*;
#[derive(JsonSchema)]
pub struct Outer {
#[schemars(example = "eight", example = "null")]
pub int: i32,
pub values: BTreeMap<&'static str, Value>,
pub value: Value,
pub inner: Option<Inner>,
}
#[derive(JsonSchema)]
pub enum Inner {
UndocumentedUnit1,
UndocumentedUnit2,
/// This is a documented unit variant
DocumentedUnit,
ValueNewType(Value),
}
fn eight() -> i32 {
8
}
fn null() {}
#[test]
fn schema_matches_draft07() -> TestResult {
test_generated_schema::<Outer>("schema_settings", SchemaSettings::draft07())
}
#[test]
fn schema_matches_2019_09() -> TestResult {
test_generated_schema::<Outer>("schema_settings-2019_09", SchemaSettings::draft2019_09())
}
#[test]
#[ignore = "Fails due to default/empty `Metadata` not being considered equal to `Option::None`, although they're conceptually the same and serialize to identical JSON"]
fn schema_matches_openapi3() -> TestResult {
test_generated_schema::<Outer>("schema_settings-openapi3", SchemaSettings::openapi3())
}
|