taro 2.4.0 → 2.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c7750f1403fa65519d22915908d5aeb6cf5bbeec5497d68369bf5a4e37fb0e8
4
- data.tar.gz: 0b6d6b440c1f4fcdb965af8fb1aaf2d26f2ca3a9d2a2fb924bfe9456cb811090
3
+ metadata.gz: d8f629d8573ed34c2d60303a387e99cae4cc9fcb0b14901d7080def1e27d0d90
4
+ data.tar.gz: 40c3ae606ade65922c5b69f9dd86353f2740d061b6d7094f61abe906e5f9198f
5
5
  SHA512:
6
- metadata.gz: 1f37ffe80f9f14ef49bd3131f0a64f5254219c4851de19ec6523143d508440cb263741c2ca56858eeff917cf0a4d1002b642b4e6f87498e47b62b3ffc5fbc4c8
7
- data.tar.gz: 59fbfef1126825880c2d5b64b1d2a3799c25502d094f9758fa9181d7e1e3fa44b2b2504ccbf24c1d18925a5e53ceef1e1ca309cd8980f8950d385d1f3197aadb
6
+ metadata.gz: 34b8e8d9ef5c2f016f56a887b674fa243ae6074fc59e4d29a1cb1873c4dfc3e87d8c24a37dd93a461ad71fc0fd38849462360bed7f6f9a1cca89e37fb3ad192b
7
+ data.tar.gz: d99f3bdc2e40e555a1a0b54dcac6a62d5774b6ae2c7c0d5e05c5ee0f1457864af696b37949173d8189769b03b5d9ce589eb1f49d855209c5c2bccadf32b51d84
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [2.5.0] - 2025-04-16
4
+
5
+ ### Added
6
+
7
+ - Support for setting `openapi_format` for types and during export
8
+
3
9
  ## [2.4.0] - 2025-03-11
4
10
 
5
11
  ### Added
data/README.md CHANGED
@@ -410,7 +410,6 @@ end
410
410
  - mixed arrays
411
411
  - mixed enums
412
412
  - nullable enums
413
- - string format specifications (e.g. binary, int64, password ...)
414
413
  - string minLength and maxLength (substitute: `self.pattern = /\A.{3,5}\z/`)
415
414
  - number minimum, exclusiveMinimum, maximum, multipleOf
416
415
  - readOnly, writeOnly
@@ -129,7 +129,7 @@ class Taro::Export::OpenAPIv3 < Taro::Export::Base # rubocop:disable Metrics/Cla
129
129
 
130
130
  def export_type(type)
131
131
  if type < Taro::Types::ScalarType && !custom_scalar_type?(type)
132
- { type: type.openapi_type }
132
+ { type: type.openapi_type, format: type.openapi_format }.compact
133
133
  else
134
134
  extract_component_ref(type)
135
135
  end
@@ -148,7 +148,7 @@ class Taro::Export::OpenAPIv3 < Taro::Export::Base # rubocop:disable Metrics/Cla
148
148
  end
149
149
 
150
150
  def export_scalar_field(field)
151
- base = { type: field.openapi_type }
151
+ base = { type: field.openapi_type, format: field.openapi_format }.compact
152
152
  # Using oneOf seems more correct than an array of types
153
153
  # as it puts props like format together with the main type.
154
154
  # https://github.com/OAI/OpenAPI-Specification/issues/3148
@@ -17,6 +17,7 @@ Taro::Types::BaseType = Struct.new(:object) do
17
17
  extend Taro::Types::Shared::Description
18
18
  extend Taro::Types::Shared::Equivalence
19
19
  extend Taro::Types::Shared::Name
20
+ extend Taro::Types::Shared::OpenAPIFormat
20
21
  extend Taro::Types::Shared::OpenAPIName
21
22
  extend Taro::Types::Shared::OpenAPIType
22
23
  extend Taro::Types::Shared::Rendering
@@ -30,6 +30,10 @@ Taro::Types::Field = Data.define(:name, :type, :null, :method, :default, :enum,
30
30
  type.openapi_type
31
31
  end
32
32
 
33
+ def openapi_format
34
+ type.openapi_format
35
+ end
36
+
33
37
  private
34
38
 
35
39
  def coerce_to_enum(arg)
@@ -0,0 +1,61 @@
1
+ # Provides a setter and getter for type classes' `openapi_format`,
2
+ # for use in the OpenAPI export.
3
+ module Taro::Types::Shared::OpenAPIFormat
4
+ OPENAPI_STRING_FORMATS = %i[
5
+ date
6
+ date-time
7
+ password
8
+ byte
9
+ binary
10
+ email
11
+ uuid
12
+ uri
13
+ hostname
14
+ ipv4
15
+ ipv6
16
+ ].freeze
17
+
18
+ OPENAPI_INTEGER_FORMATS = %i[
19
+ int32
20
+ int64
21
+ ].freeze
22
+
23
+ OPENAPI_NUMBER_FORMATS = %i[
24
+ float
25
+ double
26
+ ].freeze
27
+
28
+ def openapi_format
29
+ return unless @openapi_format
30
+
31
+ unless valid_formats_for_openapi_type.include?(@openapi_format)
32
+ raise(Taro::ArgumentError, "openapi_format #{@openapi_format.inspect} is invalid for openapi_type #{@openapi_type.inspect}, must be one for #{valid_formats_for_openapi_type}")
33
+ end
34
+
35
+ @openapi_format
36
+ end
37
+
38
+ def openapi_format=(arg)
39
+ @openapi_format = arg
40
+ end
41
+
42
+ def inherited(subclass)
43
+ subclass.instance_variable_set(:@openapi_format, @openapi_format)
44
+ super
45
+ end
46
+
47
+ private
48
+
49
+ def valid_formats_for_openapi_type
50
+ case @openapi_type
51
+ when :string
52
+ OPENAPI_STRING_FORMATS
53
+ when :integer
54
+ OPENAPI_INTEGER_FORMATS
55
+ when :number
56
+ OPENAPI_NUMBER_FORMATS
57
+ else
58
+ []
59
+ end
60
+ end
61
+ end
data/lib/taro/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # :nocov:
2
2
  module Taro
3
- VERSION = "2.4.0"
3
+ VERSION = "2.5.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taro
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2025-03-11 00:00:00.000000000 Z
12
+ date: 2025-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -115,6 +115,7 @@ files:
115
115
  - lib/taro/types/shared/item_type.rb
116
116
  - lib/taro/types/shared/name.rb
117
117
  - lib/taro/types/shared/object_coercion.rb
118
+ - lib/taro/types/shared/openapi_format.rb
118
119
  - lib/taro/types/shared/openapi_name.rb
119
120
  - lib/taro/types/shared/openapi_type.rb
120
121
  - lib/taro/types/shared/pattern.rb
@@ -146,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
146
147
  - !ruby/object:Gem::Version
147
148
  version: '0'
148
149
  requirements: []
149
- rubygems_version: 3.5.22
150
+ rubygems_version: 3.5.16
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: Typed Api using Ruby Objects.