@@ -164,16 +164,38 @@ declareSchemaRef proxy = do
164164 return $ Ref (Reference name)
165165 _ -> Inline <$> declareSchema proxy
166166
167−inlineSchemas :: Data s => [T.Text] -> Definitions -> s -> s
168−inlineSchemas names defs = template %~ deref
167+-- | Inline any referenced schema if its name satisfies given predicate.
168+--
169+-- /NOTE:/ if a referenced schema is not found in definitions the predicate is ignored
170+-- and schema stays referenced.
171+--
172+-- __WARNING:__ @'inlineSchemasWhen'@ will loop when inlining recursive schemas.
173+inlineSchemasWhen :: Data s => (T.Text -> Bool) -> Definitions -> s -> s
174+inlineSchemasWhen p defs = template %~ deref
169175 where
170176 deref r@(Ref (Reference name))
171− | name `elem` names =
177+ | p name =
172178 case HashMap.lookup name defs of
173− Just schema -> Inline (inlineSchemas names defs schema)
179+ Just schema -> Inline (inlineSchemasWhen p defs schema)
174180 Nothing -> r
175181 deref r = r
176182
183+-- | Inline any referenced schema if its name is in the given list.
184+--
185+-- /NOTE:/ if a referenced schema is not found in definitions
186+-- it stays referenced even if it appears in the list of names.
187+--
188+-- __WARNING:__ @'inlineSchemas'@ will loop when inlining recursive schemas.
189+inlineSchemas :: Data s => [T.Text] -> Definitions -> s -> s
190+inlineSchemas names = inlineSchemasWhen (`elem` names)
191+
192+-- | Inline all schema references for which the definition
193+-- can be found in @'Definitions'@.
194+--
195+-- __WARNING:__ @'inlineAllSchemas'@ will loop when inlining recursive schemas.
196+inlineAllSchemas :: Data s => Definitions -> s -> s
197+inlineAllSchemas = inlineSchemasWhen (const True)
198+
177199class GToSchema (f :: * -> *) where
178200 gdeclareNamedSchema :: SchemaOptions -> proxy f -> Schema -> Declare Definitions NamedSchema
179201