easy_talk 0.1.9 → 0.1.10

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cac3597b203d800e1c15c79ea019a6d81080dd5c5ed669dc96500e262a32a505
4
- data.tar.gz: 626bb67445db8ffa2d41df7a0b82ceba30db827ed0cb610f4d1b382d161a5191
3
+ metadata.gz: 1ebe87803e47220d1a3f6396a1735fd2aa04b3f2b1428bea43cd873cb32f3bca
4
+ data.tar.gz: ecdaaa2801742335160a89a38a92ef9b402be563d3ce0e54c52f3068d75c93ce
5
5
  SHA512:
6
- metadata.gz: e58629e7e0b4aff314f04d0a0d14f3129e0af8b54c23c1d061d57464648aa97caaf2db514353fcf34713d1d14113eb13c599ccc28b6106a3c5f06cd4197671af
7
- data.tar.gz: f3ba1ec6c87ff2028a5bd26f22ebade4446717c8d9e27702c94f5e4080fd951885dd033a0d4f88078d44849cb7b251fc1dbb303f9da84b2a592bf85c1daaf9ef
6
+ metadata.gz: 866e44d124957d2149bd67584c0e35129bd922c98da0bb9d4b37cead66636d84b508290be35b4ce79ad3940bd556585ee604aeb79c220f898450624765e3fd50
7
+ data.tar.gz: 551cd5c6f3de517efd56fadb407fd723de14764d3520b7be7ee73e12a7027d391816452ad13a00752e0fa690d5da2eef4aff2d0b12b585ed686eeb31635875ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## [0.1.10] - 2024-04-29
2
+ - Accept `:optional` key as constraint which excludes property from required node.
3
+ - Spec fixes
1
4
  ## [0.1.9] - 2024-04-29
2
5
  - Added the ability to describe an object schema withing the define_schema block. Example:
3
6
  ```ruby
@@ -11,7 +11,8 @@ module EasyTalk
11
11
  # representing schema properties.
12
12
  COMMON_OPTIONS = {
13
13
  title: { type: T.nilable(String), key: :title },
14
- description: { type: T.nilable(String), key: :description }
14
+ description: { type: T.nilable(String), key: :description },
15
+ optional: { type: T.nilable(T::Boolean), key: :optional }
15
16
  }.freeze
16
17
 
17
18
  attr_reader :name, :schema, :options
@@ -14,7 +14,7 @@ module EasyTalk
14
14
  properties: { type: T::Hash[T.any(Symbol, String), T.untyped], key: :properties },
15
15
  additional_properties: { type: T::Boolean, key: :additionalProperties },
16
16
  subschemas: { type: T::Array[T.untyped], key: :subschemas },
17
- required: { type: T::Array[Symbol], key: :required },
17
+ required: { type: T::Array[T.any(Symbol, String)], key: :required },
18
18
  defs: { type: T.untyped, key: :$defs },
19
19
  allOf: { type: T.untyped, key: :allOf },
20
20
  anyOf: { type: T.untyped, key: :anyOf },
@@ -42,7 +42,9 @@ module EasyTalk
42
42
  end
43
43
 
44
44
  def add_required_property(property_name, options)
45
- return unless options.is_a?(Hash) && !(options[:type].respond_to?(:nilable?) && options[:type].nilable?)
45
+ return if options.is_a?(Hash) && !!(options[:type].respond_to?(:nilable?) && options[:type].nilable?)
46
+
47
+ return if options.respond_to?(:optional?) && options.optional?
46
48
 
47
49
  @required_properties << property_name
48
50
  end
@@ -15,7 +15,8 @@ module EasyTalk
15
15
  max_length: { type: Integer, key: :maxLength },
16
16
  enum: { type: T::Array[String], key: :enum },
17
17
  const: { type: String, key: :const },
18
- default: { type: String, key: :default }
18
+ default: { type: String, key: :default },
19
+ optional: { type: T::Boolean, key: :optional }
19
20
  }.freeze
20
21
 
21
22
  sig { params(name: Symbol, constraints: Hash).void }
@@ -16,8 +16,8 @@ module EasyTalk
16
16
 
17
17
  attr_reader :name, :schema
18
18
 
19
- def initialize(name)
20
- @schema = {}
19
+ def initialize(name, schema = {})
20
+ @schema = schema
21
21
  @name = name
22
22
  end
23
23
 
@@ -39,12 +39,16 @@ module EasyTalk
39
39
  @schema[:properties] ||= {}
40
40
 
41
41
  if block_given?
42
- property_schema = SchemaDefinition.new(name)
42
+ property_schema = SchemaDefinition.new(name, constraints)
43
43
  property_schema.instance_eval(&blk)
44
44
  @schema[:properties][name] = property_schema
45
45
  else
46
46
  @schema[:properties][name] = { type:, constraints: }
47
47
  end
48
48
  end
49
+
50
+ def optional?
51
+ @schema[:optional]
52
+ end
49
53
  end
50
54
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EasyTalk
4
- VERSION = '0.1.9'
4
+ VERSION = '0.1.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_talk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Bayona
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-29 00:00:00.000000000 Z
11
+ date: 2024-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -177,7 +177,6 @@ files:
177
177
  - LICENSE.txt
178
178
  - README.md
179
179
  - Rakefile
180
- - easy_talk.gemspec
181
180
  - lib/easy_talk.rb
182
181
  - lib/easy_talk/builders/all_of_builder.rb
183
182
  - lib/easy_talk/builders/any_of_builder.rb
data/easy_talk.gemspec DELETED
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'lib/easy_talk/version'
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = 'easy_talk'
7
- spec.version = EasyTalk::VERSION
8
- spec.authors = ['Sergio Bayona']
9
- spec.email = ['bayona.sergio@gmail.com']
10
-
11
- spec.summary = 'Generate json-schema from Ruby classes.'
12
- spec.description = 'Generate json-schema from plain Ruby classes.'
13
- spec.homepage = 'https://github.com/sergiobayona/easy_talk'
14
- spec.license = 'MIT'
15
- spec.required_ruby_version = '>= 3.2'
16
-
17
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
18
-
19
- spec.metadata['homepage_uri'] = spec.homepage
20
- spec.metadata['source_code_uri'] = 'https://github.com/sergiobayona/easy_talk'
21
- spec.metadata['changelog_uri'] = 'https://github.com/sergiobayona/easy_talk/blob/main/CHANGELOG.md'
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(__dir__) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (File.expand_path(f) == __FILE__) ||
28
- f.start_with?(*%w[bin/ spec/ .git .github Gemfile])
29
- end
30
- end
31
-
32
- spec.require_paths = ['lib']
33
-
34
- spec.add_dependency 'activesupport', '~> 7.0'
35
- spec.add_dependency 'json-schema', '~> 4'
36
- spec.add_dependency 'sorbet-runtime', '~> 0.5'
37
- spec.add_development_dependency 'pry-byebug', '>= 3.10'
38
- spec.add_development_dependency 'rake', '~> 13.1'
39
- spec.add_development_dependency 'rspec', '~> 3.0'
40
- spec.add_development_dependency 'rspec-json_expectations', '~> 2.0'
41
- spec.add_development_dependency 'rspec-mocks', '~> 3.13'
42
- spec.add_development_dependency 'rubocop', '~> 1.21'
43
- spec.add_development_dependency 'rubocop-rake', '~> 0.6'
44
- spec.add_development_dependency 'rubocop-rspec', '~> 2.29'
45
- end