Skip to content

Commit 43442e8

Browse files
committed
Re-add validator.
1 parent 10e6820 commit 43442e8

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
lines changed

.github/workflows/update.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
uses: ruby/setup-ruby@v1
1616
with:
1717
bundler-cache: true
18+
- name: Download
19+
run: bundle exec rake api:download
1820
- name: Update
1921
run: bundle exec rake api:update
2022
- name: Validate

Rakefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ require 'fileutils'
99
Bundler.setup :default, :development
1010

1111
load 'tasks/download.rake'
12+
load 'tasks/events.rake'
13+
load 'tasks/methods.rake'
14+
load 'tasks/validate.rake'
1215
load 'tasks/update.rake'

tasks/events.rake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require_relative 'lib/slack_api/spec_validator'
2+
3+
namespace :api do
4+
namespace :events do
5+
desc 'Validate scraped events are valid.'
6+
task :validate do
7+
schema = File.read('schemas/events.json')
8+
validator = SlackApi::SpecValidator.new(schema)
9+
Dir.glob('events/**/*.json').each do |file|
10+
abort "Invalid file format: #{file}" unless validator.valid?(file)
11+
end
12+
end
13+
end
14+
end
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
module SlackApi
4+
# Validates JSON against an expected schema
5+
class SpecValidator
6+
def initialize(schema)
7+
@schema = schema
8+
end
9+
10+
def valid?(json)
11+
JSON::Validator.validate(@schema, json)
12+
end
13+
end
14+
end

tasks/methods.rake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require_relative 'lib/slack_api/spec_validator'
2+
3+
namespace :api do
4+
namespace :methods do
5+
desc 'Validate scraped methods are valid.'
6+
task :validate do
7+
schema = File.read('schemas/methods.json')
8+
validator = SlackApi::SpecValidator.new(schema)
9+
Dir.glob('methods/**/*.json').each do |file|
10+
abort "Invalid file format: #{file}" unless validator.valid?(file)
11+
end
12+
end
13+
end
14+
end

tasks/update.rake

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
# frozen_string_literal: true
1+
require_relative 'lib/slack_api/spec_validator'
22

33
namespace :api do
4-
namespace :events do
5-
desc 'Scrape Slack events, replacing previous results.'
6-
task :update do
7-
raise 'This needs to be reimplemented.'
8-
end
4+
desc 'Validate scraped methods and events are valid.'
5+
task :update do
6+
puts "TODO"
97
end
10-
end
8+
end

tasks/validate.rake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require_relative 'lib/slack_api/spec_validator'
2+
3+
namespace :api do
4+
desc 'Validate scraped methods and events are valid.'
5+
task :validate do
6+
Rake::Task['api:methods:validate'].invoke
7+
Rake::Task['api:events:validate'].invoke
8+
end
9+
end

0 commit comments

Comments
 (0)