Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add schema URL to the meta object #313

Merged
merged 10 commits into from
Oct 17, 2022
33 changes: 33 additions & 0 deletions add-schema-uri.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash
e-backmark-ericsson marked this conversation as resolved.
Show resolved Hide resolved

# A helper script to add property schemaUri to the latest schemas and increase
# its version.
schemas_dir="schemas"
semver_regex='(.*)/([[:digit:]]+)\.([[:digit:]]+)\.([[:digit:]]+)\.(json)'

property_path='.properties.meta.properties'
property_to_add='{schemaUri: {type: "string", additionalProperties: false}}'

for current_file in $(./find-latest-schemas.sh -d "$schemas_dir"); do
# schema=$(basename "$path")
if [[ ! "$current_file" =~ $semver_regex ]]; then
echo "$path doesn't match $semver_regex" 1>&2
exit 1
fi

path="${BASH_REMATCH[1]}"
major="${BASH_REMATCH[2]}"
minor="${BASH_REMATCH[3]}"
patch="${BASH_REMATCH[4]}"
suffix="${BASH_REMATCH[5]}"

((minor += 1))
new_version="$major.$minor.$patch"
new_file="$path/$new_version.$suffix"

cat "$current_file" | jq "$property_path += $property_to_add" | \
jq ".properties.meta.properties.version.enum[0] |= \"$new_version\"" | \
jq ".properties.meta.properties.version.default |= \"$new_version\"" \
> "$new_file"
ls -l "$new_file"
done
39 changes: 39 additions & 0 deletions find-latest-schemas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

usage() {
echo "Usage: $(basename "$0") OPTION
where OPTION is
-d|--schemas-dir SCHEMAS_DIR
Prints out the latest JSON schemas of SCHEMAS_DIR. It expects a folder
containing sub-folders per event, i.e. <SCHEMAS_DIR>/<event-dir>/X.Y.Z.json.
The output is list of files separated by new-lines.

-h|--help Prints out this help.
"

}
schemasdir=''

while [[ $# -gt 0 ]]; do
case $1 in
-d|--schemas-dir)
schemasdir="$2"
shift 2
;;
*)
usage
exit 1
;;
esac
done

if [ -z "$schemasdir" ]; then
usage
exit 1
fi

while IFS= read -r -d '' schemadir
do
schema=$(ls "$schemadir/$d" | sort -V | tail -1)
echo "$schemadir/$d$schema"
done < <(find "$schemasdir" -mindepth 1 -type d -print0 )
189 changes: 189 additions & 0 deletions schemas/EiffelActivityCanceledEvent/3.2.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"meta": {
"type": "object",
"properties": {
"id": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
},
"type": {
"type": "string",
"enum": [
"EiffelActivityCanceledEvent"
]
},
"version": {
"type": "string",
"enum": [
"3.2.0"
],
"default": "3.2.0"
},
"time": {
"type": "integer"
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"source": {
"type": "object",
"properties": {
"domainId": {
"type": "string"
},
"host": {
"type": "string"
},
"name": {
"type": "string"
},
"serializer": {
"type": "string",
"pattern": "^pkg:"
},
"uri": {
"type": "string"
}
},
"additionalProperties": false
},
"security": {
"type": "object",
"properties": {
"authorIdentity": {
"type": "string"
},
"integrityProtection": {
"type": "object",
"properties": {
"signature": {
"type": "string"
},
"alg": {
"type": "string",
"enum": [
"HS256",
"HS384",
"HS512",
"RS256",
"RS384",
"RS512",
"ES256",
"ES384",
"ES512",
"PS256",
"PS384",
"PS512"
]
},
"publicKey": {
"type": "string"
}
},
"required": [
"signature",
"alg"
],
"additionalProperties": false
},
"sequenceProtection": {
"type": "array",
"items": {
"type": "object",
"properties": {
"sequenceName": {
"type": "string"
},
"position": {
"type": "integer"
}
},
"additionalProperties": false,
"required": [
"sequenceName",
"position"
]
}
}
},
"additionalProperties": false,
"required": [
"authorIdentity"
]
},
"schemaUri": {
"type": "string",
"additionalProperties": false
}
},
"required": [
"id",
"type",
"version",
"time"
],
"additionalProperties": false
},
"data": {
"type": "object",
"properties": {
"reason": {
"type": "string"
},
"customData": {
"type": "array",
"items": {
"type": "object",
"properties": {
"key": {
"type": "string"
},
"value": {}
},
"required": [
"key",
"value"
],
"additionalProperties": false
}
}
},
"additionalProperties": false
},
"links": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string"
},
"target": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$"
},
"domainId": {
"type": "string"
}
},
"required": [
"type",
"target"
],
"additionalProperties": false
}
}
},
"required": [
"meta",
"data",
"links"
],
"additonalProperties": false
}