diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..2655e86 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,22 @@ +name: validate-json + +on: + [push] + # push: + # branches: ["main"] + # pull_request: + # branches: ["main"] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: ">=1.22.4" + - name: Install dependencies + run: go install github.com/santhosh-tekuri/jsonschema/cmd/jv@latest + - name: Validate JSON files + run: jv test/data/snapshot-schema.json test/data/json/*.json diff --git a/test/data/json/example.json b/test/data/json/example.json new file mode 100644 index 0000000..d9a1239 --- /dev/null +++ b/test/data/json/example.json @@ -0,0 +1,60 @@ +[ + { + "id": "f103c749-9932-48bb-8f61-2e8ed2beacc3", + "start_at": "2012-03-29T10:05:45-06:00", + "end_at": "2012-03-29T10:05:45-06:00", + "title": "hello user - this needs translation", + "description": "lorem ipsum user - this needs translation", + "CTA": "lorem ipsum user - this needs translation", + "URL": "https://thunderbird.net", + "severity": 5, + "type": "donation", + "targeting": { + "percent_chance": 10, + "exclude": [ + { + "locales": [], + "versions": [], + "channels": [], + "operating_systems": [] + } + ], + "include": [ + { + "locales": [], + "versions": [], + "channels": [] + } + ] + } + }, + { + "id": "f103c749-9932-48bb-8f61-2e8ed2beacc3", + "start_at": "2012-03-29T10:05:45-06:00", + "end_at": "2024-05-03T15:49:20.331Z", + "title": "hello user - this needs translation", + "description": "lorem ipsum user - this needs translation", + "CTA": "lorem ipsum user - this needs translation", + "URL": "https://thunderbird.net", + "severity": 5, + "type": "donation", + "targeting": { + "percent_chance": 10, + "exclude": [ + { + "locales": [], + "versions": [], + "channels": [], + "operating_systems": [] + } + ], + "include": [ + { + "locales": [], + "versions": [], + "channels": [] + } + ] + } + } +] diff --git a/test/data/snapshot-schema.json b/test/data/snapshot-schema.json new file mode 100644 index 0000000..e33a93f --- /dev/null +++ b/test/data/snapshot-schema.json @@ -0,0 +1,125 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "title": "Thunderbird In-App Notifications", + "type": "array", + "items": { + "type": "object", + "properties": { + "id": { + "type": "string", + "format": "uuid", + "description": "Unique ID set by the server" + }, + "start_at": { + "type": "string", + "format": "date-time", + "description": "UTC Timestamp after which Thunderbird will show the event after startup." + }, + "end_at": { + "type": "string", + "format": "date-time", + "description": "UTC Timestamp after which Thunderbird will never show the event, even if it has never been shown to the user." + }, + "title": { + "type": "string", + "description": "Short sentence describing the event which will be displayed in the Thunderbird UI." + }, + "description": { + "type": "string", + "description": "A short paragraph that can contain HTML and will be displayed in the Thunderbird UI." + }, + "URL": { + "type": "string", + "format": "uri", + "description": "URL to open from the CTA, if any." + }, + "CTA": { + "type": "string", + "description": "Link text to show for the URL." + }, + "severity": { + "enum": [1, 2, 3, 4, 5], + "description": "Severity level, where 1 is the most important/urgent and 5 is the least." + }, + "type": { + "enum": ["donation", "message", "security", "blog"], + "description": "Category of notification." + }, + "targeting": { + "type": "object", + "properties": { + "percent_chance": { + "type": "number", + "minimum": 0, + "maximum": 100 + }, + "exclude": { + "type": "array", + "items": { + "$ref": "#/definitions/profile" + } + }, + "include": { + "type": "array", + "items": { + "$ref": "#/definitions/profile" + } + } + } + } + }, + "required": [ + "id", + "start_at", + "end_at", + "title", + "description", + "severity", + "type", + "targeting" + ], + "dependentRequired": { "CTA": ["URL"] } + }, + "definitions": { + "profile": { + "type": "object", + "properties": { + "locales": { + "type": "array", + "items": { + "type": "string" + } + }, + "versions": { + "type": "array", + "items": { + "type": "string" + } + }, + "channels": { + "type": "array", + "items": { + "enum": ["default", "esr", "release", "beta", "daily"], + "description": "Channel" + } + }, + "operating_systems": { + "type": "array", + "items": { + "enum": [ + "win", + "macosx", + "linux", + "freebsd", + "openbsd", + "netbsd", + "solaris", + "other" + ], + "description": "Operating System" + } + } + } + } + } +}