Skip to content

Commit

Permalink
Enable coercion / defaults by using ajv instead of ajv-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
iilei committed Dec 25, 2018
1 parent 4d15055 commit a90582a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RUN apk update \

RUN npm i -g "[email protected]" \
"@sindresorhus/[email protected]" \
"ajv[email protected]" \
"ajv@6.6.2" \
"[email protected]" \
"[email protected]"

Expand Down
5 changes: 2 additions & 3 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ export NODE_PATH=/usr/lib/node_modules
# parse services.yaml.tmpl by envsubst and write to services.json
echo "Utilizing 'envtpl' and 'yq' to generate services.json ..."
set -x
envtpl < services.yaml.tmpl | yq -M -r '.' > services.json
envtpl < services.yaml.tmpl | yq -M -r '.' > services.raw.json
node /hbs/validate.js >| /services.json
set +x

echo "Result:"
jq '.' services.json

set -x
ajv validate -s /hbs/schema.json -d services.json

# copy
cp -rf /nginx/* /etc/nginx/
rm /etc/nginx/**/*.hbs
Expand Down
15 changes: 15 additions & 0 deletions hbs/validate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Ajv = require('ajv');
const schema = require("./schema.json");
const data = require("/services.raw.json")

const ajv = new Ajv({
useDefaults: true,
});

var validate = ajv.compile(schema);

if (!validate(data)) {
process.exitCode = 1;
}

console.log(JSON.stringify(data, null, 2));

0 comments on commit a90582a

Please sign in to comment.