Repository: GREsau/schemars
Pull request #398 (2025-05-24 15:33:40)

Rename `always_inline_schema()` to `inline_schema()`
Related to https://github.com/GREsau/schemars/pull/380


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5373ec9..12f0e44 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -159,7 +159,7 @@
 - The default `SchemaSettings` (used by the `schema_for!()`/`schema_for_value!()` macros and `SchemaGenerator::default()`) now conform to JSON Schema draft 2020-12 instead of draft 7.
 - Schemas generated using `SchemaSettings::draft2019_09()` (and `draft2020_12()` and `default()`) now use `$defs` instead of `definitions`. While using `definitions` is allowed by the spec, `$defs` is the preferred property for storing reusable schemas.
 - `JsonSchema::schema_name()` now returns `Cow<'static, str>` instead of `String`
-- `JsonSchema::is_referenceable()` has been removed, and replaced with the more clearly-named `JsonSchema::always_inline()` (which should returns the **opposite** value to what `is_referenceable` returned!)
+- `JsonSchema::is_referenceable()` has been removed, and replaced with the more clearly-named `JsonSchema::always_inline_schema()` (which should returns the **opposite** value to what `is_referenceable` returned!)
 - The `SchemaGenerator.definitions` field is now a `serde_json::Map<String, Value>`
 - Macros/functions that previously returned a `RootSchema` now return a `Schema` instead
 - All optional dependencies are now suffixed by their version:
diff --git a/docs/2-implementing.md b/docs/2-implementing.md
index 06dfa0e..15d31b1 100644
--- a/docs/2-implementing.md
+++ b/docs/2-implementing.md
@@ -67,10 +67,10 @@ This function creates the JSON schema itself. The `generator` argument can be us
 
 `json_schema` should not return a `$ref` schema.
 
-## always_inline_schema (optional)
+## inline_schema (optional)
 
 ```rust
-fn always_inline_schema() -> bool;
+fn inline_schema() -> bool;
 ```
 
 If this function returns `false`, then Schemars can re-use the generate schema where possible by adding it to the root schema's `$defs` and having other schemas reference it using the `$ref` keyword. This can greatly simplify schemas that include a particular type multiple times, especially if that type's schema is fairly complex.
