apiwork 0.7.1 → 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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/apiwork/exports_controller.rb +0 -2
  3. data/lib/apiwork/adapter/base.rb +10 -2
  4. data/lib/apiwork/adapter/capability/base.rb +2 -0
  5. data/lib/apiwork/adapter/capability/contract/scope.rb +0 -1
  6. data/lib/apiwork/adapter/capability/operation/base.rb +1 -0
  7. data/lib/apiwork/adapter/capability/runner.rb +0 -1
  8. data/lib/apiwork/adapter/serializer/resource/base.rb +0 -1
  9. data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +1 -2
  10. data/lib/apiwork/adapter/standard/capability/filtering/constants.rb +0 -3
  11. data/lib/apiwork/adapter/standard/capability/filtering/operation/filter.rb +0 -16
  12. data/lib/apiwork/adapter/standard/capability/filtering.rb +3 -0
  13. data/lib/apiwork/adapter/standard/capability/including/operation.rb +0 -1
  14. data/lib/apiwork/adapter/standard/capability/including.rb +1 -0
  15. data/lib/apiwork/adapter/standard/capability/pagination/operation/paginate/cursor.rb +0 -1
  16. data/lib/apiwork/adapter/standard/capability/pagination.rb +2 -0
  17. data/lib/apiwork/adapter/standard/capability/sorting.rb +2 -0
  18. data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +0 -4
  19. data/lib/apiwork/adapter/standard/capability/writing/operation.rb +1 -0
  20. data/lib/apiwork/adapter/standard/capability/writing.rb +2 -0
  21. data/lib/apiwork/adapter/standard.rb +3 -0
  22. data/lib/apiwork/adapter/wrapper/collection/default.rb +1 -0
  23. data/lib/apiwork/adapter/wrapper/member/default.rb +2 -0
  24. data/lib/apiwork/api/base.rb +5 -7
  25. data/lib/apiwork/api/object.rb +1 -1
  26. data/lib/apiwork/api/resource.rb +10 -10
  27. data/lib/apiwork/api/router.rb +0 -1
  28. data/lib/apiwork/api/type_registry.rb +1 -0
  29. data/lib/apiwork/configuration/option.rb +0 -1
  30. data/lib/apiwork/configuration/validatable.rb +1 -0
  31. data/lib/apiwork/configuration.rb +1 -0
  32. data/lib/apiwork/contract/action/request.rb +4 -0
  33. data/lib/apiwork/contract/action/response.rb +1 -0
  34. data/lib/apiwork/contract/action.rb +2 -2
  35. data/lib/apiwork/contract/base.rb +3 -3
  36. data/lib/apiwork/contract/object/coercer.rb +0 -2
  37. data/lib/apiwork/contract/object/deserializer.rb +0 -1
  38. data/lib/apiwork/contract/object/transformer.rb +0 -1
  39. data/lib/apiwork/contract/object/validator.rb +12 -18
  40. data/lib/apiwork/contract/object.rb +7 -9
  41. data/lib/apiwork/contract/request_parser.rb +0 -2
  42. data/lib/apiwork/controller.rb +3 -6
  43. data/lib/apiwork/engine.rb +1 -0
  44. data/lib/apiwork/error_code/registry.rb +0 -1
  45. data/lib/apiwork/export/apiwork.rb +1 -0
  46. data/lib/apiwork/export/apiwork_mapper.rb +0 -1
  47. data/lib/apiwork/export/base.rb +2 -3
  48. data/lib/apiwork/export/open_api.rb +4 -11
  49. data/lib/apiwork/export/pipeline/writer.rb +1 -1
  50. data/lib/apiwork/export/pipeline.rb +0 -5
  51. data/lib/apiwork/export/sorbus.rb +2 -0
  52. data/lib/apiwork/export/sorbus_mapper.rb +1 -5
  53. data/lib/apiwork/export/surface_resolver.rb +6 -4
  54. data/lib/apiwork/export/type_analysis.rb +2 -1
  55. data/lib/apiwork/export/type_script.rb +2 -0
  56. data/lib/apiwork/export/type_script_mapper.rb +0 -8
  57. data/lib/apiwork/export/zod.rb +4 -2
  58. data/lib/apiwork/export/zod_mapper.rb +0 -8
  59. data/lib/apiwork/introspection/dump/action.rb +1 -1
  60. data/lib/apiwork/introspection/dump/api.rb +0 -4
  61. data/lib/apiwork/introspection/dump/contract.rb +0 -6
  62. data/lib/apiwork/introspection/dump/param.rb +6 -6
  63. data/lib/apiwork/introspection/dump/resource.rb +1 -0
  64. data/lib/apiwork/introspection/dump/type.rb +5 -5
  65. data/lib/apiwork/reference_generator.rb +10 -10
  66. data/lib/apiwork/registry.rb +1 -0
  67. data/lib/apiwork/representation/association.rb +3 -3
  68. data/lib/apiwork/representation/attribute.rb +0 -4
  69. data/lib/apiwork/representation/base.rb +2 -5
  70. data/lib/apiwork/representation/deserializer.rb +0 -1
  71. data/lib/apiwork/representation/inheritance.rb +22 -10
  72. data/lib/apiwork/representation/model_detector.rb +1 -0
  73. data/lib/apiwork/representation/serializer.rb +3 -2
  74. data/lib/apiwork/version.rb +1 -1
  75. data/lib/apiwork.rb +9 -8
  76. metadata +4 -4
