apiwork 0.7.0 → 0.7.2
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 +4 -4
- data/README.md +7 -2
- data/app/controllers/apiwork/exports_controller.rb +0 -2
- data/lib/apiwork/adapter/base.rb +10 -2
- data/lib/apiwork/adapter/capability/base.rb +2 -0
- data/lib/apiwork/adapter/capability/contract/scope.rb +0 -1
- data/lib/apiwork/adapter/capability/operation/base.rb +1 -0
- data/lib/apiwork/adapter/capability/runner.rb +0 -1
- data/lib/apiwork/adapter/serializer/resource/base.rb +0 -1
- data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +1 -2
- data/lib/apiwork/adapter/standard/capability/filtering/constants.rb +0 -3
- data/lib/apiwork/adapter/standard/capability/filtering/operation/filter.rb +0 -16
- data/lib/apiwork/adapter/standard/capability/filtering.rb +3 -0
- data/lib/apiwork/adapter/standard/capability/including/operation.rb +0 -1
- data/lib/apiwork/adapter/standard/capability/including.rb +1 -0
- data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/cursor.rb +0 -1
- data/lib/apiwork/adapter/standard/capability/pagination.rb +2 -0
- data/lib/apiwork/adapter/standard/capability/sorting.rb +2 -0
- data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +0 -4
- data/lib/apiwork/adapter/standard/capability/writing/operation.rb +1 -0
- data/lib/apiwork/adapter/standard/capability/writing.rb +2 -0
- data/lib/apiwork/adapter/standard.rb +3 -0
- data/lib/apiwork/adapter/wrapper/collection/default.rb +1 -0
- data/lib/apiwork/adapter/wrapper/member/default.rb +2 -0
- data/lib/apiwork/api/base.rb +5 -7
- data/lib/apiwork/api/object.rb +8 -7
- data/lib/apiwork/api/resource.rb +10 -10
- data/lib/apiwork/api/router.rb +0 -1
- data/lib/apiwork/api/type_registry.rb +1 -0
- data/lib/apiwork/configuration/option.rb +0 -1
- data/lib/apiwork/configuration/validatable.rb +1 -0
- data/lib/apiwork/configuration.rb +1 -0
- data/lib/apiwork/contract/action/request.rb +4 -0
- data/lib/apiwork/contract/action/response.rb +1 -0
- data/lib/apiwork/contract/action.rb +2 -2
- data/lib/apiwork/contract/base.rb +3 -3
- data/lib/apiwork/contract/object/coercer.rb +0 -2
- data/lib/apiwork/contract/object/deserializer.rb +0 -1
- data/lib/apiwork/contract/object/transformer.rb +0 -1
- data/lib/apiwork/contract/object/validator.rb +13 -19
- data/lib/apiwork/contract/object.rb +14 -14
- data/lib/apiwork/contract/request_parser.rb +0 -2
- data/lib/apiwork/controller.rb +3 -6
- data/lib/apiwork/engine.rb +1 -0
- data/lib/apiwork/error_code/registry.rb +0 -1
- data/lib/apiwork/export/apiwork.rb +1 -0
- data/lib/apiwork/export/apiwork_mapper.rb +0 -1
- data/lib/apiwork/export/base.rb +2 -3
- data/lib/apiwork/export/open_api.rb +4 -11
- data/lib/apiwork/export/pipeline/writer.rb +1 -1
- data/lib/apiwork/export/pipeline.rb +0 -5
- data/lib/apiwork/export/sorbus.rb +2 -0
- data/lib/apiwork/export/sorbus_mapper.rb +1 -5
- data/lib/apiwork/export/surface_resolver.rb +6 -4
- data/lib/apiwork/export/type_analysis.rb +2 -1
- data/lib/apiwork/export/type_script.rb +2 -0
- data/lib/apiwork/export/type_script_mapper.rb +0 -8
- data/lib/apiwork/export/zod.rb +4 -2
- data/lib/apiwork/export/zod_mapper.rb +0 -8
- data/lib/apiwork/introspection/dump/action.rb +1 -1
- data/lib/apiwork/introspection/dump/api.rb +0 -4
- data/lib/apiwork/introspection/dump/contract.rb +0 -6
- data/lib/apiwork/introspection/dump/param.rb +6 -6
- data/lib/apiwork/introspection/dump/resource.rb +1 -0
- data/lib/apiwork/introspection/dump/type.rb +5 -5
- data/lib/apiwork/object.rb +12 -4
- data/lib/apiwork/reference_generator.rb +10 -10
- data/lib/apiwork/registry.rb +1 -0
- data/lib/apiwork/representation/association.rb +3 -3
- data/lib/apiwork/representation/attribute.rb +1 -5
- data/lib/apiwork/representation/base.rb +2 -5
- data/lib/apiwork/representation/deserializer.rb +0 -1
- data/lib/apiwork/representation/inheritance.rb +22 -10
- data/lib/apiwork/representation/model_detector.rb +1 -0
- data/lib/apiwork/representation/serializer.rb +3 -2
- data/lib/apiwork/version.rb +1 -1
- data/lib/apiwork.rb +9 -8
- metadata +4 -18
|
@@ -7,7 +7,6 @@ module Apiwork
|
|
|
7
7
|
def register(key, attach_path: false, status:)
|
|
8
8
|
key = normalize_key(key)
|
|
9
9
|
status = Integer(status)
|
|
10
|
-
|
|
11
10
|
raise ArgumentError, "Status must be 400-599, got #{status}" unless (400..599).cover?(status)
|
|
12
11
|
|
|
13
12
|
store[key] = Definition.new(attach_path:, key:, status:)
|
|
@@ -80,7 +80,6 @@ module Apiwork
|
|
|
80
80
|
type_hashes = types.transform_values(&:to_h)
|
|
81
81
|
sorted = TypeAnalysis.topological_sort_types(type_hashes)
|
|
82
82
|
recursive = TypeAnalysis.cycle_breaking_types(type_hashes)
|
|
83
|
-
|
|
84
83
|
sorted.map { |name, _| serialize_type(name, types[name], recursive: recursive.include?(name)) }
|
|
85
84
|
end
|
|
86
85
|
|
data/lib/apiwork/export/base.rb
CHANGED
|
@@ -95,7 +95,6 @@ module Apiwork
|
|
|
95
95
|
|
|
96
96
|
def generate(api_base_path, format: nil, **options)
|
|
97
97
|
format ||= :json
|
|
98
|
-
|
|
99
98
|
raise ArgumentError, "#{export_name} export does not support #{format} format" if hash_output? && !supports_format?(format)
|
|
100
99
|
|
|
101
100
|
export = new(api_base_path, **options)
|
|
@@ -158,12 +157,14 @@ module Apiwork
|
|
|
158
157
|
return nil unless value.is_a?(Hash)
|
|
159
158
|
|
|
160
159
|
nested = {}
|
|
160
|
+
|
|
161
161
|
option.children.each do |child_name, child_option|
|
|
162
162
|
child_value = value[child_name] || value[child_name.to_s]
|
|
163
163
|
next if child_value.nil?
|
|
164
164
|
|
|
165
165
|
nested[child_name] = child_option.cast(child_value)
|
|
166
166
|
end
|
|
167
|
+
|
|
167
168
|
nested
|
|
168
169
|
end
|
|
169
170
|
|
|
@@ -216,7 +217,6 @@ module Apiwork
|
|
|
216
217
|
@options = self.class.default_options.merge(api_config).merge(all_options)
|
|
217
218
|
@options[:key_format] ||= @api_class.key_format || :keep
|
|
218
219
|
validate_options!
|
|
219
|
-
|
|
220
220
|
@api = @api_class.introspect(locale: @options[:locale])
|
|
221
221
|
end
|
|
222
222
|
|
|
@@ -250,7 +250,6 @@ module Apiwork
|
|
|
250
250
|
# @see #key_format
|
|
251
251
|
def transform_key(key)
|
|
252
252
|
key_string = key.to_s
|
|
253
|
-
|
|
254
253
|
return key_string if key_string.match?(/\A[A-Z]+\z/)
|
|
255
254
|
|
|
256
255
|
case key_format
|
|
@@ -6,6 +6,7 @@ module Apiwork
|
|
|
6
6
|
KEY_ORDER = %i[openapi info servers paths components].freeze
|
|
7
7
|
|
|
8
8
|
export_name :openapi
|
|
9
|
+
|
|
9
10
|
output :hash
|
|
10
11
|
|
|
11
12
|
option :version, default: '3.1.0', enum: %w[3.1.0], type: :string
|
|
@@ -26,6 +27,7 @@ module Apiwork
|
|
|
26
27
|
return { title: api_base_path, version: '1.0.0' } unless api.info
|
|
27
28
|
|
|
28
29
|
info = api.info
|
|
30
|
+
|
|
29
31
|
{
|
|
30
32
|
contact: build_contact(info.contact),
|
|
31
33
|
description: info.description,
|
|
@@ -100,8 +102,8 @@ module Apiwork
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
path_params = extract_path_parameters(action.path)
|
|
103
|
-
|
|
104
105
|
request = action.request
|
|
106
|
+
|
|
105
107
|
if request
|
|
106
108
|
query_params = request.query? ? build_query_parameters(request.query) : []
|
|
107
109
|
all_params = path_params + query_params
|
|
@@ -116,7 +118,6 @@ module Apiwork
|
|
|
116
118
|
end
|
|
117
119
|
|
|
118
120
|
operation[:responses] = build_responses(action_name, action.response, raises: action.raises)
|
|
119
|
-
|
|
120
121
|
operation.compact
|
|
121
122
|
end
|
|
122
123
|
|
|
@@ -203,7 +204,6 @@ module Apiwork
|
|
|
203
204
|
|
|
204
205
|
def build_responses(action_name, response, raises: [])
|
|
205
206
|
responses = {}
|
|
206
|
-
|
|
207
207
|
response_description = response.description || ''
|
|
208
208
|
|
|
209
209
|
if response.no_content?
|
|
@@ -317,15 +317,11 @@ module Apiwork
|
|
|
317
317
|
end
|
|
318
318
|
|
|
319
319
|
schema = map_param(param)
|
|
320
|
-
|
|
321
320
|
schema[:description] = param.description if param.description
|
|
322
321
|
schema[:example] = param.example if param.concrete? && param.example
|
|
323
322
|
schema[:deprecated] = true if param.deprecated?
|
|
324
|
-
|
|
325
323
|
schema[:format] = param.format.to_s if param.formattable? && param.format
|
|
326
|
-
|
|
327
324
|
schema[:default] = param.default if param.respond_to?(:default) && param.default?
|
|
328
|
-
|
|
329
325
|
apply_nullable(schema, param.nullable?)
|
|
330
326
|
end
|
|
331
327
|
|
|
@@ -372,9 +368,7 @@ module Apiwork
|
|
|
372
368
|
|
|
373
369
|
def map_array(param)
|
|
374
370
|
items_param = param.of
|
|
375
|
-
|
|
376
371
|
return { items: map_inline_object(param.shape), type: 'array' } if items_param.nil? && param.shape.any?
|
|
377
|
-
|
|
378
372
|
return { items: {}, type: 'array' } unless items_param
|
|
379
373
|
|
|
380
374
|
{
|
|
@@ -446,6 +440,7 @@ module Apiwork
|
|
|
446
440
|
end
|
|
447
441
|
|
|
448
442
|
mapping = {}
|
|
443
|
+
|
|
449
444
|
variants.each do |variant|
|
|
450
445
|
tag = variant.tag
|
|
451
446
|
next unless tag
|
|
@@ -483,11 +478,9 @@ module Apiwork
|
|
|
483
478
|
return {} if param.unknown?
|
|
484
479
|
|
|
485
480
|
type_value = openapi_type(param.type)
|
|
486
|
-
|
|
487
481
|
return {} if type_value.nil?
|
|
488
482
|
|
|
489
483
|
result = { type: type_value }
|
|
490
|
-
|
|
491
484
|
format_value = openapi_format(param.type)
|
|
492
485
|
result[:format] = format_value if format_value
|
|
493
486
|
|
|
@@ -17,10 +17,8 @@ module Apiwork
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
api_classes = api_base_path ? [find_api_class(api_base_path)] : API.values
|
|
20
|
-
|
|
21
20
|
start_time = Time.zone.now
|
|
22
21
|
count = 0
|
|
23
|
-
|
|
24
22
|
Rails.logger.debug 'Generating artifacts...'
|
|
25
23
|
|
|
26
24
|
api_classes.each do |api_class|
|
|
@@ -40,7 +38,6 @@ module Apiwork
|
|
|
40
38
|
end
|
|
41
39
|
|
|
42
40
|
Rails.logger.debug "\nGenerated #{count} file#{count == 1 ? '' : 's'} in #{(Time.zone.now - start_time).round(2)}s"
|
|
43
|
-
|
|
44
41
|
count
|
|
45
42
|
end
|
|
46
43
|
|
|
@@ -58,11 +55,9 @@ module Apiwork
|
|
|
58
55
|
|
|
59
56
|
def generate_file(api_class:, export_name:, format:, key_format:, locale:, output:, version:)
|
|
60
57
|
api_base_path = api_class.base_path
|
|
61
|
-
|
|
62
58
|
options = { format:, key_format:, locale:, version: }.compact
|
|
63
59
|
options_label = options.any? ? " (#{options.map { |key, value| "#{key}: #{value}" }.join(', ')})" : ''
|
|
64
60
|
Rails.logger.debug " ✓ #{api_base_path} to #{export_name}#{options_label}"
|
|
65
|
-
|
|
66
61
|
content = generate(export_name, api_base_path, format:, key_format:, locale:, version:)
|
|
67
62
|
export_class = Registry.find!(export_name)
|
|
68
63
|
extension = export_class.file_extension_for(format:)
|
|
@@ -61,19 +61,14 @@ module Apiwork
|
|
|
61
61
|
def build_endpoint(resource_name, action_name, action)
|
|
62
62
|
path = transform_path(action.path)
|
|
63
63
|
endpoint = { path:, method: action.method.to_s.upcase }
|
|
64
|
-
|
|
65
64
|
path_params = extract_path_params(action.path)
|
|
66
65
|
endpoint[:pathParams] = build_path_params_schema(path_params) if path_params.any?
|
|
67
|
-
|
|
68
66
|
request = build_request(action.request)
|
|
69
67
|
endpoint[:request] = request if request
|
|
70
|
-
|
|
71
68
|
response = build_response(action.response)
|
|
72
69
|
endpoint[:response] = response if response
|
|
73
|
-
|
|
74
70
|
errors = resolve_errors(action)
|
|
75
71
|
endpoint[:errors] = errors if errors.any?
|
|
76
|
-
|
|
77
72
|
endpoint
|
|
78
73
|
end
|
|
79
74
|
|
|
@@ -109,6 +104,7 @@ module Apiwork
|
|
|
109
104
|
properties = params.sort_by { |name, _| name.to_s }.map do |name, param|
|
|
110
105
|
"#{@export.transform_key(name)}: #{@zod_mapper.map_field(param)}"
|
|
111
106
|
end.join(', ')
|
|
107
|
+
|
|
112
108
|
"z.object({ #{properties} })"
|
|
113
109
|
end
|
|
114
110
|
|
|
@@ -37,9 +37,11 @@ module Apiwork
|
|
|
37
37
|
|
|
38
38
|
def collect_type_names_from_actions
|
|
39
39
|
type_names = Set.new
|
|
40
|
+
|
|
40
41
|
@api.resources.each_value do |resource|
|
|
41
42
|
collect_types_from_resource(resource, type_names)
|
|
42
43
|
end
|
|
44
|
+
|
|
43
45
|
type_names
|
|
44
46
|
end
|
|
45
47
|
|
|
@@ -47,6 +49,7 @@ module Apiwork
|
|
|
47
49
|
resource.actions.each_value do |action|
|
|
48
50
|
collect_types_from_action(action, type_names)
|
|
49
51
|
end
|
|
52
|
+
|
|
50
53
|
resource.resources.each_value do |nested|
|
|
51
54
|
collect_types_from_resource(nested, type_names)
|
|
52
55
|
end
|
|
@@ -61,7 +64,6 @@ module Apiwork
|
|
|
61
64
|
|
|
62
65
|
def collect_types_from_param(param, type_names)
|
|
63
66
|
type_names << param.reference if param.reference?
|
|
64
|
-
|
|
65
67
|
param.shape.each_value { |nested| collect_types_from_param(nested, type_names) } if param.object?
|
|
66
68
|
|
|
67
69
|
if param.array?
|
|
@@ -109,7 +111,6 @@ module Apiwork
|
|
|
109
111
|
|
|
110
112
|
def collect_reference_names_from_param(param, reference_names)
|
|
111
113
|
reference_names << param.reference if param.reference?
|
|
112
|
-
|
|
113
114
|
param.shape.each_value { |nested| collect_reference_names_from_param(nested, reference_names) } if param.object?
|
|
114
115
|
|
|
115
116
|
if param.array?
|
|
@@ -122,9 +123,11 @@ module Apiwork
|
|
|
122
123
|
|
|
123
124
|
def collect_enum_names_from_actions
|
|
124
125
|
enum_names = Set.new
|
|
126
|
+
|
|
125
127
|
@api.resources.each_value do |resource|
|
|
126
128
|
collect_enums_from_resource(resource, enum_names)
|
|
127
129
|
end
|
|
130
|
+
|
|
128
131
|
enum_names
|
|
129
132
|
end
|
|
130
133
|
|
|
@@ -132,6 +135,7 @@ module Apiwork
|
|
|
132
135
|
resource.actions.each_value do |action|
|
|
133
136
|
collect_enums_from_action(action, enum_names)
|
|
134
137
|
end
|
|
138
|
+
|
|
135
139
|
resource.resources.each_value do |nested|
|
|
136
140
|
collect_enums_from_resource(nested, enum_names)
|
|
137
141
|
end
|
|
@@ -145,7 +149,6 @@ module Apiwork
|
|
|
145
149
|
|
|
146
150
|
def collect_enums_from_param(param, enum_names)
|
|
147
151
|
enum_names << param.enum if param.enum_reference?
|
|
148
|
-
|
|
149
152
|
param.shape.each_value { |nested| collect_enums_from_param(nested, enum_names) } if param.object?
|
|
150
153
|
|
|
151
154
|
if param.array?
|
|
@@ -175,7 +178,6 @@ module Apiwork
|
|
|
175
178
|
def collect_enums_from_type_param(param, enum_names)
|
|
176
179
|
enum_names << param.enum if param.enum_reference?
|
|
177
180
|
enum_names << param.reference if param.reference? && @api.enums.key?(param.reference)
|
|
178
|
-
|
|
179
181
|
param.shape.each_value { |nested| collect_enums_from_type_param(nested, enum_names) } if param.object?
|
|
180
182
|
|
|
181
183
|
if param.array?
|
|
@@ -115,12 +115,14 @@ module Apiwork
|
|
|
115
115
|
return unless state[:lowlinks][node] == state[:indices][node]
|
|
116
116
|
|
|
117
117
|
component = []
|
|
118
|
+
|
|
118
119
|
loop do
|
|
119
120
|
successor = state[:stack].pop
|
|
120
121
|
state[:on_stack].delete(successor)
|
|
121
122
|
component << successor
|
|
122
123
|
break if successor == node
|
|
123
124
|
end
|
|
125
|
+
|
|
124
126
|
state[:components] << component
|
|
125
127
|
end
|
|
126
128
|
|
|
@@ -134,7 +136,6 @@ module Apiwork
|
|
|
134
136
|
extract_type_field(node, references, filter)
|
|
135
137
|
extract_of_field(node[:of], references, filter)
|
|
136
138
|
extract_extends_field(node[:extends], references, filter)
|
|
137
|
-
|
|
138
139
|
node[:variants]&.each { |variant| collect_references(variant, references, filter) }
|
|
139
140
|
node[:shape]&.each_value { |param| collect_references(param, references, filter) }
|
|
140
141
|
end
|
|
@@ -40,7 +40,6 @@ module Apiwork
|
|
|
40
40
|
end.join("\n")
|
|
41
41
|
|
|
42
42
|
type_jsdoc = jsdoc(description: type.description, example: type.example)
|
|
43
|
-
|
|
44
43
|
code = build_interface_code(type_name, properties, type.extends)
|
|
45
44
|
type_jsdoc ? "#{type_jsdoc}\n#{code}" : code
|
|
46
45
|
end
|
|
@@ -105,11 +104,8 @@ module Apiwork
|
|
|
105
104
|
|
|
106
105
|
def build_action_request_type(resource_name, action_name, request, parent_identifiers: [])
|
|
107
106
|
nested_properties = []
|
|
108
|
-
|
|
109
107
|
nested_properties << " query: #{action_type_name(resource_name, action_name, 'RequestQuery', parent_identifiers:)};" if request[:query].any?
|
|
110
|
-
|
|
111
108
|
nested_properties << " body: #{action_type_name(resource_name, action_name, 'RequestBody', parent_identifiers:)};" if request[:body].any?
|
|
112
|
-
|
|
113
109
|
"export interface #{action_type_name(resource_name, action_name, 'Request', parent_identifiers:)} {\n#{nested_properties.join("\n")}\n}"
|
|
114
110
|
end
|
|
115
111
|
|
|
@@ -156,7 +152,6 @@ module Apiwork
|
|
|
156
152
|
end
|
|
157
153
|
|
|
158
154
|
base_type = [base_type, 'null'].sort.join(' | ') if param.nullable?
|
|
159
|
-
|
|
160
155
|
base_type
|
|
161
156
|
end
|
|
162
157
|
|
|
@@ -195,9 +190,7 @@ module Apiwork
|
|
|
195
190
|
|
|
196
191
|
def map_array_type(param)
|
|
197
192
|
items_type = param.of
|
|
198
|
-
|
|
199
193
|
return "#{map_object_type(param)}[]" if items_type.nil? && param.shape.any?
|
|
200
|
-
|
|
201
194
|
return 'unknown[]' unless items_type
|
|
202
195
|
|
|
203
196
|
element_type = map_param(items_type)
|
|
@@ -375,7 +368,6 @@ module Apiwork
|
|
|
375
368
|
type_name = action_type_name(resource_name, action_name, 'Request', parent_identifiers:)
|
|
376
369
|
code = build_action_request_type(resource_name, action_name, { body: request.body, query: request.query }, parent_identifiers:)
|
|
377
370
|
types << { code:, name: type_name }
|
|
378
|
-
|
|
379
371
|
types
|
|
380
372
|
end
|
|
381
373
|
|
data/lib/apiwork/export/zod.rb
CHANGED
|
@@ -4,23 +4,25 @@ module Apiwork
|
|
|
4
4
|
module Export
|
|
5
5
|
class Zod < Base
|
|
6
6
|
export_name :zod
|
|
7
|
+
|
|
7
8
|
output :string
|
|
9
|
+
|
|
8
10
|
file_extension '.ts'
|
|
9
11
|
|
|
10
12
|
option :version, default: '4', enum: %w[4], type: :string
|
|
11
13
|
|
|
12
14
|
def generate
|
|
13
15
|
parts = []
|
|
14
|
-
|
|
15
16
|
parts << "import { z } from 'zod';\n"
|
|
16
|
-
|
|
17
17
|
zod_schemas = ZodMapper.map(self, surface)
|
|
18
|
+
|
|
18
19
|
if zod_schemas.present?
|
|
19
20
|
parts << zod_schemas
|
|
20
21
|
parts << ''
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
typescript_types = TypeScriptMapper.map(self, surface)
|
|
25
|
+
|
|
24
26
|
if typescript_types.present?
|
|
25
27
|
parts << typescript_types
|
|
26
28
|
parts << ''
|
|
@@ -29,19 +29,14 @@ module Apiwork
|
|
|
29
29
|
|
|
30
30
|
def map(surface)
|
|
31
31
|
parts = []
|
|
32
|
-
|
|
33
32
|
enum_schemas = build_enum_schemas(surface.enums)
|
|
34
33
|
parts << enum_schemas if enum_schemas.present?
|
|
35
|
-
|
|
36
34
|
type_schemas = build_type_schemas(surface.types)
|
|
37
35
|
parts << type_schemas if type_schemas.present?
|
|
38
|
-
|
|
39
36
|
action_schemas = build_action_schemas
|
|
40
37
|
parts << action_schemas if action_schemas.present?
|
|
41
|
-
|
|
42
38
|
action_response_schemas = build_action_response_schemas
|
|
43
39
|
parts << action_response_schemas if action_response_schemas.present?
|
|
44
|
-
|
|
45
40
|
parts.join("\n\n")
|
|
46
41
|
end
|
|
47
42
|
|
|
@@ -96,7 +91,6 @@ module Apiwork
|
|
|
96
91
|
end
|
|
97
92
|
|
|
98
93
|
union_body = variant_schemas.map { |schema| " #{schema}" }.join(",\n")
|
|
99
|
-
|
|
100
94
|
type_annotation = recursive ? ": z.ZodType<#{schema_name}>" : ''
|
|
101
95
|
|
|
102
96
|
union_code = if type.discriminator
|
|
@@ -191,7 +185,6 @@ module Apiwork
|
|
|
191
185
|
|
|
192
186
|
type = map_param(param)
|
|
193
187
|
type = resolve_enum_schema(param) || type
|
|
194
|
-
|
|
195
188
|
apply_modifiers(type, param, force_optional:)
|
|
196
189
|
end
|
|
197
190
|
|
|
@@ -458,7 +451,6 @@ module Apiwork
|
|
|
458
451
|
|
|
459
452
|
def apply_modifiers(type, param, force_optional: nil)
|
|
460
453
|
type += '.nullable()' if param.nullable?
|
|
461
|
-
|
|
462
454
|
has_default = param.respond_to?(:default) && param.default?
|
|
463
455
|
optional = force_optional.nil? ? param.optional? : force_optional
|
|
464
456
|
|
|
@@ -77,7 +77,6 @@ module Apiwork
|
|
|
77
77
|
|
|
78
78
|
action_name = @contract_action.name.to_sym
|
|
79
79
|
return [:unprocessable_entity] if [:create, :update].include?(action_name)
|
|
80
|
-
|
|
81
80
|
return [] if [:index, :show, :destroy].include?(action_name)
|
|
82
81
|
|
|
83
82
|
http_method = find_http_method
|
|
@@ -93,6 +92,7 @@ module Apiwork
|
|
|
93
92
|
resource = api_class.root_resource.find_resource do |candidate|
|
|
94
93
|
candidate.contract_class == @contract_action.contract_class
|
|
95
94
|
end
|
|
95
|
+
|
|
96
96
|
return nil unless resource
|
|
97
97
|
|
|
98
98
|
resource.actions[@contract_action.name.to_sym]&.method
|
|
@@ -29,9 +29,7 @@ module Apiwork
|
|
|
29
29
|
|
|
30
30
|
def collect_all_error_code_keys(resources)
|
|
31
31
|
error_code_keys = Set.new(@api_class.raises)
|
|
32
|
-
|
|
33
32
|
collect_action_error_codes(resources, error_code_keys)
|
|
34
|
-
|
|
35
33
|
error_code_keys.to_a.sort_by(&:to_s)
|
|
36
34
|
end
|
|
37
35
|
|
|
@@ -63,11 +61,9 @@ module Apiwork
|
|
|
63
61
|
|
|
64
62
|
def build_info
|
|
65
63
|
info = @api_class.info
|
|
66
|
-
|
|
67
64
|
title = resolve_info_text(info, :title)
|
|
68
65
|
summary = resolve_info_text(info, :summary)
|
|
69
66
|
description = resolve_info_text(info, :description)
|
|
70
|
-
|
|
71
67
|
return nil unless info || title || summary || description
|
|
72
68
|
|
|
73
69
|
{
|
|
@@ -12,9 +12,7 @@ module Apiwork
|
|
|
12
12
|
|
|
13
13
|
def to_h
|
|
14
14
|
@contract_class.api_class.ensure_all_contracts_built!
|
|
15
|
-
|
|
16
15
|
result = { actions: {} }
|
|
17
|
-
|
|
18
16
|
action_names = available_actions
|
|
19
17
|
action_names = @contract_class.actions.keys if action_names.empty?
|
|
20
18
|
|
|
@@ -32,7 +30,6 @@ module Apiwork
|
|
|
32
30
|
|
|
33
31
|
result[:types] = types
|
|
34
32
|
result[:enums] = enums
|
|
35
|
-
|
|
36
33
|
result
|
|
37
34
|
end
|
|
38
35
|
|
|
@@ -60,12 +57,10 @@ module Apiwork
|
|
|
60
57
|
def build_referenced_types_and_enums(actions_dump)
|
|
61
58
|
type_registry = @contract_class.api_class.type_registry
|
|
62
59
|
enum_registry = @contract_class.api_class.enum_registry
|
|
63
|
-
|
|
64
60
|
referenced_types = Set.new
|
|
65
61
|
referenced_enums = Set.new
|
|
66
62
|
dumped_types = {}
|
|
67
63
|
visited_types = Set.new
|
|
68
|
-
|
|
69
64
|
collect_references(actions_dump, referenced_types, referenced_enums)
|
|
70
65
|
|
|
71
66
|
until (pending_types = referenced_types - visited_types).empty?
|
|
@@ -89,7 +84,6 @@ module Apiwork
|
|
|
89
84
|
|
|
90
85
|
types = dumped_types.sort_by { |name, _| name.to_s }.to_h
|
|
91
86
|
enums = dumped_enums.sort_by { |name, _| name.to_s }.to_h
|
|
92
|
-
|
|
93
87
|
[types, enums]
|
|
94
88
|
end
|
|
95
89
|
|
|
@@ -54,6 +54,7 @@ module Apiwork
|
|
|
54
54
|
value: options[:type] == :literal ? options[:value] : nil,
|
|
55
55
|
variants: [],
|
|
56
56
|
}
|
|
57
|
+
|
|
57
58
|
result[:default] = options[:default] if options.key?(:default)
|
|
58
59
|
result
|
|
59
60
|
end
|
|
@@ -82,6 +83,7 @@ module Apiwork
|
|
|
82
83
|
value: nil,
|
|
83
84
|
variants: union_dump[:variants],
|
|
84
85
|
}
|
|
86
|
+
|
|
85
87
|
result[:default] = options[:default] if options.key?(:default)
|
|
86
88
|
result
|
|
87
89
|
end
|
|
@@ -111,6 +113,7 @@ module Apiwork
|
|
|
111
113
|
value: nil,
|
|
112
114
|
variants: [],
|
|
113
115
|
}
|
|
116
|
+
|
|
114
117
|
result[:default] = options[:default] if options.key?(:default)
|
|
115
118
|
result
|
|
116
119
|
end
|
|
@@ -186,7 +189,6 @@ module Apiwork
|
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
result[:of] = build_of_from_element(element.inner) if [:array, :record].include?(element.type) && element.inner
|
|
189
|
-
|
|
190
192
|
result
|
|
191
193
|
end
|
|
192
194
|
|
|
@@ -200,7 +202,6 @@ module Apiwork
|
|
|
200
202
|
def build_variant(variant)
|
|
201
203
|
variant_type = variant[:custom_type] || variant[:type]
|
|
202
204
|
is_registered = registered_type?(variant_type)
|
|
203
|
-
|
|
204
205
|
reference = is_registered ? qualified_name(variant_type, @contract_param) : nil
|
|
205
206
|
resolved_type = is_registered ? :reference : (variant[:type] || :unknown)
|
|
206
207
|
|
|
@@ -266,9 +267,11 @@ module Apiwork
|
|
|
266
267
|
|
|
267
268
|
def dump_api_object(api_object)
|
|
268
269
|
result = {}
|
|
270
|
+
|
|
269
271
|
api_object.params.sort_by { |name, _| name.to_s }.each do |name, options|
|
|
270
272
|
result[name] = build_api_param(options)
|
|
271
273
|
end
|
|
274
|
+
|
|
272
275
|
result
|
|
273
276
|
end
|
|
274
277
|
|
|
@@ -332,6 +335,7 @@ module Apiwork
|
|
|
332
335
|
value: nil,
|
|
333
336
|
variants: union_shape ? union_shape.variants.map { |variant| build_api_variant(variant) } : [],
|
|
334
337
|
}
|
|
338
|
+
|
|
335
339
|
result[:of] = build_api_of({ of: of.inner }) if of.type == :array && of.inner
|
|
336
340
|
result
|
|
337
341
|
end
|
|
@@ -366,7 +370,6 @@ module Apiwork
|
|
|
366
370
|
|
|
367
371
|
def build_shape(options)
|
|
368
372
|
dumped = options[:shape] ? build_nested_shape(options[:shape]) : nil
|
|
369
|
-
|
|
370
373
|
return dumped || {} if [:object, :array].include?(options[:type])
|
|
371
374
|
|
|
372
375
|
dumped
|
|
@@ -400,7 +403,6 @@ module Apiwork
|
|
|
400
403
|
|
|
401
404
|
representation_name = attribute.representation_class_name
|
|
402
405
|
attribute_name = attribute.name
|
|
403
|
-
|
|
404
406
|
api_class.translate(:representations, representation_name, :attributes, attribute_name, :description)
|
|
405
407
|
end
|
|
406
408
|
|
|
@@ -410,7 +412,6 @@ module Apiwork
|
|
|
410
412
|
|
|
411
413
|
representation_name = association.representation_class_name
|
|
412
414
|
association_name = association.name
|
|
413
|
-
|
|
414
415
|
api_class.translate(:representations, representation_name, :associations, association_name, :description)
|
|
415
416
|
end
|
|
416
417
|
|
|
@@ -446,7 +447,6 @@ module Apiwork
|
|
|
446
447
|
|
|
447
448
|
def imported_type?(type_name, contract_param)
|
|
448
449
|
import_prefixes = import_prefix_cache(contract_param.contract_class)
|
|
449
|
-
|
|
450
450
|
return true if import_prefixes[:direct].include?(type_name)
|
|
451
451
|
|
|
452
452
|
type_name = type_name.to_s
|
|
@@ -77,6 +77,7 @@ module Apiwork
|
|
|
77
77
|
parent_path: resource_path,
|
|
78
78
|
parent_singular: @resource.singular,
|
|
79
79
|
}
|
|
80
|
+
|
|
80
81
|
nested_options[:parent_param] = @resource.param&.to_s || "#{@resource.name.to_s.singularize}_id" unless @resource.singular
|
|
81
82
|
|
|
82
83
|
@resource.resources.transform_values do |nested_resource|
|