Finding and removing unused fields in Sanity documents
Since these fields count towards our attribute limit, we want to get rid of any unused ones.
Basically what I seem to be looking for is a way to validate an entire dataset against a schema.
My example happens to be
body(see attached)
get the documents current fields using
Object.keys()•
filter out every field in the whitelist of allowed fields •
send the result into a patch of unsets
schema.validateDocument(doc)function in https://github.com/sanity-io/sanity/tree/next/packages/%40sanity/schema
schemainformation with
import schema from 'part:@sanity/base/schema'Problem is now that in v3, I don’t know what’s the equivalent of that import. I came to know ``import {useSchema} from 'sanity'`` but that is only applicable inside a React component while the other example is with `sanity.config.ts``s
contextargument in deskTool
structure
Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.