@@ -4,7 +4,9 @@ module Apiwork
4
4
  module Export
5
5
  class Sorbus < Base
6
6
  export_name :sorbus
7
+
7
8
  output :string
9
+
8
10
  file_extension '.ts'
9
11
 
10
12
  def generate
@@ -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
@@ -4,7 +4,9 @@ module Apiwork
4
4
  module Export
5
5
  class TypeScript < Base
6
6
  export_name :typescript
7
+
7
8
  output :string
9
+
8
10
  file_extension '.ts'
9
11
 
10
12
  option :version, default: '5', enum: %w[4 5], type: :string
@@ -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
 
@@ -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|
@@ -76,12 +76,12 @@ module Apiwork
76
76
  return {} unless type_definition.params
77
77
 
78
78
  result = {}
79
-
80
79
  expand_merged_types(type_definition, result)
81
80
 
82
81
  type_definition.params.sort_by { |name, _| name.to_s }.each do |name, param_options|
83
82
  result[name] = build_param(name, param_options, type_definition.scope)
84
83
  end
84
+
85
85
  result
86
86
  end
87
87
 
@@ -135,6 +135,7 @@ module Apiwork
135
135
  value: options[:type] == :literal ? options[:value] : nil,
136
136
  variants: build_nested_variants(options[:shape]),
137
137
  }
138
+
138
139
  result[:default] = options[:default] if options.key?(:default)
139
140
  result
140
141
  end
@@ -171,9 +172,11 @@ module Apiwork
171
172
  return {} unless shape.respond_to?(:params)
172
173
 
173
174
  result = {}
175
+
174
176
  shape.params.sort_by { |name, _| name.to_s }.each do |name, param_options|
175
177
  result[name] = build_param(name, param_options, nil)
176
178
  end
179
+
177
180
  result
178
181
  end
179
182
 
@@ -240,6 +243,7 @@ module Apiwork
240
243
  value: nil,
241
244
  variants: union_shape ? union_shape.variants.map { |variant| build_variant(variant, scope) } : [],
242
245
  }
246
+
243
247
  result[:of] = resolve_of({ of: of.inner }, scope) if of.type == :array && of.inner
244
248
  result
245
249
  end
@@ -301,14 +305,12 @@ module Apiwork
301
305
  def i18n_attribute_description(attribute)
302
306
  representation_name = attribute.representation_class_name
303
307
  attribute_name = attribute.name
304
-
305
308
  @api_class.translate(:representations, representation_name, :attributes, attribute_name, :description)
306
309
  end
307
310
 
308
311
  def i18n_association_description(association)
309
312
  representation_name = association.representation_class_name
310
313
  association_name = association.name
311
-
312
314
  @api_class.translate(:representations, representation_name, :associations, association_name, :description)
313
315
  end
314
316
 
