Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
f8d26ec
Added some fixes for api changes in builder
Haniyya Apr 11, 2019
86c2290
Use forked version of json_schema-builder for testing purposes
stex Apr 15, 2019
098e3a2
updated json-schema_builder revision
stex Apr 15, 2019
e297ed1
Switched from schema-builder to schema-dsl
Haniyya Oct 10, 2019
6f82de5
A lot done here, sorry for the big commit:
Haniyya Oct 14, 2019
1728565
Registered new renderer.
Haniyya Oct 14, 2019
f2b4fd0
Made expand_partials private and refactored it a bit.
Haniyya Oct 14, 2019
dd3c3f5
Added type_defaults integration to templates.
Haniyya Oct 14, 2019
6b74f13
Made schemas builders and added a initialize default that should only be
Haniyya Oct 15, 2019
0f47223
Added root option to context so that a context can now know if it is
Haniyya Oct 15, 2019
6029da8
Integrated template config with dsl config.
Haniyya Oct 15, 2019
fa6fa12
Added SchemaTemplates.enable! to easily enable the addon after a reset.
Haniyya Oct 15, 2019
3d93620
Removed obsolete files.
Haniyya Oct 15, 2019
81cb636
Changed specs so that they expect object defaults to apply if there a…
Haniyya Oct 15, 2019
3fce272
Clear the type defaults before each example.
Haniyya Oct 15, 2019
bb8e734
Added test renderer that can render without templates enabled.
Haniyya Oct 15, 2019
184d255
Added untyped 'Locals' node to support syntax where partials and locals
Haniyya Oct 17, 2019
0782095
Added solargraph config to ignore.
Haniyya Oct 17, 2019
5e493aa
The big redoc commit.
Haniyya Oct 18, 2019
bc9afde
Switched dependency to published dsl.
Haniyya Nov 14, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@

# rspec failure tracking
.rspec_status

.solargraph.yml
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ source 'https://rubygems.org'

git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }

# gem 'json-schema_builder', git: 'https://github.com/Haniyya/json-schema_builder', branch: '9-endless-recursion-fix'

# Specify your gem's dependencies in json-schema_templates.gemspec
gemspec
57 changes: 44 additions & 13 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
PATH
remote: .
specs:
json-schema_templates (0.1.0)
json-schema_builder (~> 0.8.2)
json-schema_templates (0.2.0)
json-schema (< 3)
json-schema_dsl (~> 1.0)

