Commit Graph

11 Commits

Author SHA1 Message Date
Valentin Gagarin
af7915a564 lib/jsonschema: render defaults for submodule options
this relaxes the constraint that options of type `submodule` are always
required, and will render benign default values.
2025-04-16 16:55:46 +02:00
Johannes Kirschbauer
15fe06fbf5 feat(jsonschema): add test for attrsof submodule 2025-04-16 14:48:49 +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
Michael Hoang
c2eaf74df5 lib/jsonschema: fix enum support 2025-04-08 08:53:27 +02:00
Johannes Kirschbauer
5c63ce0058 jsonschema: migrate tests 2024-11-12 13:23:31 +01: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
Johannes Kirschbauer
b222c98a54 Inventory: add concrete use-case examples 2024-06-24 14:35:41 +02:00
Qubasa
83f07816a3 Add jsonschema test case 2024-05-03 19:40:42 +02:00
Jörg Thalheim
4d183fff58 apply prettier to source tree 2023-08-24 14:13:02 +02:00
DavHau
7262208a4c clanLib.jsonschema: move tests from pkgs/clan-cli 2023-08-09 16:05:33 +02:00