@@ -333,9 +335,7 @@ module Apiwork
333
335
  def resolve_scoped_type_name(type_name, scope)
334
336
  return nil unless type_name.is_a?(Symbol)
335
337
  return nil unless @api_class
336
-
337
338
  return type_name if @api_class.type_registry.key?(type_name) || @api_class.enum_registry.key?(type_name)
338
-
339
339
  return nil unless scope
340
340
 
341
341
  scoped_name = @api_class.scoped_type_name(scope, type_name)
@@ -9,6 +9,7 @@ module Apiwork
9
9
  GEM_ROOT = File.expand_path('../..', __dir__)
10
10
  OUTPUT_DIR = File.join(GEM_ROOT, 'docs/reference')
11
11
  GITHUB_URL = 'https://github.com/skiftle/apiwork/blob/main'
12
+
12
13
  RUBY_PRIMITIVES = %w[
13
14
  String Integer Float Boolean Symbol Hash Array Object
14
15
  TrueClass FalseClass NilClass Numeric Proc
@@ -22,7 +23,6 @@ module Apiwork
22
23
 
23
24
  def generate
24
25
  require 'yard'
25
-
26
26
  parse_source
27
27
  modules = extract_modules
28
28
  write_files(modules)
@@ -82,7 +82,6 @@ module Apiwork
82
82
 
83
83
  has_own_docstring = !yard_object.docstring.to_s.strip.empty?
84
84
  return true if has_own_docstring && api_tag
85
-
86
85
  return false unless yard_object.file
87
86
 
88
87
  lines = File.readlines(yard_object.file)
@@ -93,8 +92,8 @@ module Apiwork
93
92
  else
94
93
  [yard_object.line - 5, 0].max
95
94
  end
96
- end_line = yard_object.line
97
95
 
96
+ end_line = yard_object.line
98
97
  preceding_lines = lines[start_line...end_line].join
99
98
  preceding_lines.include?('@api public')
100
99
  end
@@ -167,6 +166,7 @@ module Apiwork
167
166
 
168
167
  def build_signature(method)
169
168
  params = method.parameters.reject { |name, _default| name.to_s.start_with?('internal') }
169
+
170
170
  params = params.map do |name, default|
171
171
  if name.to_s.end_with?(':')
172
172
  default ? "#{name} #{default}" : name.to_s
@@ -216,6 +216,7 @@ module Apiwork
216
216
  return { default: nil, description: nil, values: nil, values_type: nil } if text.blank?
217
217
 
218
218
  match = text.match(/\A(?:\(([^)]+)\))?\s*(?:\[(?:(\w+):\s*)?([^\]]+)\])?\s*(.*)\z/m)
