Commit Graph

12 Commits

Author SHA1 Message Date
Johannes Kirschbauer
dad55040ba Feat(jsonschema): simplify isRequired, look into default and defaultText 2025-06-04 19:57:39 +02:00
Valentin Gagarin
06e27c84de 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
3ae82f3efc *: nix fmt 2024-12-02 15:14:40 +01:00
Johannes Kirschbauer
5c63ce0058 jsonschema: migrate tests 2024-11-12 13:23:31 +01:00
Johannes Kirschbauer
a67f42ee7a Jsonschema: clean up tests 2024-11-08 13:22:58 +01:00
Johannes Kirschbauer
c43c4ef067 Fix schema test 2024-07-14 15:02:32 +02:00
Johannes Kirschbauer
77577a9f27 Json-schema: extend interface by header to allow schema spec and arbitrary extensions 2024-07-14 13:29:19 +02:00
Johannes Kirschbauer
c77230e3b6 Json-schema tests: add schema specifier to test 2024-06-24 16:00:46 +02:00
Johannes Kirschbauer
bcb7152c9f schema improvements: add additionalProperties: false to ensure closed types 2024-06-24 15:55:48 +02:00
Jörg Thalheim
ede4d3f6e5 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