forked from fediversity/module-schema
Generate JSON schema for Nix modules
- Nix 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
`optionsToSchema` returns the bare per-option property map, with the
`$schema`/`$defs` meta keys mixed in at the top level -- not itself a valid
object schema. Every consumer that wants a standalone schema (to validate a
whole configuration, or to feed a form renderer) had to wrap that map into the
object root by hand, re-deriving `required` from scratch.
`moduleToSchema` upstreams that wrap step: fed `(moduleType.getSubOptions [ ])`,
it returns `{ "$schema" = ...; type = "object"; additionalProperties = false;
properties = <options>; required = <options-without-default>; "$defs" = <defs>; }`
directly. It strips the module-system bookkeeping options
`_module`/`_freeformOptions` that `getSubOptions` surfaces, so a caller can pass
that output verbatim without them leaking in as properties.
The wrap logic already existed inside the `submodule` branch (which produces
exactly this object root for a submodule type) but was unreachable from the
top-level option-map entry. Factor it into a shared `wrapAsObject` helper (with a
shared `hasDefault`) that both the `submodule` branch and `moduleToSchema` call,
so there is a single source of truth for the object root a module validates as.
The submodule branch stays byte-identical (2900/2900 tests, golden `services.*`
included); `matchesSubmoduleBranch.test` pins the equivalence.
Assisted-by: Claude:claude-opus-4-8
|
||
| lib | ||
| notes | ||
| npins | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| shell.nix | ||
module-schema
Generate JSON schema for NixOS modules