Commit Graph

11 Commits

Author SHA1 Message Date
Valentin Gagarin
e28681c4f2 lib/jsonschema: make attrs required
Before the change, modules of the form

```nix
{ lib, ... }: {
  foo.bar = lib.mkOption {
    # ...
  };
}
```

or

```nix
{ lib, ... }: {
  foo = lib.mkOption {
    type = lib.types.subModule {
      bar = lib.mkOption {
        # ...
      };
    };
  };
}
```

would not render with `foo` as required, which is not faithful to the
module system's semantics.

This change also tests that fields with defaults are not marked required.
Note that submodule options cannot have their defaults rendered to JSON
schema, and are therefore always marked required.

Architecturally this change is rather unfortunate: So far the checks for
defaults happen in the rendering (using `isDefault`) and not in the parsing,
but here we're adding a field to `$exportedModuleInfo`. While strictly
speaking we probably don't want to consider requiredness as module-level
information, it seems more reasonable to me to do it that way since at
the JSON schema level we have lost the distinction between `attrs`,
`attrsOf`, `submodule`.
2025-04-16 13:20:00 +02:00
lassulus
79a2283c71 *: nix fmt 2024-12-02 15:14:40 +01:00
Johannes Kirschbauer
b9ef080950 jsonschema: migrate tests 2024-11-12 13:23:31 +01:00
Johannes Kirschbauer
c33c5f8b19 Jsonschema: clean up tests 2024-11-08 13:22:58 +01:00
Johannes Kirschbauer
ad321976ff Fix schema test 2024-07-14 15:02:32 +02:00
Johannes Kirschbauer
3034b9ef92 Json-schema: extend interface by header to allow schema spec and arbitrary extensions 2024-07-14 13:29:19 +02:00
Johannes Kirschbauer
d7dc66da03 Json-schema tests: add schema specifier to test 2024-06-24 16:00:46 +02:00
Johannes Kirschbauer
51154c1d54 schema improvements: add additionalProperties: false to ensure closed types 2024-06-24 15:55:48 +02:00
Jörg Thalheim
e296a3019d re-format with nixfmt 2024-03-17 19:48:49 +01:00
DavHau
cd048c2114 lan-config: handle nested options 2023-08-09 18:19:43 +02:00
DavHau
7262208a4c clanLib.jsonschema: move tests from pkgs/clan-cli 2023-08-09 16:05:33 +02:00