taro 1.3.0 → 1.4.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
  SHA256:
3
- metadata.gz: 41f14035882a39e03a7bae9c799a42c9fa63414e4201fbbab7f876d54d8d214b
4
- data.tar.gz: 768b505506f8ad58792d0d86b6152f1aa60da98419aef111b9fc187ee74eab42
3
+ metadata.gz: d30f413c950e02e52f99ed96d234acdba122c92ec4e39dd2d35e87c899ed8a13
4
+ data.tar.gz: 5ed455623397ce6fbcb19412710bf98bc7ca2b6898db193a2cf858104a149327
5
5
  SHA512:
6
- metadata.gz: 27607c95ed9c5a7ab2c4d579dec41357657f24c694f43eac06b15677a82e491fd5986c5cad8b7bf999ee23ee456d75cc2c90debee47e93d02cdc901b4e45f498
7
- data.tar.gz: f99bfdfe66f7a09ac1746c23e2671bcec7f20cfee23e980db76561f14e1ea082bc2fcc59e4650af8732d7e608a8b7c012473dc0f862bb15ff9d89501a641c825
6
+ metadata.gz: ba99529dd914238371708a80b5f3f6497a4884a042a0e11ec7e9b557107379d0bfa2232b6a71137623658651e5d920f8ad47ab683119ae5ce105261fa627b980
7
+ data.tar.gz: 26b2652184c485aa7970707373cfe4ebfdecd3141fc7e995066060b5a0a5452b1e749d6e16fdc3d99e34a199434ed9edc7400d89fe8f8ed32df442d764d06175
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.4.0] - 2024-11-27
4
+
5
+ ### Added
6
+
7
+ - added operationId to OpenAPI export
8
+
9
+ ### Fixed
10
+
11
+ - fixed potential ref name clashes in OpenAPI export
12
+ - e.g. `FooBar::BazController` & `Foo::BarBazController`
13
+
3
14
  ## [1.3.0] - 2024-11-25
4
15
 
5
16
  ### Added
@@ -31,9 +31,10 @@ class Taro::Export::OpenAPIv3 < Taro::Export::Base # rubocop:disable Metrics/Cla
31
31
  description: declaration.desc,
32
32
  summary: declaration.summary,
33
33
  tags: declaration.tags,
34
+ operationId: route.openapi_operation_id,
34
35
  parameters: route_parameters(declaration, route),
35
36
  requestBody: request_body(declaration, route),
36
- responses: responses(declaration),
37
+ responses: responses(declaration, route),
37
38
  }.compact,
38
39
  }
39
40
  end
@@ -91,7 +92,7 @@ class Taro::Export::OpenAPIv3 < Taro::Export::Base # rubocop:disable Metrics/Cla
91
92
 
92
93
  body_input_type = Class.new(params)
93
94
  body_input_type.fields.replace(body_param_fields)
94
- body_input_type.openapi_name = params.openapi_name
95
+ body_input_type.openapi_name = "#{route.openapi_operation_id}_Input"
95
96
 
96
97
  # For polymorphic routes (more than one for the same declaration),
97
98
  # we can't use refs because their request body might differ:
@@ -109,7 +110,9 @@ class Taro::Export::OpenAPIv3 < Taro::Export::Base # rubocop:disable Metrics/Cla
109
110
  end
110
111
  end
111
112
 
112
- def responses(declaration)
113
+ def responses(declaration, route)
114
+ name_anonymous_return_types(declaration, route)
115
+
113
116
  declaration.returns.sort.to_h do |code, type|
114
117
  [
115
118
  code.to_s,
@@ -121,6 +124,14 @@ class Taro::Export::OpenAPIv3 < Taro::Export::Base # rubocop:disable Metrics/Cla
121
124
  end
122
125
  end
123
126
 
127
+ def name_anonymous_return_types(declaration, route)
128
+ declaration.returns.each do |code, type|
129
+ next if type.openapi_name?
130
+
131
+ type.openapi_name = "#{route.openapi_operation_id}_#{code}_Response"
132
+ end
133
+ end
134
+
124
135
  def export_type(type)
125
136
  if type < Taro::Types::ScalarType && !custom_scalar_type?(type)
126
137
  { type: type.openapi_type }
@@ -53,11 +53,6 @@ class Taro::Rails::Declaration
53
53
  end
54
54
 
55
55
  def finalize(controller_class:, action_name:)
56
- add_routes(controller_class:, action_name:)
57
- add_openapi_names(controller_class:, action_name:)
58
- end
59
-
60
- def add_routes(controller_class:, action_name:)
61
56
  routes = Taro::Rails::RouteFinder.call(controller_class:, action_name:)
62
57
  routes.any? || raise_missing_route(controller_class, action_name)
63
58
  self.routes = routes
@@ -72,21 +67,6 @@ class Taro::Rails::Declaration
72
67
  routes.size > 1
73
68
  end
74
69
 
75
- # TODO: these change when the controller class is renamed.
76
- # We might need a way to set `base`. Perhaps as a kwarg to `::api`?
77
- def add_openapi_names(controller_class:, action_name:)
78
- base = "#{controller_class.name.chomp('Controller').gsub('::', '_')}_#{action_name}"
79
- params.openapi_name = "#{base}_Input"
80
- params.define_singleton_method(:name) { openapi_name }
81
-
82
- returns.each do |status, return_type|
83
- next if return_type.openapi_name? # only set for ad-hoc / nested return types
84
-
85
- return_type.openapi_name = "#{base}_#{status}_Response"
86
- return_type.define_singleton_method(:name) { openapi_name }
87
- end
88
- end
89
-
90
70
  require 'rack'
91
71
  def self.coerce_status_to_int(status)
92
72
  # support using http status numbers directly
@@ -137,6 +117,6 @@ class Taro::Rails::Declaration
137
117
  end
138
118
 
139
119
  def <=>(other)
140
- params.openapi_name <=> other.params.openapi_name
120
+ routes.first.openapi_operation_id <=> other.routes.first.openapi_operation_id
141
121
  end
142
122
  end
@@ -18,15 +18,26 @@ Taro::Rails::NormalizedRoute = Data.define(:rails_route) do
18
18
  rails_route.path.spec.to_s.gsub('(.:format)', '').gsub(/:(\w+)/, '{\1}')
19
19
  end
20
20
 
21
+ def openapi_operation_id
22
+ "#{verb}_#{action}_#{controller.gsub('/', '__')}"
23
+ end
24
+
21
25
  def path_params
22
26
  openapi_path.scan(/{(\w+)}/).flatten.map(&:to_sym)
23
27
  end
24
28
 
25
29
  def endpoint
26
- controller, action = rails_route.requirements.values_at(:controller, :action)
27
30
  "#{controller}##{action}"
28
31
  end
29
32
 
33
+ def action
34
+ rails_route.requirements[:action]
35
+ end
36
+
37
+ def controller
38
+ rails_route.requirements[:controller]
39
+ end
40
+
30
41
  def can_have_request_body?
31
42
  %w[patch post put].include?(verb)
32
43
  end
@@ -34,4 +45,5 @@ Taro::Rails::NormalizedRoute = Data.define(:rails_route) do
34
45
  def inspect
35
46
  %(#<#{self.class} "#{verb} #{openapi_path}">)
36
47
  end
48
+ alias to_s inspect
37
49
  end
data/lib/taro/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # :nocov:
2
2
  module Taro
3
- VERSION = "1.3.0"
3
+ VERSION = "1.4.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: 1.3.0
4
+ version: 1.4.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: 2024-11-25 00:00:00.000000000 Z
12
+ date: 2024-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack