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