GEM
remote: https://rubygems.org/
specs:
activesupport (5.2.2)
activesupport (5.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
addressable (2.6.0)
public_suffix (>= 2.0.2, < 4.0)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
ast (2.4.0)
byebug (11.0.0)
coderay (1.1.2)
concurrent-ruby (1.1.4)
concurrent-ruby (1.1.5)
diff-lcs (1.3)
i18n (1.6.0)
docile (1.3.2)
dry-configurable (0.8.3)
concurrent-ruby (~> 1.0)
dry-core (~> 0.4, >= 0.4.7)
dry-container (0.7.2)
concurrent-ruby (~> 1.0)
dry-configurable (~> 0.1, >= 0.1.3)
dry-core (0.4.9)
concurrent-ruby (~> 1.0)
dry-equalizer (0.2.2)
dry-inflector (0.2.0)
dry-logic (1.0.3)
concurrent-ruby (~> 1.0)
dry-core (~> 0.2)
dry-equalizer (~> 0.2)
dry-struct (1.0.0)
dry-core (~> 0.4, >= 0.4.3)
dry-equalizer (~> 0.2)
dry-types (~> 1.0)
ice_nine (~> 0.11)
dry-types (1.2.0)
concurrent-ruby (~> 1.0)
dry-container (~> 0.3)
dry-core (~> 0.4, >= 0.4.4)
dry-equalizer (~> 0.2, >= 0.2.2)
dry-inflector (~> 0.1, >= 0.1.2)
dry-logic (~> 1.0, >= 1.0.2)
i18n (1.7.0)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
jaro_winkler (1.5.2)
json-schema (2.8.1)
addressable (>= 2.4)
json-schema_builder (0.8.2)
activesupport (>= 4.0)
json-schema (>= 2.1)
json-schema_dsl (1.0.0)
activesupport (< 6.0)
docile (< 2)
dry-struct (~> 1.0)
dry-types (~> 1.0)
method_source (0.9.2)
minitest (5.11.3)
minitest (5.13.0)
parallel (1.14.0)
parser (2.6.0.0)
ast (~> 2.4.0)
Expand All @@ -40,7 +71,7 @@ GEM
byebug (~> 11.0)
pry (~> 0.10)
psych (3.1.0)
public_suffix (3.0.3)
public_suffix (4.0.1)
rainbow (3.0.0)
rake (10.5.0)
rspec (3.8.0)
Expand Down Expand Up @@ -88,4 +119,4 @@ DEPENDENCIES
rubocop (~> 0.60)

BUNDLED WITH
1.17.1
1.17.2
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Json::SchemaTemplates

Built on top of [JSON::SchemaBuilder](https://github.com/parrish/json-schema_builder), `JSON::SchemaTemplates`
Built on top of [JSON::SchemaDsl](https://github.com/parrish/json-schema_builder), `JSON::SchemaTemplates`
contains some quality of life improvements when writing JSON schemas for Rails applications.

It is based purely on Ruby classes, but handles them as templates and partials,
Expand Down
4 changes: 3 additions & 1 deletion json-schema_templates.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ['>= 2.5', '< 3']

spec.add_dependency 'json-schema_builder', '~> 0.8.2'
# spec.add_dependency 'json-schema_builder', '~> 0.8.2'

spec.add_dependency 'json-schema', '< 3'
spec.add_dependency 'json-schema_dsl', '~> 1.0'
spec.add_development_dependency 'bundler', '~> 1.17'
spec.add_development_dependency 'pry', '~> 0.12'
spec.add_development_dependency 'pry-byebug', '~> 3.6'
Expand Down
14 changes: 11 additions & 3 deletions lib/json/schema_templates.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

require 'json/schema_builder'
require 'json-schema'
require 'json/schema_dsl'

%w[base additional_types builder_overrides context configuration].each do |file|
%w[base context configuration types renderers resolver].each do |file|
require "json/schema_templates/#{file}"
end

Expand All @@ -20,8 +21,15 @@ def self.configure
yield(configuration)
end

def self.enable!
JSON::SchemaDsl.register_type(Types::Email)
JSON::SchemaDsl.register_type(Types::DateTime)
JSON::SchemaDsl.register_type(Types::Partial)
JSON::SchemaDsl.registered_renderers.prepend(Renderers::PartialExpander)
end

#
# @return [JSON::SchemaTemplates::Context, nil] the requested schema or +nil+ if it couldn't be found.
# @return [JSON::SchemaDsl::Builder, nil] the requested schema or +nil+ if it couldn't be found.
#
# @param [String] schema_path
# The requested schema relative to the schema base path.
Expand Down
35 changes: 0 additions & 35 deletions lib/json/schema_templates/additional_types.rb

This file was deleted.

41 changes: 26 additions & 15 deletions lib/json/schema_templates/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,51 @@

module JSON
module SchemaTemplates
#
# Class to hold dsl definitions to be evaluated by contexts.
#
class Base
include JSON::SchemaDsl
attr_reader :context

class << self
#
# Defines a new JSON schema
#
# @return [JSON::SchemaDsl::Builder] The resulting builder structure from the schema.
# @param [Hash] default_locals
# Can be used to define default locals to be available within the schema definition.
# Any value given here is automatically overridden by a local passed in through a `partial` call
# or a corresponding object call with `partial: 'something'`
#
def schema(**default_locals, &block)
define_method :schema do |**locals|
context.tap_eval(locals: default_locals.merge(locals), &block)
context.context_eval(locals: default_locals.merge(locals), &block)
end
end
end
#
# @!method schema(**locals)
# @param [Hash] locals The locals applied to this schema.
# @see Types::Locals
# @return [Hash] The resulting ast from the definition evaluated
# in this schemas context.

def initialize(context = Context.new)
#
# @param [Context] context The context which will be used to evaluate the definition from
# #schema. Defaults to a root context that is supplied with the self_partial of this schema
# and is initialized in root mode.
#
def initialize(context = Context.new(self_partial, self, root: true))
@context = context
@context.current_schema = self
end

#
# @return [Hash] A partial node that represents this current schema.
# @see Types::Partial
#
def self_partial
{name: path.split('/').last, type: 'partial', current_dir: dirname}
end

#
Expand All @@ -39,18 +62,6 @@ def dirname
def path
self.class.to_s.underscore
end

def method_missing(meth, *args, &block)
if context.respond_to?(meth)
context.public_send(meth, *args, &block)
else
super
end
end

def respond_to_missing?(meth, include_private = false)
context.respond_to?(meth, include_private)
end
end
end
end
57 changes: 0 additions & 57 deletions lib/json/schema_templates/builder_overrides.rb

This file was deleted.

Loading