Ensure root schemas do not have a $ref property.

If necessary, wrap the `$ref` in an `allOf`.
This commit is contained in:
Graham Esau 2019-12-16 21:36:20 +00:00
parent d7c010d9c2
commit fc592e5dd7

View file

@ -231,7 +231,8 @@ impl SchemaGenerator {
/// add them to the `SchemaGenerator`'s schema definitions and include them in the returned `SchemaObject`'s /// add them to the `SchemaGenerator`'s schema definitions and include them in the returned `SchemaObject`'s
/// [`definitions`](../schema/struct.Metadata.html#structfield.definitions) /// [`definitions`](../schema/struct.Metadata.html#structfield.definitions)
pub fn root_schema_for<T: ?Sized + JsonSchema>(&mut self) -> RootSchema { pub fn root_schema_for<T: ?Sized + JsonSchema>(&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); schema.metadata().title.get_or_insert_with(T::schema_name);
RootSchema { RootSchema {
meta_schema: self.settings.meta_schema.clone(), 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 /// 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) /// include them in the returned `SchemaObject`'s [`definitions`](../schema/struct.Metadata.html#structfield.definitions)
pub fn into_root_schema_for<T: ?Sized + JsonSchema>(mut self) -> RootSchema { pub fn into_root_schema_for<T: ?Sized + JsonSchema>(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); schema.metadata().title.get_or_insert_with(T::schema_name);
RootSchema { RootSchema {
meta_schema: self.settings.meta_schema, meta_schema: self.settings.meta_schema,