diff --git a/lib/jsonschema/default.nix b/lib/jsonschema/default.nix index 855739897..b0bad30de 100644 --- a/lib/jsonschema/default.nix +++ b/lib/jsonschema/default.nix @@ -425,7 +425,19 @@ rec { # return jsonschema property definition for submodule # then (lib.attrNames (option.type.getSubOptions option.loc).opt) then - exposedModuleInfo // example // description // parseSubOptions { inherit option; } + (lib.recursiveUpdate exposedModuleInfo ( + if (default ? default) then + default + else + { + "$exportedModuleInfo" = { + required = true; + }; + } + )) + // example + // description + // parseSubOptions { inherit option; } # throw error if option type is not supported else notSupported option; diff --git a/lib/jsonschema/example-interface.nix b/lib/jsonschema/example-interface.nix index fedd0d12b..3d1e04d57 100644 --- a/lib/jsonschema/example-interface.nix +++ b/lib/jsonschema/example-interface.nix @@ -20,7 +20,7 @@ default = false; description = "Is the user an admin?"; }; - # a submodule option + # a submodule option without default services = lib.mkOption { type = lib.types.submodule { options.opt = lib.mkOption { @@ -30,6 +30,17 @@ }; }; }; + # a submodule option with default + programs = lib.mkOption { + type = lib.types.submodule { + options.opt = lib.mkOption { + type = lib.types.str; + default = "bar"; + description = "Another submodule option"; + }; + }; + default = { }; + }; # attrs of int userIds = lib.mkOption { type = lib.types.attrsOf lib.types.int; diff --git a/lib/jsonschema/example-schema.json b/lib/jsonschema/example-schema.json index 6b95742a4..ecb937fc7 100644 --- a/lib/jsonschema/example-schema.json +++ b/lib/jsonschema/example-schema.json @@ -92,6 +92,20 @@ } } }, + "programs": { + "$exportedModuleInfo": { "path": ["programs"] }, + "type": "object", + "additionalProperties": false, + "properties": { + "opt": { + "$exportedModuleInfo": { "path": ["programs", "opt"] }, + "type": "string", + "default": "bar", + "description": "Another submodule option" + } + }, + "default": {} + }, "destinations": { "$exportedModuleInfo": { "path": ["destinations"] }, "additionalProperties": { diff --git a/lib/jsonschema/test_parseOption.nix b/lib/jsonschema/test_parseOption.nix index 51f092de1..75ced777c 100644 --- a/lib/jsonschema/test_parseOption.nix +++ b/lib/jsonschema/test_parseOption.nix @@ -324,6 +324,7 @@ in }; }; }; + default = { }; }; }; @@ -354,6 +355,7 @@ in }; }; }; + default = { }; required = [ "opt" ]; }; };