219
+
219
220
  {
220
221
  default: match[1],
221
222
  description: match[4].presence,
@@ -257,8 +258,8 @@ module Apiwork
257
258
  cleanup_old_files
258
259
  @modules = modules
259
260
  @modules_with_children = build_modules_with_children(modules)
260
-
261
261
  write_root_index
262
+
262
263
  modules.each.with_index(1) do |mod, order|
263
264
  filepath = module_filepath(mod[:path])
264
265
  FileUtils.mkdir_p(File.dirname(filepath))
@@ -288,7 +289,6 @@ module Apiwork
288
289
  end
289
290
 
290
291
  parts << "#{linkify_yard_refs(constant[:docstring])}\n" if constant[:docstring].present?
291
-
292
292
  parts.join("\n")
293
293
  end
294
294
 
@@ -376,6 +376,7 @@ module Apiwork
376
376
  link = folder ? "./#{child_path}/" : "./#{child_path}"
377
377
  parts << "- [#{child}](#{link})"
378
378
  end
379
+
379
380
  parts << ''
380
381
  end
381
382
 
@@ -391,6 +392,7 @@ module Apiwork
391
392
 
392
393
  def build_modules_with_children(modules)
393
394
  paths = modules.map { |m| m[:path] }.to_set
395
+
394
396
  paths.select do |path|
395
397
  paths.any? { |other| other != path && other.start_with?("#{path}::") }
396
398
  end.to_set
@@ -433,6 +435,7 @@ module Apiwork
433
435
  link_path = yard_ref_to_path(ref)
434
436
  "[#{ref}](#{link_path})"
435
437
  end
438
+
436
439
  escape_html(result)
437
440
  end
438
441
 
@@ -501,6 +504,7 @@ module Apiwork
501
504
 
502
505
  def build_type_path_lookup
503
506
  lookup = {}
507
+
504
508
  public_api_yard_objects.each do |yard_object|
505
509
  full_path = yard_object.path.delete_prefix('Apiwork::')
506
510
  parts = full_path.split('::')
@@ -541,7 +545,6 @@ module Apiwork
541
545
  resolved = type_path_lookup[class_name] || class_name
542
546
  without_apiwork = resolved.delete_prefix('Apiwork::')
543
547
  parts = without_apiwork.split('::')
544
-
545
548
  return '/reference/' if parts.empty?
546
549
 
547
550
  file_parts = parts.map { |part| dasherize(part) }
@@ -585,10 +588,9 @@ module Apiwork
585
588
  end
586
589
 
587
590
  parts << "#{linkify_yard_refs(mod[:docstring])}\n" if mod[:docstring].present?
588
-
589
591
  render_examples(parts, mod[:examples]) if mod[:examples].any?
590
-
591
592
  children = find_direct_children(mod[:path])
593
+
592
594
  if children.any?
593
595
  parts << "## Modules\n"
594
596
  render_child_links(parts, mod[:path], children)
@@ -613,7 +615,6 @@ module Apiwork
613
615
 
614
616
  def render_method(method, prefix)
615
617
  parts = []
616
-
617
618
  parts << "### #{prefix}#{escape_brackets(method[:name])}\n"
618
619
  parts << "`#{prefix}#{method[:signature]}`\n"
619
620
 
@@ -673,7 +674,6 @@ module Apiwork
673
674
  end
674
675
 
675
676
  render_examples(parts, method[:examples]) if method[:examples].any?
676
-
677
677
  parts << "---\n"
678
678
  parts.join("\n")
679
679
  end
@@ -13,6 +13,7 @@ module Apiwork
13
13
 
14
14
  def find!(key)
15
15
  normalized_key = normalize_key(key)
16
+
16
17
  store.fetch(normalized_key) do
17
18
  raise KeyError.new(
18
19
  "#{registry_name} :#{normalized_key} not found. Available: #{keys.join(', ')}",
@@ -82,7 +82,6 @@ module Apiwork
82
82
  @representation_class = representation
83
83
  validate_representation!
84
84
  @polymorphic = normalize_polymorphic(polymorphic)
85
-
86
85
  @filterable = filterable
87
86
  @sortable = sortable
88
87
  @include = include
@@ -92,9 +91,7 @@ module Apiwork
92
91
  @description = description
93
92
  @example = example
94
93
  @deprecated = deprecated
95
-
96
94
  detect_polymorphic_discriminator! if @polymorphic
97
-
98
95
  validate_include_option!
99
96
  validate_association_exists!
100
97
  validate_polymorphic!
@@ -322,6 +319,7 @@ module Apiwork
322
319
 
323
320
  detail = "Invalid include option ':#{@include}' for association '#{@name}'. " \
324
321
  'Must be :always or :optional'
322
+
325
323
  error = ConfigurationError.new(
326
324
  detail:,
327
325
  code: :invalid_include_option,
@@ -340,6 +338,7 @@ module Apiwork
340
338
  return if reflection
341
339
 
342
340
  detail = "Undefined association '#{@name}' in #{@owner_representation_class.name}: no association on model"
341
+
343
342
  error = ConfigurationError.new(
344
343
  detail:,
345
344
  code: :invalid_association,
@@ -354,6 +353,7 @@ module Apiwork
354
353
  return unless writable?
355
354
 
356
355
  nested_attribute_method = "#{@name}_attributes="
356
+
357
357
  unless @model_class.instance_methods.include?(nested_attribute_method.to_sym)
358
358
  detail = "#{@model_class.name} doesn't accept nested attributes for #{@name}. " \
359
359
  "Add: accepts_nested_attributes_for :#{@name}"