From 6bebd73701df8f9c11df8273e02501978739a354 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Sun, 29 Dec 2019 22:30:17 +0000 Subject: [PATCH] Add test for allow_ref_siblings behaviour --- schemars/tests/docs.rs | 8 ++++- .../doc_comments_struct_ref_siblings.json | 31 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 schemars/tests/expected/doc_comments_struct_ref_siblings.json diff --git a/schemars/tests/docs.rs b/schemars/tests/docs.rs index bcbb513..bdae83a 100644 --- a/schemars/tests/docs.rs +++ b/schemars/tests/docs.rs @@ -1,5 +1,5 @@ mod util; -use schemars::JsonSchema; +use schemars::{gen::SchemaSettings, JsonSchema}; use util::*; #[derive(Debug, JsonSchema)] @@ -56,6 +56,12 @@ fn doc_comments_struct() -> TestResult { test_default_generated_schema::("doc_comments_struct") } +#[test] +fn doc_comments_struct_ref_siblings() -> TestResult { + let settings = SchemaSettings::draft07().with(|s| s.allow_ref_siblings = true); + test_generated_schema::("doc_comments_struct_ref_siblings", settings) +} + #[test] fn doc_comments_enum() -> TestResult { test_default_generated_schema::("doc_comments_enum") diff --git a/schemars/tests/expected/doc_comments_struct_ref_siblings.json b/schemars/tests/expected/doc_comments_struct_ref_siblings.json new file mode 100644 index 0000000..c215d43 --- /dev/null +++ b/schemars/tests/expected/doc_comments_struct_ref_siblings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "This is the struct's title", + "description": "This is the struct's description.", + "type": "object", + "required": [ + "my_int", + "my_undocumented_bool", + "my_unit" + ], + "properties": { + "my_int": { + "title": "An integer", + "type": "integer", + "format": "int32" + }, + "my_undocumented_bool": { + "type": "boolean" + }, + "my_unit": { + "description": "A unit struct instance", + "$ref": "#/definitions/MyUnitStruct" + } + }, + "definitions": { + "MyUnitStruct": { + "title": "A Unit", + "type": "null" + } + } +} \ No newline at end of file