Skip to content

Commit

Permalink
Merge pull request #32 from praxis/json_schema_support
Browse files Browse the repository at this point in the history
support json-schema methods for blueprints
  • Loading branch information
blanquer committed Aug 21, 2020
2 parents fa6234d + 2b1036e commit a658d74
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## next

## 3.4

* Upgrade to latest Attributor gem (which has JSON-schema support), and add json-schema methods for blueprints.

## 3.3

* Include Attributor::Dumpable in Blueprint, so it renders (semi) correctly if
Expand Down
9 changes: 9 additions & 0 deletions lib/praxis-blueprints/blueprint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,5 +362,14 @@ def validate(context = Attributor::DEFAULT_ROOT_CONTEXT)
def _get_attr(name)
self.send(name)
end

# Delegates the json-schema methods to the underlying attribute/member_type
def self.as_json_schema(**args)
@attribute.type.as_json_schema(args)
end

def self.json_schema_type
@attribute.type.json_schema_type
end
end
end
2 changes: 1 addition & 1 deletion lib/praxis-blueprints/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: true
module Praxis
BLUEPRINTS_VERSION = '3.4'
BLUEPRINTS_VERSION = '3.5'
end
2 changes: 1 addition & 1 deletion praxis-blueprints.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency('randexp', ['~> 0'])
spec.add_runtime_dependency('attributor', ['>= 5.4'])
spec.add_runtime_dependency('attributor', ['>= 5.5'])
spec.add_runtime_dependency('activesupport', ['>= 3'])

spec.add_development_dependency 'bundler'
Expand Down
13 changes: 13 additions & 0 deletions spec/praxis-blueprints/blueprint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -421,4 +421,17 @@
end
end
end

context '.as_json_schema' do
it 'delegates to the attribute type' do
Person.attribute.type.should receive(:as_json_schema)
Person.as_json_schema
end
end
context '.json_schema_type' do
it 'delegates to the attribute type' do
Person.attribute.type.should receive(:json_schema_type)
Person.json_schema_type
end
end
end

0 comments on commit a658d74

Please sign in to comment.