about summary refs log tree commit diff
path: root/pkgs/development/tools/cue/validator.nix
blob: cddc3fe342b721f31a171fcf5da6ffb66f490725 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ cue, writeShellScript, lib }:
# `document` must be a fragment of definition or structure that the input data will be matched against.
# `document` must exist in the Cue schema file provided (`cueSchemaFile`).
# The result is a script that can be used to validate the input data (JSON/YAML and more can be supported depending on Cue)
# against the fragment described by `document` or the whole definition.
# The script will be strict and enforce concrete values, i.e. partial documents are not supported.
cueSchemaFile: { document ? null }:
  writeShellScript "validate-using-cue"
  ''${cue}/bin/cue \
      --all-errors \
      --strict \
      vet \
      --concrete \
      "$1" \
      ${cueSchemaFile} \
      ${lib.optionalString (document != null) "-d \"${document}\""}
  ''