Skip to content

langium-zod / FilterConfig

Interface: FilterConfig

Defined in: config.ts:51

Include/exclude filter that controls which Langium type names are emitted during schema generation.

When include is non-empty, only the listed type names (and any stub types they reference) are generated. When exclude is non-empty, the listed names are skipped. If both are supplied, exclude takes precedence for names that appear in both lists. An empty (or omitted) FilterConfig emits all types.

Remarks

Stub types — referenced type names that have no corresponding interface or union in the grammar (e.g. standalone datatype rules like ValidID) — are only emitted when neither include nor exclude suppresses them. If you use include, you must enumerate stub type names explicitly if you want them in the output.

Example

ts
// Emit only two types + any stubs they transitively reference
const filter: FilterConfig = { include: ['Greeting', 'Person'] };

// Suppress internal Langium bookkeeping types
const filter: FilterConfig = { exclude: ['AbstractElement', 'NamedElement'] };

Use When

  • You want to emit schemas for only a curated subset of your grammar's types.
  • You need to exclude abstract base types that your application never validates directly.
  • You are generating incremental schemas for a large grammar where only a few types change.

Avoid When

  • You want all grammar types — omit FilterConfig entirely or pass {}.
  • You need to exclude fields within a type (not the whole type) — use projection in ZodGeneratorConfig instead.

Never

  • NEVER include a union type in include without also including all of its member interface types. BECAUSE the union descriptor references its members by name; absent members produce a discriminated union with zero branches, which Zod rejects at runtime.
  • NEVER rely on exclude to strip security-sensitive fields from the generated schema at runtime. BECAUSE filtering operates on whole types, not fields; use projection to strip individual fields.

Config

See

ZodGeneratorConfig

Extended by

Properties

PropertyTypeDefined in
exclude?string[]config.ts:53
include?string[]config.ts:52

Released under the MIT License.