Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 cue, 3 writeShellScript, 4 lib, 5}: 6# `document` must be a fragment of definition or structure that the input data will be matched against. 7# `document` must exist in the Cue schema file provided (`cueSchemaFile`). 8# The result is a script that can be used to validate the input data (JSON/YAML and more can be supported depending on Cue) 9# against the fragment described by `document` or the whole definition. 10# The script will be strict and enforce concrete values, i.e. partial documents are not supported. 11cueSchemaFile: 12{ 13 document ? null, 14}: 15writeShellScript "validate-using-cue" '' 16 ${cue}/bin/cue \ 17 --all-errors \ 18 --strict \ 19 vet \ 20 --concrete \ 21 "$1" \ 22 ${cueSchemaFile} \ 23 ${lib.optionalString (document != null) "-d \"${document}\""} 24''