diff --git a/docs/_includes/attributes.md b/docs/_includes/attributes.md
index 0d23efd..406ae80 100644
--- a/docs/_includes/attributes.md
+++ b/docs/_includes/attributes.md
@@ -323,7 +323,7 @@ Set the Rust built-in [`deprecated`](https://doc.rust-lang.org/edition-guide/rus
 
 </h3>
 
-Set the return value of [`always_inline_schema`](trait.JsonSchema.html#method.always_inline_schema) to `true` to include JSON schemas generated for this type directly in parent schemas, rather than being re-used where possible using the `$ref` keyword.
+Set the return value of [`inline_schema`](trait.JsonSchema.html#method.inline_schema) to `true` to include JSON schemas generated for this type directly in parent schemas, rather than being re-used where possible using the `$ref` keyword.
 
 <h3 id="crate">
 
diff --git a/schemars/src/_private/mod.rs b/schemars/src/_private/mod.rs
index baf90f9..b2262ca 100644
--- a/schemars/src/_private/mod.rs
+++ b/schemars/src/_private/mod.rs
@@ -31,7 +31,7 @@ pub fn json_schema_for_internally_tagged_enum_newtype_variant<T: ?Sized + JsonSc
     let mut transform = AllowUnknownProperties::default();
     transform_immediate_subschemas(&mut transform, &mut schema);
 
-    if T::always_inline_schema()
+    if T::inline_schema()
         || generator.settings().inline_subschemas
         || schema.get("type").and_then(Value::as_str) == Some("null")
         || schema.get("additionalProperties").and_then(Value::as_bool) == Some(false)
diff --git a/schemars/src/generate.rs b/schemars/src/generate.rs
index 498d3b4..9803703 100644
--- a/schemars/src/generate.rs
+++ b/schemars/src/generate.rs
@@ -277,15 +277,15 @@ impl SchemaGenerator {
     /// Generates a JSON Schema for the type `T`, and returns either the schema itself or a `$ref`
     /// schema referencing `T`'s schema.
     ///
-    /// If `T` is not [inlined](JsonSchema::always_inline_schema), this will add `T`'s schema to
+    /// If `T` is not [inlined](JsonSchema::inline_schema), this will add `T`'s schema to
     /// this generator's definitions, and return a `$ref` schema referencing that schema.
     /// Otherwise, this method behaves identically to [`JsonSchema::json_schema`].
     ///
-    /// If `T`'s schema depends on any [non-inlined](JsonSchema::always_inline_schema) schemas, then
+    /// If `T`'s schema depends on any [non-inlined](JsonSchema::inline_schema) schemas, then
     /// this method will add them to the `SchemaGenerator`'s schema definitions.
     pub fn subschema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
         let uid = self.schema_uid::<T>();
-        let return_ref = !T::always_inline_schema()
+        let return_ref = !T::inline_schema()
             && (!self.settings.inline_subschemas || self.pending_schema_ids.contains(&uid));
 
         if return_ref {
@@ -335,7 +335,7 @@ impl SchemaGenerator {
         self.definitions.insert(name.into(), schema.to_value());
     }
 
-    /// Borrows the collection of all [non-inlined](JsonSchema::always_inline_schema) schemas that
+    /// Borrows the collection of all [non-inlined](JsonSchema::inline_schema) schemas that
     /// have been generated.
     ///
     /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the
@@ -344,7 +344,7 @@ impl SchemaGenerator {
         &self.definitions
     }
 
-    /// Mutably borrows the collection of all [non-inlined](JsonSchema::always_inline_schema)
+    /// Mutably borrows the collection of all [non-inlined](JsonSchema::inline_schema)
     /// schemas that have been generated.
     ///
     /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the
@@ -353,7 +353,7 @@ impl SchemaGenerator {
         &mut self.definitions
     }
 
-    /// Returns the collection of all [non-inlined](JsonSchema::always_inline_schema) schemas that
+    /// Returns the collection of all [non-inlined](JsonSchema::inline_schema) schemas that
     /// have been generated, leaving an empty `Map` in its place.
     ///
     /// The keys of the returned `Map` are the [schema names](JsonSchema::schema_name), and the
@@ -370,7 +370,7 @@ impl SchemaGenerator {
 
     /// Generates a JSON Schema for the type `T`.
     ///
-    /// If `T`'s schema depends on any [non-inlined](JsonSchema::always_inline_schema) schemas, then
+    /// If `T`'s schema depends on any [non-inlined](JsonSchema::inline_schema) schemas, then
     /// this method will include them in the returned `Schema` at the [definitions
     /// path](SchemaSettings::definitions_path) (by default `"$defs"`).
     pub fn root_schema_for<T: ?Sized + JsonSchema>(&mut self) -> Schema {
@@ -394,7 +394,7 @@ impl SchemaGenerator {
 
     /// Consumes `self` and generates a JSON Schema for the type `T`.
     ///
-    /// If `T`'s schema depends on any [non-inlined](JsonSchema::always_inline_schema) schemas, then
+    /// If `T`'s schema depends on any [non-inlined](JsonSchema::inline_schema) schemas, then
     /// this method will include them in the returned `Schema` at the [definitions
     /// path](SchemaSettings::definitions_path) (by default `"$defs"`).
     pub fn into_root_schema_for<T: ?Sized + JsonSchema>(mut self) -> Schema {
diff --git a/schemars/src/json_schema_impls/array.rs b/schemars/src/json_schema_impls/array.rs
index c17fbba..bd4a0d8 100644
--- a/schemars/src/json_schema_impls/array.rs
+++ b/schemars/src/json_schema_impls/array.rs
@@ -5,7 +5,7 @@ use alloc::borrow::Cow;
 
 // Does not require T: JsonSchema.
 impl<T> JsonSchema for [T; 0] {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "EmptyArray".into()
@@ -27,7 +27,7 @@ macro_rules! array_impls {
     ($($len:tt)+) => {
         $(
             impl<T: JsonSchema> JsonSchema for [T; $len] {
-                always_inline!();
+                inline_schema!();
 
                 fn schema_name() -> Cow<'static, str> {
                     format!("Array_size_{}_of_{}", $len, T::schema_name()).into()
diff --git a/schemars/src/json_schema_impls/arrayvec07.rs b/schemars/src/json_schema_impls/arrayvec07.rs
index 0d7270f..fc72777 100644
--- a/schemars/src/json_schema_impls/arrayvec07.rs
+++ b/schemars/src/json_schema_impls/arrayvec07.rs
@@ -11,7 +11,7 @@ impl<T, const CAP: usize> JsonSchema for ArrayVec<T, CAP>
 where
     T: JsonSchema,
 {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> alloc::borrow::Cow<'static, str> {
         format!("Array_up_to_size_{}_of_{}", CAP, T::schema_name()).into()
diff --git a/schemars/src/json_schema_impls/chrono04.rs b/schemars/src/json_schema_impls/chrono04.rs
index 700af09..f4ab140 100644
--- a/schemars/src/json_schema_impls/chrono04.rs
+++ b/schemars/src/json_schema_impls/chrono04.rs
@@ -4,7 +4,7 @@ use alloc::borrow::Cow;
 use chrono04::prelude::*;
 
 impl JsonSchema for Weekday {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "Weekday".into()
@@ -36,7 +36,7 @@ macro_rules! formatted_string_impl {
     };
     ($ty:ident, $format:literal, $($desc:tt)+) => {
         impl $($desc)+ {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 stringify!($ty).into()
diff --git a/schemars/src/json_schema_impls/core.rs b/schemars/src/json_schema_impls/core.rs
index 489c6f4..68bed2e 100644
--- a/schemars/src/json_schema_impls/core.rs
+++ b/schemars/src/json_schema_impls/core.rs
@@ -6,7 +6,7 @@ use core::ops::{Bound, Range, RangeInclusive};
 use serde_json::Value;
 
 impl<T: JsonSchema> JsonSchema for Option<T> {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         format!("Nullable_{}", T::schema_name()).into()
diff --git a/schemars/src/json_schema_impls/decimal.rs b/schemars/src/json_schema_impls/decimal.rs
index c16ff30..250e3fb 100644
--- a/schemars/src/json_schema_impls/decimal.rs
+++ b/schemars/src/json_schema_impls/decimal.rs
@@ -7,7 +7,7 @@ use serde_json::Value;
 macro_rules! decimal_impl {
     ($type:ty) => {
         impl JsonSchema for $type {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 "Decimal".into()
diff --git a/schemars/src/json_schema_impls/either1.rs b/schemars/src/json_schema_impls/either1.rs
index 2be1684..b275310 100644
--- a/schemars/src/json_schema_impls/either1.rs
+++ b/schemars/src/json_schema_impls/either1.rs
@@ -5,7 +5,7 @@ use alloc::borrow::Cow;
 use either1::Either;
 
 impl<L: JsonSchema, R: JsonSchema> JsonSchema for Either<L, R> {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         format!("Either_{}_or_{}", L::schema_name(), R::schema_name()).into()
diff --git a/schemars/src/json_schema_impls/jiff02.rs b/schemars/src/json_schema_impls/jiff02.rs
index 1b43fbc..b2d6709 100644
--- a/schemars/src/json_schema_impls/jiff02.rs
+++ b/schemars/src/json_schema_impls/jiff02.rs
@@ -9,7 +9,7 @@ macro_rules! formatted_string_impl {
     };
     ($ty:ident, $format:literal, $($desc:tt)+) => {
         impl $($desc)+ {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 stringify!($ty).into()
diff --git a/schemars/src/json_schema_impls/maps.rs b/schemars/src/json_schema_impls/maps.rs
index 86d43c8..9926034 100644
--- a/schemars/src/json_schema_impls/maps.rs
+++ b/schemars/src/json_schema_impls/maps.rs
@@ -8,7 +8,7 @@ macro_rules! map_impl {
         where
             V: JsonSchema,
         {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 format!("Map_of_{}", V::schema_name()).into()
diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs
index 089620b..a5e076c 100644
--- a/schemars/src/json_schema_impls/mod.rs
+++ b/schemars/src/json_schema_impls/mod.rs
@@ -1,6 +1,6 @@
-macro_rules! always_inline {
+macro_rules! inline_schema {
     () => {
-        fn always_inline_schema() -> bool {
+        fn inline_schema() -> bool {
             true
         }
     };
@@ -9,8 +9,8 @@ macro_rules! always_inline {
 macro_rules! forward_impl {
     (($($impl:tt)+) => $target:ty) => {
         impl $($impl)+ {
-            fn always_inline_schema() -> bool {
-                <$target>::always_inline_schema()
+            fn inline_schema() -> bool {
+                <$target>::inline_schema()
             }
 
             fn schema_name() -> alloc::borrow::Cow<'static, str> {
diff --git a/schemars/src/json_schema_impls/nonzero.rs b/schemars/src/json_schema_impls/nonzero.rs
index ede0c58..b60e5de 100644
--- a/schemars/src/json_schema_impls/nonzero.rs
+++ b/schemars/src/json_schema_impls/nonzero.rs
@@ -6,7 +6,7 @@ use core::num::*;
 macro_rules! nonzero_signed_impl {
     ($type:ty => $primitive:ty) => {
         impl JsonSchema for $type {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 stringify!($type).into()
@@ -37,7 +37,7 @@ nonzero_signed_impl!(NonZeroIsize => isize);
 macro_rules! nonzero_unsigned_impl {
     ($type:ty => $primitive:ty) => {
         impl JsonSchema for $type {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 stringify!($type).into()
diff --git a/schemars/src/json_schema_impls/primitives.rs b/schemars/src/json_schema_impls/primitives.rs
index e59bc5d..42a7a39 100644
--- a/schemars/src/json_schema_impls/primitives.rs
+++ b/schemars/src/json_schema_impls/primitives.rs
@@ -6,7 +6,7 @@ use alloc::borrow::Cow;
 macro_rules! simple_impl {
     ($type:ty => $instance_type:literal) => {
         impl JsonSchema for $type {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 $instance_type.into()
@@ -21,7 +21,7 @@ macro_rules! simple_impl {
     };
     ($type:ty => $instance_type:literal, $format:literal) => {
         impl JsonSchema for $type {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 $format.into()
@@ -71,7 +71,7 @@ mod std_types {
 macro_rules! unsigned_impl {
     ($type:ty => $instance_type:literal, $format:literal) => {
         impl JsonSchema for $type {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 $format.into()
@@ -96,7 +96,7 @@ unsigned_impl!(u128 => "integer", "uint128");
 unsigned_impl!(usize => "integer", "uint");
 
 impl JsonSchema for char {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "Character".into()
diff --git a/schemars/src/json_schema_impls/sequences.rs b/schemars/src/json_schema_impls/sequences.rs
index 4af62a2..38bf6a1 100644
--- a/schemars/src/json_schema_impls/sequences.rs
+++ b/schemars/src/json_schema_impls/sequences.rs
@@ -9,7 +9,7 @@ macro_rules! seq_impl {
         where
             T: JsonSchema,
         {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 format!("Array_of_{}", T::schema_name()).into()
@@ -35,7 +35,7 @@ macro_rules! set_impl {
         where
             T: JsonSchema,
         {
-            always_inline!();
+            inline_schema!();
 
             fn schema_name() -> Cow<'static, str> {
                 format!("Set_of_{}", T::schema_name()).into()
diff --git a/schemars/src/json_schema_impls/serdejson.rs b/schemars/src/json_schema_impls/serdejson.rs
index 2b6aa7d..8308eb1 100644
--- a/schemars/src/json_schema_impls/serdejson.rs
+++ b/schemars/src/json_schema_impls/serdejson.rs
@@ -6,7 +6,7 @@ use alloc::collections::BTreeMap;
 use serde_json::{Map, Number, Value};
 
 impl JsonSchema for Value {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "AnyValue".into()
@@ -20,7 +20,7 @@ impl JsonSchema for Value {
 forward_impl!(Map<String, Value> => BTreeMap<String, Value>);
 
 impl JsonSchema for Number {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "Number".into()
diff --git a/schemars/src/json_schema_impls/tuple.rs b/schemars/src/json_schema_impls/tuple.rs
index 88cc0ff..d7a1540 100644
--- a/schemars/src/json_schema_impls/tuple.rs
+++ b/schemars/src/json_schema_impls/tuple.rs
@@ -7,7 +7,7 @@ macro_rules! tuple_impls {
     ($($len:expr => ($($name:ident)+))+) => {
         $(
             impl<$($name: JsonSchema),+> JsonSchema for ($($name,)+) {
-                always_inline!();
+                inline_schema!();
 
                 fn schema_name() -> Cow<'static, str> {
                     let mut name = "Tuple_of_".to_owned();
diff --git a/schemars/src/json_schema_impls/url2.rs b/schemars/src/json_schema_impls/url2.rs
index 6fcaceb..fa36983 100644
--- a/schemars/src/json_schema_impls/url2.rs
+++ b/schemars/src/json_schema_impls/url2.rs
@@ -4,7 +4,7 @@ use alloc::borrow::Cow;
 use url2::Url;
 
 impl JsonSchema for Url {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "Url".into()
diff --git a/schemars/src/json_schema_impls/uuid1.rs b/schemars/src/json_schema_impls/uuid1.rs
index 677c279..0a66d93 100644
--- a/schemars/src/json_schema_impls/uuid1.rs
+++ b/schemars/src/json_schema_impls/uuid1.rs
@@ -4,7 +4,7 @@ use alloc::borrow::Cow;
 use uuid1::Uuid;
 
 impl JsonSchema for Uuid {
-    always_inline!();
+    inline_schema!();
 
     fn schema_name() -> Cow<'static, str> {
         "Uuid".into()
diff --git a/schemars/src/lib.rs b/schemars/src/lib.rs
index b62a153..170b1da 100644
--- a/schemars/src/lib.rs
+++ b/schemars/src/lib.rs
@@ -146,6 +146,14 @@ pub mod r#gen {
 /// assert_eq!(<GenericType<i32>>::schema_id(), <&mut GenericType<&i32>>::schema_id());
 /// ```
 pub trait JsonSchema {
+    /// Only included for backward-compatibility - use `inline_schema()` instead".
+    ///
+    /// This will be removed before schemars 1.0 becomes stable.
+    #[deprecated = "Use `inline_schema()` instead"]
+    fn always_inline_schema() -> bool {
+        false
+    }
+
     /// Whether JSON Schemas generated for this type should be included directly in parent schemas,
     /// rather than being re-used where possible using the `$ref` keyword.
     ///
@@ -154,8 +162,9 @@ pub trait JsonSchema {
     /// infinite cycles when generating schemas.
     ///
     /// By default, this returns `false`.
-    fn always_inline_schema() -> bool {
-        false
+    fn inline_schema() -> bool {
+        #[allow(deprecated)]
+        Self::always_inline_schema()
     }
 
     /// The name of the generated JSON Schema.
@@ -179,7 +188,7 @@ pub trait JsonSchema {
 
     /// Generates a JSON Schema for this type.
     ///
-    /// If the returned schema depends on any [non-inlined](JsonSchema::always_inline_schema)
+    /// If the returned schema depends on any [non-inlined](JsonSchema::inline_schema)
     /// schemas, then this method will add them to the [`SchemaGenerator`]'s schema definitions.
     ///
     /// This should not return a `$ref` schema.
diff --git a/schemars_derive/src/lib.rs b/schemars_derive/src/lib.rs
index 2ac7278..6cc4505 100644
--- a/schemars_derive/src/lib.rs
+++ b/schemars_derive/src/lib.rs
@@ -58,8 +58,8 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
 
                 #[automatically_derived]
                 impl #impl_generics schemars::JsonSchema for #type_name #ty_generics #where_clause {
-                    fn always_inline_schema() -> bool {
-                        <#ty as schemars::JsonSchema>::always_inline_schema()
+                    fn inline_schema() -> bool {
+                        <#ty as schemars::JsonSchema>::inline_schema()
                     }
 
                     fn schema_name() -> schemars::_private::alloc::borrow::Cow<'static, str> {
@@ -199,7 +199,7 @@ fn derive_json_schema(mut input: syn::DeriveInput, repr: bool) -> syn::Result<To
                     #schema_expr
                 }
 
-                fn always_inline_schema() -> bool {
+                fn inline_schema() -> bool {
                     #inline
                 }
             };
diff --git a/schemars_derive/src/schema_exprs.rs b/schemars_derive/src/schema_exprs.rs
index 7721103..166a65d 100644
--- a/schemars_derive/src/schema_exprs.rs
+++ b/schemars_derive/src/schema_exprs.rs
@@ -155,7 +155,7 @@ fn type_for_schema(with_attr: &WithAttr) -> (syn::Type, Option<TokenStream>) {
                 struct #ty_name;
 
                 impl schemars::JsonSchema for #ty_name {
-                    fn always_inline_schema() -> bool {
+                    fn inline_schema() -> bool {
                         true
                     }
 


Test patch:
diff --git a/schemars/tests/integration/test_helper.rs b/schemars/tests/integration/test_helper.rs
index 41f937b..bd4c277 100644
--- a/schemars/tests/integration/test_helper.rs
+++ b/schemars/tests/integration/test_helper.rs
@@ -123,9 +123,9 @@ impl<T: JsonSchema> TestHelper<T> {
         );
 
         assert_eq!(
-            T::always_inline_schema(),
-            T2::always_inline_schema(),
-            "`{t}` and `{t2}` have identical schemas, so should have the same always_inline_schema"
+            T::inline_schema(),
+            T2::inline_schema(),
+            "`{t}` and `{t2}` have identical schemas, so should have the same inline_schema"
         );
 
         self