json-schema_dsl 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a4440ff6f54f529a109585c1730238dc271eea973943de58eec898d3584436ab
4
+ data.tar.gz: ef8d143006c60e320b8fd31b07128362be8bdc9c1c481f611519f02d386b1f17
5
+ SHA512:
6
+ metadata.gz: 4d260d9c2eb4ac92256a1c8d3408fc2d197d8f21cf224c1fc517605d2cc19fd611d92d5e2822d20c596d1ef428e6e3276de8f8527b7e5ccb3035a331caa5efff
7
+ data.tar.gz: fa581ea3eefe8ec1633fc465360168f7350c879409824d45748ca6d5ad7a7a818198f13394b768892e1c83de231a5f29478b25e7d4e6fbb53bc9598471c3c1b9
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,30 @@
1
+ # This file is a template, and might need editing before it works on your project.
2
+ # Official language image. Look for the different tagged releases at:
3
+ # https://hub.docker.com/r/library/ruby/tags/
4
+ image: "ruby:2.6"
5
+
6
+ include:
7
+ - template: Code-Quality.gitlab-ci.yml
8
+
9
+ # Cache gems in between builds
10
+ cache:
11
+ paths:
12
+ - vendor/ruby
13
+
14
+ # This is a basic example for a gem or script which doesn't use
15
+ # services such as redis or postgres
16
+ before_script:
17
+ - ruby -v # Print out ruby version for debugging
18
+ # Uncomment next line if your rails app needs a JS runtime:
19
+ # - apt-get update -q && apt-get install nodejs -yqq
20
+ - gem install bundler -v '2.0.2'
21
+ - bundle install -j $(nproc) --path vendor # Install dependencies into ./vendor/ruby
22
+
23
+ # Optional - Delete if not using `rubocop`
24
+ rubocop:
25
+ script:
26
+ - bundle exec rubocop
27
+
28
+ rspec:
29
+ script:
30
+ - bundle exec rspec spec
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,19 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ require: rubocop-rspec
3
+
4
+ Metrics/BlockLength:
5
+ ExcludedMethods: ['describe', 'context', 'let']
6
+
7
+ RSpec/NestedGroups:
8
+ Max: 8
9
+
10
+ RSpec/ContextWording:
11
+ Prefixes:
12
+ - when
13
+ - with
14
+ - without
15
+ - and
16
+ - while
17
+
18
+ RSpec/DescribeClass:
19
+ Enabled: false
@@ -0,0 +1,13 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2019-04-26 19:48:42 +0200 using RuboCop version 0.65.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
11
+ # URISchemes: http, https
12
+ Metrics/LineLength:
13
+ Max: 96
@@ -0,0 +1,15 @@
1
+ ---
2
+ include:
3
+ - "**/*.rb"
4
+ exclude:
5
+ - spec/**/*
6
+ - test/**/*
7
+ - vendor/**/*
8
+ - ".bundle/**/*"
9
+ require: []
10
+ domains: []
11
+ reporters:
12
+ - rubocop
13
+ - require_not_found
14
+ require_paths: []
15
+ max_files: 5000
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at paul.martensen@gmx.de. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in json-schema_dsl.gemspec
6
+ gemspec
@@ -0,0 +1,114 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ json-schema_dsl (1.0.0)
5
+ activesupport (< 6.0)
6
+ docile (< 2)
7
+ dry-struct (~> 1.0)
8
+ dry-types (~> 1.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (5.2.3)
14
+ concurrent-ruby (~> 1.0, >= 1.0.2)
15
+ i18n (>= 0.7, < 2)
16
+ minitest (~> 5.1)
17
+ tzinfo (~> 1.1)
18
+ ast (2.4.0)
19
+ byebug (11.0.1)
20
+ coderay (1.1.2)
21
+ concurrent-ruby (1.1.5)
22
+ diff-lcs (1.3)
23
+ docile (1.3.2)
24
+ dry-configurable (0.8.3)
25
+ concurrent-ruby (~> 1.0)
26
+ dry-core (~> 0.4, >= 0.4.7)
27
+ dry-container (0.7.2)
28
+ concurrent-ruby (~> 1.0)
29
+ dry-configurable (~> 0.1, >= 0.1.3)
30
+ dry-core (0.4.9)
31
+ concurrent-ruby (~> 1.0)
32
+ dry-equalizer (0.2.2)
33
+ dry-inflector (0.2.0)
34
+ dry-logic (1.0.3)
35
+ concurrent-ruby (~> 1.0)
36
+ dry-core (~> 0.2)
37
+ dry-equalizer (~> 0.2)
38
+ dry-struct (1.0.0)
39
+ dry-core (~> 0.4, >= 0.4.3)
40
+ dry-equalizer (~> 0.2)
41
+ dry-types (~> 1.0)
42
+ ice_nine (~> 0.11)
43
+ dry-types (1.2.0)
44
+ concurrent-ruby (~> 1.0)
45
+ dry-container (~> 0.3)
46
+ dry-core (~> 0.4, >= 0.4.4)
47
+ dry-equalizer (~> 0.2, >= 0.2.2)
48
+ dry-inflector (~> 0.1, >= 0.1.2)
49
+ dry-logic (~> 1.0, >= 1.0.2)
50
+ i18n (1.6.0)
51
+ concurrent-ruby (~> 1.0)
52
+ ice_nine (0.11.2)
53
+ jaro_winkler (1.5.3)
54
+ method_source (0.9.2)
55
+ minitest (5.11.3)
56
+ parallel (1.18.0)
57
+ parser (2.6.5.0)
58
+ ast (~> 2.4.0)
59
+ pry (0.12.2)
60
+ coderay (~> 1.1.0)
61
+ method_source (~> 0.9.0)
62
+ pry-byebug (3.7.0)
63
+ byebug (~> 11.0)
64
+ pry (~> 0.10)
65
+ rainbow (3.0.0)
66
+ rake (10.5.0)
67
+ rspec (3.8.0)
68
+ rspec-core (~> 3.8.0)
69
+ rspec-expectations (~> 3.8.0)
70
+ rspec-mocks (~> 3.8.0)
71
+ rspec-core (3.8.0)
72
+ rspec-support (~> 3.8.0)
73
+ rspec-expectations (3.8.3)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-mocks (3.8.0)
77
+ diff-lcs (>= 1.2.0, < 2.0)
78
+ rspec-support (~> 3.8.0)
79
+ rspec-support (3.8.0)
80
+ rubocop (0.74.0)
81
+ jaro_winkler (~> 1.5.1)
82
+ parallel (~> 1.10)
83
+ parser (>= 2.6)
84
+ rainbow (>= 2.2.2, < 4.0)
85
+ ruby-progressbar (~> 1.7)
86
+ unicode-display_width (>= 1.4.0, < 1.7)
87
+ rubocop-rspec (1.36.0)
88
+ rubocop (>= 0.68.1)
89
+ ruby-progressbar (1.10.1)
90
+ spring (2.0.2)
91
+ activesupport (>= 4.2)
92
+ stackprof (0.2.13)
93
+ thread_safe (0.3.6)
94
+ tzinfo (1.2.5)
95
+ thread_safe (~> 0.1)
96
+ unicode-display_width (1.6.0)
97
+
98
+ PLATFORMS
99
+ ruby
100
+
101
+ DEPENDENCIES
102
+ bundler (~> 2.0)
103
+ json-schema_dsl!
104
+ pry
105
+ pry-byebug
106
+ rake (~> 10.0)
107
+ rspec (~> 3.0)
108
+ rubocop (= 0.74.0)
109
+ rubocop-rspec (= 1.36.0)
110
+ spring
111
+ stackprof
112
+
113
+ BUNDLED WITH
114
+ 2.0.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Paul Martensen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,215 @@
1
+ # Json::SchemaDsl
2
+
3
+ `JSON::SchemaDsl` is a gem that gives you the ability to simply and comfortably
4
+ define json-schemas in ruby. It will type-check and coerce the attributes of
5
+ your definitions and gives you an easy to extend and performant way to generate
6
+ schemas.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'json-schema_dsl'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install json-schema_dsl
23
+
24
+ ## Usage
25
+
26
+ To use the gem include the main module into a class of yours:
27
+
28
+ ```rb
29
+ class Builder
30
+ include JSON::SchemaDsl
31
+ end
32
+ ```
33
+
34
+ Now that class has the ability to define new schemas for you.
35
+
36
+ ```rb
37
+ Builder.new.object do
38
+ object :meta do
39
+ string :response_code
40
+ integer :returned_count
41
+ end
42
+
43
+ array :data do
44
+ items do
45
+ object do
46
+ string :name, required: true
47
+ integer :id, minimum: 0
48
+ end
49
+ end
50
+ end
51
+ end.as_json
52
+ ```
53
+
54
+ Will generate
55
+
56
+ ```js
57
+ {
58
+ type: object,
59
+ properties: {
60
+ meta: {
61
+ type: object,
62
+ properties: {
63
+ response_code: {
64
+ type: string
65
+ },
66
+ returned_count: {
67
+ type: integer
68
+ }
69
+ }
70
+ },
71
+ data: {
72
+ type: array,
73
+ items: {
74
+ type: object,
75
+ required: [
76
+ name
77
+ ],
78
+ properties: {
79
+ name: {
80
+ type: string
81
+ },
82
+ id: {
83
+ type: integer,
84
+ minimum: 0
85
+ }
86
+ }
87
+ }
88
+ }
89
+ }
90
+ }
91
+ ```
92
+
93
+ ### Helper methods
94
+
95
+ You can define helper methods on your builder to dry up your definitions.
96
+ ```rb
97
+ class Builder
98
+ include JSON::SchemaDsl
99
+
100
+ def book
101
+ object do
102
+ string :author
103
+ string :title
104
+ end
105
+ end
106
+ end
107
+
108
+ Builder.new.array do
109
+ items { book }
110
+ end
111
+ ```
112
+ Note that to attach the object to the definition that calls the helper method,
113
+ it has to return a `JSON::Schema::Entity`. If the return value is used to
114
+ construct another entity, this is not necessary.
115
+ ```js
116
+ {
117
+ type: array,
118
+ items: {
119
+ type: object,
120
+ properties: {
121
+ author: {
122
+ type: string
123
+ },
124
+ title: {
125
+ type: string
126
+ }
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ ### Defaults
133
+
134
+ In an initializer, you can change default values for certain types of entities:
135
+ ```rb
136
+ # Adding new defaults for object
137
+ JSON::SchemaDsl.add_defaults_for(:object, {additional_properties: false})
138
+
139
+ Builder.new.object
140
+ ```
141
+ This will give the object the property `additionalProperties` with the value
142
+ `false`.
143
+ ```js
144
+ {
145
+ type: object,
146
+ additionalProperties: false
147
+ }
148
+ ```
149
+
150
+ ## Extending the gem
151
+
152
+ You an add additional types and renderers to the gem by registering them:
153
+ ```rb
154
+ # For now, types have to subclass Entity
155
+ # For this example we can define an email type
156
+ class Email < JSON::SchemaDsl::String
157
+ def self.type_method_name
158
+ 'email'
159
+ end
160
+
161
+ def self.infer_type
162
+ 'string'
163
+ end
164
+
165
+ attribute(:format, JSON::SchemaDsl::Types::String.default('e-mail'))
166
+ end
167
+ JSON::SchemaDsl.register_type(Email)
168
+ ```
169
+ Now you can use email in all your builders using the method name:
170
+ ```rb
171
+ Builder.new.object do
172
+ email :address
173
+ end
174
+ ```
175
+ Will generate
176
+ ```js
177
+ {
178
+ type: object,
179
+ properties: {
180
+ address: {
181
+ type: string,
182
+ format: e-mail
183
+ }
184
+ }
185
+ }
186
+ ```
187
+
188
+ To just build schemas on the fly without setting up a new class, use
189
+ `JSON::SchemaDsl.proxy` which will return a new proxy-builder that enables
190
+ access to the DSL.
191
+
192
+ ```ruby
193
+ JSON::SchemaDsl.proxy.object do
194
+ string :author
195
+ string :title
196
+ end
197
+ ```
198
+
199
+ ## Development
200
+
201
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
202
+
203
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
204
+
205
+ ## Contributing
206
+
207
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/json-schema_dsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
208
+
209
+ ## License
210
+
211
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
212
+
213
+ ## Code of Conduct
214
+
215
+ Everyone interacting in the Json::SchemaDsl project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/json-schema_dsl/blob/master/CODE_OF_CONDUCT.md).