jsonschema_serializer 0.0.5 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 21bc2f5a22f0f4da198b981fd6be8aade090d4fa
4
- data.tar.gz: 9d08bc5bf5c24b2bd5cec7ac1f7dfb8914374708
3
+ metadata.gz: 0bf44f052005e55102e26a83b65f8dd7652551e5
4
+ data.tar.gz: 36455d91f261bc831b86247866d44ff3a22927aa
5
5
  SHA512:
6
- metadata.gz: 55d072167b46b7999861a0d6c152753ca46a490b3f3e0386867dfc6d084c9cfc287af7acf4248f6e6039d74ab84133c59f11e19ee79b2fe52caa0c259875f62f
7
- data.tar.gz: 21b742e2afb0e3598667b4f3e9c75017cdf0096dc7a51808d99a1b4b669b256be42c9ebec4e7df479f47e92c3dcf552010ec3d0fa36dd3256428258e8026f0fc
6
+ metadata.gz: c76364ae191a25e98d85b4c7961230f2f916f94341dd5c6d871e8bc1e67ba313452ee4c95ca8b591faf9ff9f88359ff6f943f55243f3b94caf6353cabb39abad
7
+ data.tar.gz: 486c1a061008be82fd861369d28a607c3bec312a6403d4fff32e66245a09e02bf7242740378ef67a7a5adfd21d34482194878953b7df5b4fd4433227600284ac
data/README.md CHANGED
@@ -3,8 +3,13 @@
3
3
  [![Build Status](https://travis-ci.org/mberlanda/jsonschema_serializer.svg?branch=master)](https://travis-ci.org/mberlanda/jsonschema_serializer)
4
4
  [![Gem Version](https://badge.fury.io/rb/jsonschema_serializer.svg)](https://badge.fury.io/rb/jsonschema_serializer)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/7312071a0865c70f5d60/maintainability)](https://codeclimate.com/github/mberlanda/jsonschema_serializer/maintainability)
6
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/7312071a0865c70f5d60/test_coverage)](https://codeclimate.com/github/mberlanda/jsonschema_serializer/test_coverage)
6
7
 
7
8
  This purpose of this gem is to generate [JsonSchema](http://json-schema.org/).
9
+ This can be achieved with a builder class or an `ActiveRecord` wrapper.
10
+ The gem is available for both Rails 4, 5 or in Ruby standalone projects.
11
+
12
+ Since the project is still at an early stage, please do not hesitate to [open issues / feature requests](https://github.com/mberlanda/jsonschema_serializer/issues) or fork this repo for pull requests.
8
13
 
9
14
  ## Installation
10
15
 
@@ -79,7 +84,7 @@ schema.to_json
79
84
 
80
85
  At this stage, a first usage within a Rails application could be a rake task dumping the schemas inside the public folder.
81
86
 
82
- ```rb
87
+ ```ruby
83
88
  # lib/tasks/jsonschemas.rake
84
89
  require 'fileutils'
85
90
 
@@ -116,3 +121,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
116
121
  ## Contributing
117
122
 
118
123
  Bug reports and pull requests are welcome on GitHub at https://github.com/mberlanda/jsonschema_serializer.
124
+ Please ensure to keep the test coverage at 100% and follow the angularjs [commit message conv.entions](https://gist.github.com/stephenparish/9941e89d80e2bc58a153#subject-line).
@@ -9,13 +9,12 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Mauro Berlanda"]
10
10
  spec.email = ["mauro.berlanda@gmail.com"]
11
11
 
12
- spec.summary = %q{The purpose of this gem is to generate JsonSchema}
12
+ spec.summary = %q{Generate JsonSchema in Rails or standalone Ruby}
13
13
  spec.description = <<-EOT
14
- The goal behind this gem is to generate JsonSchema.
15
- This can be done using thanks to a Builder class or
16
- an ActiveRecord serialization module.
17
- The project is still at an early stage so all PR or feature request will
18
- be welcome on the Github repo
14
+ This gem allows to generate JsonSchema thanks to a Builder class or
15
+ an ActiveRecord serialization class. It can be used in Rails 4, 5 or
16
+ Ruby standalone projects.
17
+ The output validation is done agains json-schema.
19
18
  EOT
20
19
  spec.homepage = "https://github.com/mberlanda/jsonschema_serializer"
21
20
  spec.licenses = ['MIT']
@@ -30,9 +29,7 @@ Gem::Specification.new do |spec|
30
29
  # "public gem pushes."
31
30
  # end
32
31
 
33
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
34
- f.match(%r{^(test|spec|features)/})
35
- end
32
+ spec.files = Dir.glob("lib/**/*") + %w(jsonschema_serializer.gemspec README.md)
36
33
  spec.bindir = "exe"
37
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
38
35
  spec.require_paths = ["lib"]
@@ -40,6 +37,9 @@ Gem::Specification.new do |spec|
40
37
  spec.add_development_dependency "bundler", "~> 1.16"
41
38
  spec.add_development_dependency "rake", "~> 10.0"
42
39
  spec.add_development_dependency "rspec", "~> 3.0"
40
+ spec.add_development_dependency "json-schema", "~> 2.8"
41
+ spec.add_development_dependency "simplecov", "~> 0.16"
42
+ spec.add_development_dependency "appraisal", "~> 2.2"
43
43
 
44
44
  spec.extra_rdoc_files = ['README.md']
45
45
  spec.rdoc_options << '--title' << 'Jsonschema Serializer' <<
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'jsonschema_serializer/version'
2
4
  require 'jsonschema_serializer/builder'
3
5
  require 'jsonschema_serializer/active_record'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'builder'
2
4
 
3
5
  module JsonschemaSerializer
@@ -43,7 +45,7 @@ module JsonschemaSerializer
43
45
  def format_schema_attributes(klass, builder)
44
46
  builder.title schema_title(klass)
45
47
  required(klass).tap do |required|
46
- builder.required required unless required.empty?
48
+ builder.required(*required) unless required.empty?
47
49
  end
48
50
  end
49
51
 
@@ -78,11 +80,12 @@ module JsonschemaSerializer
78
80
  # Params:
79
81
  # +columns+:: +Array+ column names as +Symbol+
80
82
 
81
- # Extract required attributes from ActiveRecord class implementation
83
+ # Filter required class attributes with only/filters attributes
82
84
  # This method can be overridden when inheriting from this class
83
85
  #
84
86
  # Params:
85
87
  # +klass+:: +ActiveRecord::Base+ class name
88
+
86
89
  def required(klass)
87
90
  required_from_class(klass).tap do |req|
88
91
  return req & @only if @only
@@ -90,6 +93,12 @@ module JsonschemaSerializer
90
93
  end
91
94
  end
92
95
 
96
+ # Extract required attributes from ActiveRecord class implementation
97
+ # This method can be overridden when inheriting from this class
98
+ #
99
+ # Params:
100
+ # +klass+:: +ActiveRecord::Base+ class name
101
+
93
102
  def required_from_class(klass)
94
103
  klass.validators.select do |validator|
95
104
  validator.class.to_s == 'ActiveRecord::Validations::PresenceValidator'
@@ -119,7 +128,8 @@ module JsonschemaSerializer
119
128
  decimal: :number,
120
129
  float: :number,
121
130
  integer: :integer,
122
- text: :string
131
+ text: :string,
132
+ varchar: :string
123
133
  }.freeze
124
134
 
125
135
  # Format a ActiveRecord::ConnectionAdapters::<Adapter>::Column as an Hash
@@ -141,7 +151,9 @@ module JsonschemaSerializer
141
151
  # +col+:: +ActiveRecord::ConnectionAdapters::<Adapter>::Column+ column
142
152
 
143
153
  def sql_type(col)
144
- col.sql_type_metadata.type
154
+ return col.sql_type_metadata.type if col.respond_to?(:sql_type_metadata)
155
+ # Rails 4 backward compatibility
156
+ col.sql_type.downcase.to_sym
145
157
  end
146
158
  end
147
159
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module JsonschemaSerializer
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JsonschemaSerializer
2
- VERSION = '0.0.5'.freeze # :nodoc:
4
+ VERSION = '0.1.0'.freeze # :nodoc:
3
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonschema_serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mauro Berlanda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,12 +52,53 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: json-schema
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.8'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.16'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.16'
83
+ - !ruby/object:Gem::Dependency
84
+ name: appraisal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.2'
55
97
  description: |2
56
- The goal behind this gem is to generate JsonSchema.
57
- This can be done using thanks to a Builder class or
58
- an ActiveRecord serialization module.
59
- The project is still at an early stage so all PR or feature request will
60
- be welcome on the Github repo
98
+ This gem allows to generate JsonSchema thanks to a Builder class or
99
+ an ActiveRecord serialization class. It can be used in Rails 4, 5 or
100
+ Ruby standalone projects.
101
+ The output validation is done agains json-schema.
61
102
  email:
62
103
  - mauro.berlanda@gmail.com
63
104
  executables: []
@@ -65,16 +106,7 @@ extensions: []
65
106
  extra_rdoc_files:
66
107
  - README.md
67
108
  files:
68
- - ".gitignore"
69
- - ".rspec"
70
- - ".rubocop.yml"
71
- - ".travis.yml"
72
- - CHANGELOG.md
73
- - Gemfile
74
109
  - README.md
75
- - Rakefile
76
- - bin/console
77
- - bin/setup
78
110
  - jsonschema_serializer.gemspec
79
111
  - lib/jsonschema_serializer.rb
80
112
  - lib/jsonschema_serializer/active_record.rb
@@ -106,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
138
  version: '0'
107
139
  requirements: []
108
140
  rubyforge_project:
109
- rubygems_version: 2.4.5.4
141
+ rubygems_version: 2.6.14
110
142
  signing_key:
111
143
  specification_version: 4
112
- summary: The purpose of this gem is to generate JsonSchema
144
+ summary: Generate JsonSchema in Rails or standalone Ruby
113
145
  test_files: []
data/.gitignore DELETED
@@ -1,16 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- # rspec failure tracking
11
- .rspec_status
12
- .byebug_history
13
- .ruby-version
14
- .gem
15
-
16
- Gemfile.lock
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,27 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
- Exclude:
4
- - bin/*
5
- - "*.gemspec"
6
- - Gemfile
7
- - Rakefile
8
-
9
- Metrics/BlockLength:
10
- Exclude:
11
- - spec/**/*
12
-
13
- Metrics/LineLength:
14
- Max: 90
15
-
16
- Style/Documentation:
17
- Enabled: true
18
-
19
- Style/FrozenStringLiteralComment:
20
- Enabled: false
21
-
22
- Style/ModuleFunction:
23
- Exclude:
24
- - lib/jsonschema_serializer/active_record.rb
25
-
26
- Style/SymbolArray:
27
- EnforcedStyle: brackets
@@ -1,22 +0,0 @@
1
- sudo: false
2
-
3
- language: ruby
4
-
5
- jobs:
6
- include:
7
- - rvm: 2.1.5
8
- gemfile: Gemfile
9
- - rvm: 2.2.7
10
- gemfile: Gemfile
11
- - rvm: 2.3.4
12
- gemfile: Gemfile
13
- - rvm: 2.4.1
14
- gemfile: Gemfile
15
- - rvm: 2.5.0
16
- gemfile: Gemfile
17
- - rvm: ruby-head
18
- gemfile: Gemfile
19
- - rvm: jruby-9.0.5.0
20
- gemfile: Gemfile
21
-
22
- before_install: gem install bundler -v 1.16.1
@@ -1,27 +0,0 @@
1
- # Changelog
2
-
3
- ## v 0.0.5 (2018-05-23)
4
-
5
- - json pretty generation by default
6
- - added a Rails rake task example in the README.md
7
- - added schema `title` and `required` attributes
8
- - refactored `from_active_record` method in `from_model`
9
- - manipulate a dup of table columns
10
-
11
- ## v 0.0.4 (2018-05-22)
12
-
13
- - corrected `ActiveRecord::ConnectionAdapters::SqlTypeMetadata` reference in `JsonschemaSerializer::ActiveRecord`
14
-
15
- ## v 0.0.3 (2018-05-21)
16
-
17
- - improved documentation on existing code base
18
- - refactored `JsonschemaSerializer::ActiveRecord` as a `class`
19
-
20
- ## v 0.0.2 (2018-05-20)
21
-
22
- - basic rDoc comments for documentation
23
-
24
- ## v 0.0.1 (2018-05-20)
25
-
26
- - basic implementation of `JsonschemaSerializer::Builder`
27
- - POC implementation of a `JsonschemaSerializer::ActiveRecord` module
data/Gemfile DELETED
@@ -1,8 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- # Specify your gem's dependencies in jsonschema_serializer.gemspec
6
- gemspec
7
-
8
- gem 'rubocop', '~> 0.55.0'
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "jsonschema_serializer"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here