Merge pull request 'lib/jsonSchema: handle defaults for defaultText' (#2268) from hsjobeki/clan-core:hsjobeki-main into main
This commit is contained in:
@@ -26,8 +26,7 @@ let
|
||||
|
||||
# Exclude the option if its type is in the excludedTypes list
|
||||
# or if the option has a defaultText attribute
|
||||
isExcludedOption =
|
||||
option: ((lib.elem (option.type.name or null) excludedTypes) || (option ? defaultText));
|
||||
isExcludedOption = option: (lib.elem (option.type.name or null) excludedTypes);
|
||||
|
||||
filterExcluded = lib.filter (opt: !isExcludedOption opt);
|
||||
|
||||
@@ -58,6 +57,24 @@ rec {
|
||||
in
|
||||
parseOptions evaled.options { };
|
||||
|
||||
# get default value from option
|
||||
|
||||
# Returns '{ default = Value; }'
|
||||
# - '{}' if no default is present.
|
||||
# - Value is "<thunk>" (string literal) if the option has a defaultText attribute. This means we cannot evaluate default safely
|
||||
getDefaultFrom =
|
||||
opt:
|
||||
if !includeDefaults then
|
||||
{ }
|
||||
else if opt ? defaultText then
|
||||
{
|
||||
default = "<thunk>";
|
||||
}
|
||||
else
|
||||
lib.optionalAttrs (opt ? default) {
|
||||
default = opt.default;
|
||||
};
|
||||
|
||||
parseOptions' = lib.flip parseOptions { addHeader = false; };
|
||||
|
||||
# parses a set of evaluated nixos options to a jsonschema
|
||||
@@ -92,7 +109,7 @@ rec {
|
||||
parseOption =
|
||||
option:
|
||||
let
|
||||
default = lib.optionalAttrs (option ? default && includeDefaults) { inherit (option) default; };
|
||||
default = getDefaultFrom option;
|
||||
example = lib.optionalAttrs (option ? example) {
|
||||
examples =
|
||||
if (builtins.typeOf option.example) == "list" then option.example else [ option.example ];
|
||||
|
||||
Reference in New Issue
Block a user