Features:
- Uses single json schema file with multiple definitions (configurable via
SCHEMAVERCHECK_SCHEMA_FILE
) - Multiple definitions should be named as
#/definition/${DefinitionName}
- Verifies local data mocks against schema and specified definition
- Calls remote endpoint to verify if specified definition is compatible with remote one
- Has ability to skip remote check (via
SCHEMAVERCHECK_SKIP_REMOTE_CHECK
) - Retries the remote check 10 times before failing (useful for long container startup time)
Environment variables
SCHEMAVERCHECK_SCHEMA_FILE=/path/to/schema.json
SCHEMAVERCHECK_ENDPOINT_URL_FORMAT=https://local-service:80/verify_json_schema?definitionName=%s
SCHEMAVERCHECK_SKIP_REMOTE_CHECK=1
— allows skipping remote check (useful for local testing)
The remote check endpoint compatibility guide:
- Accepts POST request with a GET/url parameter with DefinitionName
- The body of the request consists of JSON Schema file
- 200 — If the specified definition of sent schema is compatible with the one's of endpoint
- 409 — If incomptible
- 4xx — On request errors
- 5xx — On server error
- Error response should have
error
field (string)
In this example:
- We use
/mock/employees.json
for local testing - We run local tests using mock files
- To ensure compatibility on each run we verify the mock files are compatible
- Also on each run we make POST request to ensure local schema is compatible with remote one
- This way we can easily test with local mock as well as we prevent starting incompatible container
Dockerfile:
FROM jedrzejlewandowski/schemaver-check:1.1.4 AS schemaVerCheck
FROM node
COPY --from=schemaVerCheck /bin/schemaver-check /bin/schemaver-check
ADD ./global.schema.json /global.schema.json
ENV SCHEMAVERCHECK_SCHEMA_FILE=/global.schema.json
CMD ["/bin/sh", "-c", "\
/bin/schemaver-check --data-file /mock/employees.json --definition-name \"AllEmployeesSpec\" && \
... \
"]
docker-compose.yml:
version: "3.7"
services:
node_serv:
build: .
environment:
SCHEMAVERCHECK_ENDPOINT_URL_FORMAT: https://businessapi:80/schema/check_compatibility?definitionName=%s