validation
napt.validation
Recipe validation module.
This module provides validation functions for checking recipe syntax and
configuration without making network calls or downloading files. This is
useful for quick feedback during recipe development and in CI/CD pipelines.
napt validate checks the effective configuration (code defaults,
org.yaml, vendor defaults, parent, recipe), the same merge every other
command loads, so an error in any layer is reported before a pipeline
runs into it.
Validation Checks:
- YAML syntax is valid
- Required top-level fields present (apiVersion, name, id, discovery)
- apiVersion is present (a value other than napt/v1 is a warning)
- id is usable as a folder name (letters, digits, '.', '-', '_', '+',
starting with a letter or digit); an id outside the recommended
<vendor>-<app>form (lowercase, digits, single hyphens) is a warning - parent, when declared, is a string and the file carries the
.override.yamlsuffix (a mismatch either way is a warning) - discovery.strategy exists and is registered
- Strategy-specific configuration is valid
- Every section (top level, discovery, psadt, psadt.brand_pack, intune, intune.detection, logging, directories, intunewin, deployment, secrets) is checked against its schema: field types, allowed values, integer bounds, and a warning for each unknown key naming the closest known one
- A section present but left empty is an error
- intune.minimum_supported_windows_release matches the Windows10_21H2 or Windows11_23H2 form
- psadt.app_vars only contains user-settable keys
- psadt.brand_pack.mappings entries each name a source and a target
- deployment ring names and groups are present and unique
- secrets section entries are shaped as
NAME: {hosts: [...]}, come from defaults/org.yaml alone, and every${NAME}a recipe sends is declared and bound to the request host (see napt.secrets) - A directory of recipes contains no two files with the same id
ValidationResult
dataclass
Result from validating a recipe.
Attributes:
| Name | Type | Description |
|---|---|---|
errors |
list[str]
|
List of error messages (empty if valid). |
warnings |
list[str]
|
List of warning messages. |
recipe_path |
str
|
String path to the validated recipe file. |
parent_path |
str | None
|
String path to the parent recipe merged beneath it, or None when the recipe declares no parent. |
app_id |
str | None
|
The recipe's id, or None when it has no usable one. |
config |
dict[str, Any] | None
|
The effective configuration that was validated, provenance included, when the recipe is valid; None when it has errors. |
Source code in napt/validation.py
validate_config
Validates a merged configuration dict.
Checks required fields, types, strategy registration, and section-level
validation. Used by both validate_recipe (CLI) and
load_effective_config (pipeline commands) so that one set of rules
applies everywhere. When the dict carries the loader's _provenance
entry, the secrets check also reports entries that a layer other than
org.yaml tried to declare.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
The merged configuration dictionary to validate. |
required |
recipe_path
|
str
|
Optional path string for error context. |
''
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
Validation status, errors, warnings, app count, and the app id. |
Source code in napt/validation.py
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 | |
validate_recipe
Validates a recipe's effective configuration.
Merges the recipe with its parent, vendor defaults, and org.yaml the way every other command does, then validates the result, so an error in any layer is reported here. A file that cannot be read or merged (a missing file, a YAML syntax error, a missing parent) is an invalid result rather than an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
recipe_path
|
Path
|
Path to the recipe YAML file to validate. |
required |
Returns:
| Type | Description |
|---|---|
ValidationResult
|
The errors, warnings, app id, the parent path when the recipe declares one, and the effective configuration when it is valid. |
Example
Validate a recipe and check results:
Source code in napt/validation.py
validate_recipes
Validates a recipe file or every recipe under a directory.
Each file is validated with
validate_recipe. For a directory,
two files that resolve to the same id are also reported (a parent
recipe scanned beside the child that inherits its id is the usual
cause), since napt promote refuses such a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
A recipe YAML file, or a directory scanned recursively. |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationResult]
|
One result per recipe file, in path order; a single invalid result when the path does not exist or holds no recipes. |