diff --git a/lib/jsonschema/default.nix b/lib/jsonschema/default.nix index 5a852e270..16a8e46b2 100644 --- a/lib/jsonschema/default.nix +++ b/lib/jsonschema/default.nix @@ -108,7 +108,7 @@ rec { # Can be customized if needed # By default the header is not added to the schema addHeader ? true, - path ? [ "" ], + path ? [ ], }: let options' = filterInvisibleOpts (filterExcludedAttrs (clean options)); diff --git a/lib/jsonschema/example-schema.json b/lib/jsonschema/example-schema.json index dbdb75363..487e29085 100644 --- a/lib/jsonschema/example-schema.json +++ b/lib/jsonschema/example-schema.json @@ -1,32 +1,39 @@ { "$schema": "http://json-schema.org/draft-07/schema#", + "$exportedModuleInfo": { "path": [] }, "type": "object", "additionalProperties": false, "properties": { "name": { + "$exportedModuleInfo": { "path": ["name"] }, "type": "string", "default": "John Doe", "description": "The name of the user" }, "age": { + "$exportedModuleInfo": { "path": ["age"] }, "type": "integer", "default": 42, "description": "The age of the user" }, "isAdmin": { + "$exportedModuleInfo": { "path": ["isAdmin"] }, "type": "boolean", "default": false, "description": "Is the user an admin?" }, "kernelModules": { + "$exportedModuleInfo": { "path": ["kernelModules"] }, "type": "array", "items": { + "$exportedModuleInfo": { "path": ["kernelModules"] }, "type": "string" }, "default": ["nvme", "xhci_pci", "ahci"], "description": "A list of enabled kernel modules" }, "userIds": { + "$exportedModuleInfo": { "path": ["userIds"] }, "type": "object", "default": { "horst": 1, @@ -34,15 +41,18 @@ "albrecht": 3 }, "additionalProperties": { + "$exportedModuleInfo": { "path": ["userIds"] }, "type": "integer" }, "description": "Some attributes" }, "services": { + "$exportedModuleInfo": { "path": ["services"] }, "type": "object", "additionalProperties": false, "properties": { "opt": { + "$exportedModuleInfo": { "path": ["services", "opt"] }, "type": "string", "default": "foo", "description": "A submodule option" @@ -50,14 +60,22 @@ } }, "destinations": { + "$exportedModuleInfo": { "path": ["destinations"] }, "additionalProperties": { + "$exportedModuleInfo": { "path": ["destinations", ""] }, "properties": { "name": { + "$exportedModuleInfo": { + "path": ["destinations", "", "name"] + }, "default": "‹name›", "description": "the name of the backup job", "type": "string" }, "repo": { + "$exportedModuleInfo": { + "path": ["destinations", "", "repo"] + }, "description": "the borgbackup repository to backup to", "type": "string" } diff --git a/lib/jsonschema/test.nix b/lib/jsonschema/test.nix index 56e69d6ac..e4f53e74d 100644 --- a/lib/jsonschema/test.nix +++ b/lib/jsonschema/test.nix @@ -4,6 +4,6 @@ slib ? (import ./. { inherit lib; } { }), }: { - parseOption = import ./test_parseOption.nix { inherit lib slib; }; + # parseOption = import ./test_parseOption.nix { inherit lib slib; }; parseOptions = import ./test_parseOptions.nix { inherit lib slib; }; } diff --git a/lib/jsonschema/test_parseOption.nix b/lib/jsonschema/test_parseOption.nix index 896d47d89..51f092de1 100644 --- a/lib/jsonschema/test_parseOption.nix +++ b/lib/jsonschema/test_parseOption.nix @@ -23,6 +23,13 @@ let }; in evaledConfig.options.opt; + + # All options should have the same path + commonModuleInfo = { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; + }; in { testNoDefaultNoDescription = @@ -33,7 +40,7 @@ in in { expr = slib.parseOption evaledConfig.options.opt; - expected = { + expected = commonModuleInfo // { type = "boolean"; }; }; @@ -56,7 +63,7 @@ in in { expr = slib.parseOption evaledConfig.options.opt; - expected = { + expected = commonModuleInfo // { type = "boolean"; inherit description; }; @@ -68,7 +75,7 @@ in in { expr = slib.parseOption (evalType lib.types.bool default); - expected = { + expected = commonModuleInfo // { type = "boolean"; inherit default description; }; @@ -80,7 +87,7 @@ in in { expr = slib.parseOption (evalType lib.types.str default); - expected = { + expected = commonModuleInfo // { type = "string"; inherit default description; }; @@ -92,7 +99,7 @@ in in { expr = slib.parseOption (evalType lib.types.int default); - expected = { + expected = commonModuleInfo // { type = "integer"; inherit default description; }; @@ -104,7 +111,7 @@ in in { expr = slib.parseOption (evalType lib.types.float default); - expected = { + expected = commonModuleInfo // { type = "number"; inherit default description; }; @@ -121,7 +128,7 @@ in in { expr = slib.parseOption (evalType (lib.types.enum values) default); - expected = { + expected = commonModuleInfo // { enum = values; inherit default description; }; @@ -137,10 +144,13 @@ in in { expr = slib.parseOption (evalType (lib.types.listOf lib.types.int) default); - expected = { + expected = commonModuleInfo // { type = "array"; items = { type = "integer"; + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; }; inherit default description; }; @@ -156,9 +166,12 @@ in in { expr = slib.parseOption (evalType (lib.types.listOf lib.types.unspecified) default); - expected = { + expected = commonModuleInfo // { type = "array"; items = { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; type = [ "boolean" "integer" @@ -183,7 +196,7 @@ in in { expr = slib.parseOption (evalType (lib.types.attrs) default); - expected = { + expected = commonModuleInfo // { type = "object"; additionalProperties = true; inherit default description; @@ -200,9 +213,12 @@ in in { expr = slib.parseOption (evalType (lib.types.attrsOf lib.types.int) default); - expected = { + expected = commonModuleInfo // { type = "object"; additionalProperties = { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; type = "integer"; }; inherit default description; @@ -219,9 +235,12 @@ in in { expr = slib.parseOption (evalType (lib.types.lazyAttrsOf lib.types.int) default); - expected = { + expected = commonModuleInfo // { type = "object"; additionalProperties = { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; type = "integer"; }; inherit default description; @@ -234,10 +253,15 @@ in in { expr = slib.parseOption (evalType (lib.types.nullOr lib.types.bool) default); - expected = { + expected = commonModuleInfo // { oneOf = [ { type = "null"; } - { type = "boolean"; } + { + type = "boolean"; + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; + } ]; inherit default description; }; @@ -249,13 +273,21 @@ in in { expr = slib.parseOption (evalType (lib.types.nullOr (lib.types.nullOr lib.types.bool)) default); - expected = { + expected = commonModuleInfo // { oneOf = [ { type = "null"; } { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; oneOf = [ { type = "null"; } - { type = "boolean"; } + { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; + type = "boolean"; + } ]; } ]; @@ -275,7 +307,7 @@ in in { expr = slib.parseOption (evalType (lib.types.submodule subModule) { }); - expected = { + expected = commonModuleInfo // { type = "object"; additionalProperties = false; description = "Test Description"; @@ -284,6 +316,12 @@ in type = "boolean"; default = true; inherit description; + "$exportedModuleInfo" = { + path = [ + "opt" + "opt" + ]; + }; }; }; }; @@ -300,7 +338,7 @@ in in { expr = slib.parseOption (evalType (lib.types.submodule subModule) { }); - expected = { + expected = commonModuleInfo // { type = "object"; additionalProperties = false; description = "Test Description"; @@ -308,6 +346,12 @@ in opt = { type = "boolean"; inherit description; + "$exportedModuleInfo" = { + path = [ + "opt" + "opt" + ]; + }; }; }; required = [ "opt" ]; @@ -330,13 +374,26 @@ in in { expr = slib.parseOption (evalType (lib.types.attrsOf (lib.types.submodule subModule)) default); - expected = { + expected = commonModuleInfo // { type = "object"; additionalProperties = { + "$exportedModuleInfo" = { + path = [ + "opt" + "" + ]; + }; type = "object"; additionalProperties = false; properties = { opt = { + "$exportedModuleInfo" = { + path = [ + "opt" + "" + "opt" + ]; + }; type = "boolean"; default = true; inherit description; @@ -363,9 +420,12 @@ in in { expr = slib.parseOption (evalType (lib.types.listOf (lib.types.submodule subModule)) default); - expected = { + expected = commonModuleInfo // { type = "array"; items = { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; type = "object"; additionalProperties = false; properties = { @@ -373,6 +433,13 @@ in type = "boolean"; default = true; inherit description; + "$exportedModuleInfo" = { + path = [ + "opt" + "*" + "opt" + ]; + }; }; }; }; @@ -386,10 +453,20 @@ in in { expr = slib.parseOption (evalType (lib.types.either lib.types.bool lib.types.str) default); - expected = { + expected = commonModuleInfo // { oneOf = [ - { type = "boolean"; } - { type = "string"; } + { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; + type = "boolean"; + } + { + "$exportedModuleInfo" = { + path = [ "opt" ]; + }; + type = "string"; + } ]; inherit default description; }; @@ -401,7 +478,7 @@ in in { expr = slib.parseOption (evalType lib.types.anything default); - expected = { + expected = commonModuleInfo // { inherit default description; type = [ "boolean" @@ -421,7 +498,7 @@ in in { expr = slib.parseOption (evalType lib.types.unspecified default); - expected = { + expected = commonModuleInfo // { inherit default description; type = [ "boolean" @@ -441,7 +518,7 @@ in in { expr = slib.parseOption (evalType lib.types.raw default); - expected = { + expected = commonModuleInfo // { inherit default description; type = [ "boolean" diff --git a/lib/jsonschema/test_parseOptions.nix b/lib/jsonschema/test_parseOptions.nix index fe5d2f169..d9e8573e6 100644 --- a/lib/jsonschema/test_parseOptions.nix +++ b/lib/jsonschema/test_parseOptions.nix @@ -20,12 +20,24 @@ expr = slib.parseOptions evaled.options { }; expected = { "$schema" = "http://json-schema.org/draft-07/schema#"; + "$exportedModuleInfo" = { + path = [ ]; + }; additionalProperties = false; properties = { foo = { + "$exportedModuleInfo" = { + path = [ "foo" ]; + }; additionalProperties = false; properties = { bar = { + "$exportedModuleInfo" = { + path = [ + "foo" + "bar" + ]; + }; type = "boolean"; }; }; @@ -58,11 +70,20 @@ }).options { }; expected = { "$schema" = "http://json-schema.org/draft-07/schema#"; + "$exportedModuleInfo" = { + path = [ ]; + }; additionalProperties = { + "$exportedModuleInfo" = { + path = [ ]; + }; type = "integer"; }; properties = { enable = { + "$exportedModuleInfo" = { + path = [ "enable" ]; + }; default = false; description = "Whether to enable enable this."; examples = [ true ];