From fc592e5dd7c40fca93abb34b016c893958afe750 Mon Sep 17 00:00:00 2001 From: Graham Esau Date: Mon, 16 Dec 2019 21:36:20 +0000 Subject: [PATCH] Ensure root schemas do not have a $ref property. If necessary, wrap the `$ref` in an `allOf`. --- schemars/src/gen.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/schemars/src/gen.rs b/schemars/src/gen.rs index 4f2d301..d0faf02 100644 --- a/schemars/src/gen.rs +++ b/schemars/src/gen.rs @@ -231,7 +231,8 @@ impl SchemaGenerator { /// add them to the `SchemaGenerator`'s schema definitions and include them in the returned `SchemaObject`'s /// [`definitions`](../schema/struct.Metadata.html#structfield.definitions) pub fn root_schema_for(&mut self) -> RootSchema { - let mut schema: SchemaObject = T::json_schema(self).into(); + let schema = T::json_schema(self); + let mut schema: SchemaObject = self.make_extensible(schema.into()); schema.metadata().title.get_or_insert_with(T::schema_name); RootSchema { meta_schema: self.settings.meta_schema.clone(), @@ -245,7 +246,8 @@ impl SchemaGenerator { /// If `T`'s schema depends on any [referenceable](JsonSchema::is_referenceable) schemas, then this method will /// include them in the returned `SchemaObject`'s [`definitions`](../schema/struct.Metadata.html#structfield.definitions) pub fn into_root_schema_for(mut self) -> RootSchema { - let mut schema: SchemaObject = T::json_schema(&mut self).into(); + let schema = T::json_schema(&mut self); + let mut schema: SchemaObject = self.make_extensible(schema.into()); schema.metadata().title.get_or_insert_with(T::schema_name); RootSchema { meta_schema: self.settings.meta_schema,