apiwork 0.6.0 → 0.7.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/lib/apiwork/adapter/serializer/error/default/api_builder.rb +6 -1
  3. data/lib/apiwork/adapter/serializer/resource/default/contract_builder.rb +2 -0
  4. data/lib/apiwork/adapter/standard/capability/writing/contract_builder.rb +1 -0
  5. data/lib/apiwork/api/base.rb +31 -0
  6. data/lib/apiwork/api/object.rb +12 -12
  7. data/lib/apiwork/contract/object.rb +74 -74
  8. data/lib/apiwork/controller.rb +6 -2
  9. data/lib/apiwork/export/apiwork.rb +20 -0
  10. data/lib/apiwork/export/apiwork_mapper.rb +232 -0
  11. data/lib/apiwork/export/open_api.rb +2 -0
  12. data/lib/apiwork/export/registry.rb +1 -1
  13. data/lib/apiwork/export/sorbus.rb +1 -5
  14. data/lib/apiwork/export/type_script.rb +1 -4
  15. data/lib/apiwork/export/type_script_mapper.rb +12 -4
  16. data/lib/apiwork/export/zod.rb +0 -9
  17. data/lib/apiwork/export/zod_mapper.rb +22 -1
  18. data/lib/apiwork/export.rb +1 -0
  19. data/lib/apiwork/introspection/api/resource.rb +9 -0
  20. data/lib/apiwork/introspection/dump/param.rb +9 -10
  21. data/lib/apiwork/introspection/dump/resource.rb +3 -1
  22. data/lib/apiwork/introspection/dump/type.rb +15 -4
  23. data/lib/apiwork/introspection/enum.rb +9 -0
  24. data/lib/apiwork/introspection/param/array.rb +3 -0
  25. data/lib/apiwork/introspection/param/base.rb +11 -0
  26. data/lib/apiwork/introspection/param/binary.rb +3 -0
  27. data/lib/apiwork/introspection/param/boolean.rb +3 -0
  28. data/lib/apiwork/introspection/param/date.rb +3 -0
  29. data/lib/apiwork/introspection/param/date_time.rb +3 -0
  30. data/lib/apiwork/introspection/param/decimal.rb +3 -0
  31. data/lib/apiwork/introspection/param/integer.rb +3 -0
  32. data/lib/apiwork/introspection/param/number.rb +3 -0
  33. data/lib/apiwork/introspection/param/record.rb +3 -0
  34. data/lib/apiwork/introspection/param/string.rb +3 -0
  35. data/lib/apiwork/introspection/param/time.rb +3 -0
  36. data/lib/apiwork/introspection/param/uuid.rb +3 -0
  37. data/lib/apiwork/introspection/type.rb +9 -0
  38. data/lib/apiwork/issue.rb +1 -1
  39. data/lib/apiwork/object.rb +99 -99
  40. data/lib/apiwork/reference_generator.rb +43 -0
  41. data/lib/apiwork/representation/attribute.rb +98 -2
  42. data/lib/apiwork/representation/base.rb +9 -0
  43. data/lib/apiwork/representation/serializer.rb +2 -0
  44. data/lib/apiwork/version.rb +1 -1
  45. data/lib/apiwork.rb +4 -0
  46. metadata +4 -3
  47. data/lib/apiwork/export/builder_mapper.rb +0 -184
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e82aa84563a02e2459a6d464c65cd50e5bb3edcb762a0a5b9412e79475663c52
4
- data.tar.gz: ac7da6d7f57a6be553fa8809da6f449029ac9d9c42e4da24c780e9f4364c1a4a
3
+ metadata.gz: 7614067b7732803415ef2038394b28590c02e63734cdf9b879aab126dcb1caee
4
+ data.tar.gz: 2a7399c16a27c51c64e92811e7c020b863de65e4fdaaa7f4e400d7c8c308a94b
5
5
  SHA512:
6
- metadata.gz: 4f7bd06c06cb8485762e066e8efb64d21af6258b85442bbbc9813b1359e3d38706314dd285fe48de42d8a5526590c08508c436abdb8acfe0c23c203ade8391db
7
- data.tar.gz: 7ce587bd8232382e56a8f5da4ba33d1dd942482e018e1e968aacb1f1a6be8bb778d85dec4ee425799a350b0afdd7a4c7277c264b661209bb16f6404e7ec9bf32
6
+ metadata.gz: 58e21417d9e0fa2e6d4bd05106f4619282fc2925af365433902392f2d841eda8e4035ffb4800e0dbd96a09cf513a507237b6ec0bb31de2f648c48d8e6bd00b38
7
+ data.tar.gz: de1ce6873f0c20373ce9bab1cd8e70b4b1787b6ae9adbf2f5fcb1c65720df33e45ad05aea524a8720837a777b7e50059c8a9d02240a1ddff57e9d69ad6422caf
@@ -12,7 +12,12 @@ module Apiwork
12
12
  object(:error_issue) do |object|
13
13
  object.string(:code)
14
14
  object.string(:detail)
15
- object.array(:path, &:string)
15
+ object.array(:path) do |array|
16
+ array.of(:union) do |union|
17
+ union.variant(&:string)
18
+ union.variant(&:integer)
19
+ end
20
+ end
16
21
  object.string(:pointer)
17
22
  object.object(:meta)
18
23
  end
@@ -59,6 +59,8 @@ module Apiwork
59
59
  end
60
60
 
61
61
  representation_class.attributes.each do |name, attribute|
62
+ next if attribute.write_only?
63
+
62
64
  param_options = {
63
65
  deprecated: attribute.deprecated?,
64
66
  description: attribute.description,
@@ -168,6 +168,7 @@ module Apiwork
168
168
  type: attribute.type,
169
169
  }
170
170
 
171
+ options[:default] = attribute.default if attribute.default? && action_name == :create
171
172
  options[:min] = attribute.min if attribute.min
172
173
  options[:max] = attribute.max if attribute.max
173
174
  options[:of] = attribute.of if attribute.of
@@ -763,6 +763,13 @@ module Apiwork
763
763
  result.transform { |hash| hash.deep_transform_keys { |key| transform_key(key).to_sym } }
764
764
  end
765
765
 
766
+ def prepare_error_response(response)
767
+ result = prepare_response(response)
768
+ return result if key_format == :keep
769
+
770
+ result.transform { |body| transform_issue_paths(body) }
771
+ end
772
+
766
773
  def type?(name, scope: nil)
767
774
  type_registry.exists?(name, scope:)
768
775
  end
@@ -838,6 +845,30 @@ module Apiwork
838
845
 
839
846
  private
840
847
 
848
+ def transform_issue_paths(body)
849
+ return body unless body.is_a?(Hash)
850
+ return body unless body[:issues].is_a?(Array)
851
+
852
+ body.merge(issues: body[:issues].map { |issue| transform_issue_path(issue) })
853
+ end
854
+
855
+ def transform_issue_path(issue)
856
+ return issue unless issue.is_a?(Hash)
857
+
858
+ result = issue.dup
859
+ result[:path] = transform_path_segments(result[:path]) if result[:path].is_a?(Array)
860
+ result[:pointer] = transform_pointer_segments(result[:pointer]) if result[:pointer].is_a?(String)
861
+ result
862
+ end
863
+
864
+ def transform_path_segments(segments)
865
+ segments.map { |segment| segment.is_a?(String) ? transform_key(segment) : segment }
866
+ end
867
+
868
+ def transform_pointer_segments(pointer)
869
+ pointer.split('/').map { |segment| segment.empty? ? segment : transform_key(segment) }.join('/')
870
+ end
871
+
841
872
  def extract_namespaces(mount_path)
842
873
  return [] if mount_path.nil? || mount_path == '/'
843
874
 
@@ -36,8 +36,8 @@ module Apiwork
36
36
  # The param type.
37
37
  # @param as [Symbol, nil] (nil)
38
38
  # The target attribute name.
39
- # @param default [Object, nil] (nil)
40
- # The default value.
39
+ # @param default [Object] (UNSET)
40
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
41
41
  # @param deprecated [Boolean] (false)
42
42
  # Whether deprecated. Metadata included in exports.
43
43
  # @param description [String, nil] (nil)
@@ -86,7 +86,7 @@ module Apiwork
86
86
  type: nil,
87
87
  as: nil,
88
88
  custom_type: nil,
89
- default: nil,
89
+ default: UNSET,
90
90
  deprecated: false,
91
91
  description: nil,
92
92
  discriminator: nil,
@@ -110,7 +110,6 @@ module Apiwork
110
110
  param_hash = {
111
111
  as:,
112
112
  custom_type:,
113
- default:,
114
113
  deprecated:,
115
114
  description:,
116
115
  discriminator:,
@@ -126,10 +125,11 @@ module Apiwork
126
125
  type:,
127
126
  value:,
128
127
  of: resolved_of,
129
- }
128
+ }.compact
129
+ param_hash[:default] = default unless UNSET.equal?(default)
130
130
  param_hash[:shape] = resolved_shape if resolved_shape
131
131
 
132
- @params[name] = (@params[name] || {}).merge(param_hash.compact)
132
+ @params[name] = (@params[name] || {}).merge(param_hash)
133
133
  end
134
134
 
135
135
  # @api public
@@ -139,8 +139,8 @@ module Apiwork
139
139
  # The param name.
140
140
  # @param as [Symbol, nil] (nil)
141
141
  # The target attribute name.
142
- # @param default [Object, nil] (nil)
143
- # The default value.
142
+ # @param default [Object] (UNSET)
143
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
144
144
  # @param deprecated [Boolean] (false)
145
145
  # Whether deprecated. Metadata included in exports.
146
146
  # @param description [String, nil] (nil)
@@ -167,7 +167,7 @@ module Apiwork
167
167
  def array(
168
168
  name,
169
169
  as: nil,
170
- default: nil,
170
+ default: UNSET,
171
171
  deprecated: false,
172
172
  description: nil,
173
173
  nullable: false,
@@ -202,8 +202,8 @@ module Apiwork
202
202
  # The param name.
203
203
  # @param as [Symbol, nil] (nil)
204
204
  # The target attribute name.
205
- # @param default [Object, nil] (nil)
206
- # The default value.
205
+ # @param default [Object] (UNSET)
206
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
207
207
  # @param deprecated [Boolean] (false)
208
208
  # Whether deprecated. Metadata included in exports.
209
209
  # @param description [String, nil] (nil)
@@ -230,7 +230,7 @@ module Apiwork
230
230
  def record(
231
231
  name,
232
232
  as: nil,
233
- default: nil,
233
+ default: UNSET,
234
234
  deprecated: false,
235
235
  description: nil,
236
236
  nullable: false,
@@ -60,8 +60,8 @@ module Apiwork
60
60
  # The param type.
61
61
  # @param as [Symbol, nil] (nil)
62
62
  # The target attribute name.
63
- # @param default [Object, nil] (nil)
64
- # The default value.
63
+ # @param default [Object] (UNSET)
64
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
65
65
  # @param deprecated [Boolean] (false)
66
66
  # Whether deprecated. Metadata included in exports.
67
67
  # @param description [String, nil] (nil)
@@ -110,7 +110,7 @@ module Apiwork
110
110
  type: nil,
111
111
  as: nil,
112
112
  custom_type: nil,
113
- default: nil,
113
+ default: UNSET,
114
114
  deprecated: false,
115
115
  description: nil,
116
116
  discriminator: nil,
@@ -183,8 +183,8 @@ module Apiwork
183
183
  # The param name.
184
184
  # @param as [Symbol, nil] (nil)
185
185
  # The target attribute name.
186
- # @param default [Object, nil] (nil)
187
- # The default value.
186
+ # @param default [Object] (UNSET)
187
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
188
188
  # @param deprecated [Boolean] (false)
189
189
  # Whether deprecated. Metadata included in exports.
190
190
  # @param description [String, nil] (nil)
@@ -215,7 +215,7 @@ module Apiwork
215
215
  def array(
216
216
  name,
217
217
  as: nil,
218
- default: nil,
218
+ default: UNSET,
219
219
  deprecated: false,
220
220
  description: nil,
221
221
  max: nil,
@@ -254,8 +254,8 @@ module Apiwork
254
254
  # The param name.
255
255
  # @param as [Symbol, nil] (nil)
256
256
  # The target attribute name.
257
- # @param default [Object, nil] (nil)
258
- # The default value.
257
+ # @param default [Object] (UNSET)
258
+ # The default value. Omit to declare no default. Pass `nil` for an explicit null default.
259
259
  # @param deprecated [Boolean] (false)
260
260
  # Whether deprecated. Metadata included in exports.
261
261
  # @param description [String, nil] (nil)
@@ -282,7 +282,7 @@ module Apiwork
282
282
  def record(
283
283
  name,
284
284
  as: nil,
285
- default: nil,
285
+ default: UNSET,
286
286
  deprecated: false,
287
287
  description: nil,
288
288
  nullable: false,
@@ -395,18 +395,18 @@ module Apiwork
395
395
  def define_literal_param(name, as:, default:, deprecated:, description:, optional:, value:)
396
396
  raise ConfigurationError, 'Literal type requires a value parameter' if value.nil?
397
397
 
398
- @params[name] = (@params[name] || {}).merge(
399
- {
400
- as:,
401
- default:,
402
- deprecated:,
403
- description:,
404
- name:,
405
- optional:,
406
- value:,
407
- type: :literal,
408
- }.compact,
409
- )
398
+ params = {
399
+ as:,
400
+ deprecated:,
401
+ description:,
402
+ name:,
403
+ optional:,
404
+ value:,
405
+ type: :literal,
406
+ }.compact
407
+ params[:default] = default unless UNSET.equal?(default)
408
+
409
+ @params[name] = (@params[name] || {}).merge(params)
410
410
  end
411
411
 
412
412
  def define_union_param(name, as:, default:, discriminator:, optional:, options:, resolved_enum:, &block)
@@ -415,19 +415,19 @@ module Apiwork
415
415
  union = Union.new(@contract_class, discriminator:)
416
416
  block.arity.positive? ? yield(union) : union.instance_eval(&block)
417
417
 
418
- @params[name] = (@params[name] || {}).merge(
419
- {
420
- as:,
421
- default:,
422
- discriminator:,
423
- enum: resolved_enum,
424
- name:,
425
- optional:,
426
- type: :union,
427
- union:,
428
- **options,
429
- }.compact,
430
- )
418
+ params = {
419
+ as:,
420
+ discriminator:,
421
+ enum: resolved_enum,
422
+ name:,
423
+ optional:,
424
+ type: :union,
425
+ union:,
426
+ **options,
427
+ }.compact
428
+ params[:default] = default unless UNSET.equal?(default)
429
+
430
+ @params[name] = (@params[name] || {}).merge(params)
431
431
  end
432
432
 
433
433
  def define_regular_param(name, as:, default:, of:, optional:, options:, resolved_enum:, shape:, type:, visited_types:, &block)
@@ -514,20 +514,20 @@ module Apiwork
514
514
  end
515
515
  end
516
516
 
517
- @params[name] = (@params[name] || {}).merge(
518
- {
519
- as:,
520
- custom_type: type,
521
- default:,
522
- discriminator: type_definition.discriminator,
523
- enum: resolved_enum,
524
- name:,
525
- optional:,
526
- type: :union,
527
- union:,
528
- **options,
529
- }.compact,
530
- )
517
+ params = {
518
+ as:,
519
+ custom_type: type,
520
+ discriminator: type_definition.discriminator,
521
+ enum: resolved_enum,
522
+ name:,
523
+ optional:,
524
+ type: :union,
525
+ union:,
526
+ **options,
527
+ }.compact
528
+ params[:default] = default unless UNSET.equal?(default)
529
+
530
+ @params[name] = (@params[name] || {}).merge(params)
531
531
  end
532
532
 
533
533
  def define_custom_type_param(
@@ -557,38 +557,38 @@ module Apiwork
557
557
  block.arity.positive? ? yield(shape) : shape.instance_eval(&block)
558
558
  end
559
559
 
560
- @params[name] = (@params[name] || {}).merge(
561
- {
562
- as:,
563
- custom_type: type,
564
- default:,
565
- enum: resolved_enum,
566
- name:,
567
- of:,
568
- optional:,
569
- shape:,
570
- type: :object,
571
- **options,
572
- }.compact,
573
- )
560
+ params = {
561
+ as:,
562
+ custom_type: type,
563
+ enum: resolved_enum,
564
+ name:,
565
+ of:,
566
+ optional:,
567
+ shape:,
568
+ type: :object,
569
+ **options,
570
+ }.compact
571
+ params[:default] = default unless UNSET.equal?(default)
572
+
573
+ @params[name] = (@params[name] || {}).merge(params)
574
574
  end
575
575
 
576
576
  def define_standard_param(name, as:, default:, of:, optional:, options:, resolved_enum:, shape:, type:, &block)
577
577
  resolved_of = resolve_of(of, type, &block)
578
578
  resolved_shape = resolve_shape(shape, type, &block)
579
579
 
580
- @params[name] = (@params[name] || {}).merge(
581
- {
582
- as:,
583
- default:,
584
- enum: resolved_enum,
585
- name:,
586
- of: resolved_of,
587
- optional:,
588
- type:,
589
- **options,
590
- }.compact,
591
- )
580
+ params = {
581
+ as:,
582
+ enum: resolved_enum,
583
+ name:,
584
+ of: resolved_of,
585
+ optional:,
586
+ type:,
587
+ **options,
588
+ }.compact
589
+ params[:default] = default unless UNSET.equal?(default)
590
+
591
+ @params[name] = (@params[name] || {}).merge(params)
592
592
 
593
593
  @params[name][:shape] = resolved_shape if resolved_shape
594
594
  end
@@ -245,8 +245,12 @@ module Apiwork
245
245
 
246
246
  def render_error(error)
247
247
  representation_class = resource ? contract_class.representation_class : nil
248
- json = adapter.process_error(error, representation_class, context:)
249
- render json:, status: error.status
248
+ body = adapter.process_error(error, representation_class, context:)
249
+
250
+ response = Response.new(body:)
251
+ response = api_class.prepare_error_response(response)
252
+
253
+ render json: response.body, status: error.status
250
254
  end
251
255
 
252
256
  def contract_class
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apiwork
4
+ module Export
5
+ class Apiwork < Base
6
+ export_name :apiwork
7
+ output :hash
8
+
9
+ def generate
10
+ ApiworkMapper.map(self, surface)
11
+ end
12
+
13
+ private
14
+
15
+ def surface
16
+ @surface ||= SurfaceResolver.resolve(api)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,232 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apiwork
4
+ module Export
5
+ class ApiworkMapper
6
+ class << self
7
+ def map(export, surface)
8
+ new(export).map(surface)
9
+ end
10
+ end
11
+
12
+ def initialize(export)
13
+ @export = export
14
+ end
15
+
16
+ def map(surface)
17
+ {
18
+ base_path: @export.api.base_path,
19
+ enums: serialize_enums(surface.enums),
20
+ error_codes: serialize_error_codes,
21
+ fingerprint: @export.api.fingerprint,
22
+ info: serialize_info,
23
+ locales: @export.api.locales.map(&:to_s),
24
+ resources: serialize_resources(@export.api.resources),
25
+ types: serialize_types(surface.types),
26
+ }
27
+ end
28
+
29
+ private
30
+
31
+ def serialize_enums(enums)
32
+ enums.map do |name, enum|
33
+ {
34
+ deprecated: enum.deprecated?,
35
+ description: enum.description,
36
+ example: enum.example,
37
+ name: name.to_s,
38
+ scope: enum.scope,
39
+ values: enum.values,
40
+ }
41
+ end
42
+ end
43
+
44
+ def serialize_error_codes
45
+ @export.api.error_codes.map do |name, error_code|
46
+ {
47
+ description: error_code.description,
48
+ name: name.to_s,
49
+ status: error_code.status,
50
+ }
51
+ end
52
+ end
53
+
54
+ def serialize_info
55
+ info = @export.api.info
56
+ return unless info
57
+
58
+ {
59
+ contact: info.contact && {
60
+ email: info.contact.email,
61
+ name: info.contact.name,
62
+ url: info.contact.url,
63
+ },
64
+ description: info.description,
65
+ license: info.license && {
66
+ name: info.license.name,
67
+ url: info.license.url,
68
+ },
69
+ servers: info.servers.map do |server|
70
+ { description: server.description, url: server.url }
71
+ end,
72
+ summary: info.summary,
73
+ terms_of_service: info.terms_of_service,
74
+ title: info.title,
75
+ version: info.version,
76
+ }
77
+ end
78
+
79
+ def serialize_types(types)
80
+ type_hashes = types.transform_values(&:to_h)
81
+ sorted = TypeAnalysis.topological_sort_types(type_hashes)
82
+ recursive = TypeAnalysis.cycle_breaking_types(type_hashes)
83
+
84
+ sorted.map { |name, _| serialize_type(name, types[name], recursive: recursive.include?(name)) }
85
+ end
86
+
87
+ def serialize_type(name, type, recursive:)
88
+ result = {
89
+ recursive:,
90
+ deprecated: type.deprecated?,
91
+ description: type.description,
92
+ example: type.example,
93
+ name: name.to_s,
94
+ scope: type.scope,
95
+ type: type.type.to_s,
96
+ }
97
+
98
+ if type.object?
99
+ result[:extends] = type.extends.map(&:to_s)
100
+ result[:shape] = serialize_shape(type.shape)
101
+ else
102
+ result[:discriminator] = transform_key(type.discriminator)
103
+ result[:variants] = type.variants.map do |variant|
104
+ serialized = serialize_param(variant)
105
+ serialized[:tag] = variant.tag if variant.respond_to?(:tag) && variant.tag
106
+ serialized
107
+ end
108
+ end
109
+
110
+ result
111
+ end
112
+
113
+ def serialize_resources(resources, prefix: nil)
114
+ resources.map do |name, resource|
115
+ qualified_name = prefix ? "#{prefix}.#{name}" : name.to_s
116
+
117
+ {
118
+ actions: resource.actions.map do |action_name, action|
119
+ serialize_action(action, name: "#{qualified_name}.#{action_name}")
120
+ end,
121
+ identifier: resource.identifier.to_s,
122
+ name: name.to_s,
123
+ parent_identifiers: resource.parent_identifiers.map(&:to_s),
124
+ path: transform_path(resource.path),
125
+ resources: serialize_resources(resource.resources, prefix: qualified_name),
126
+ scope: resource.scope,
127
+ }
128
+ end
129
+ end
130
+
131
+ def serialize_action(action, name:)
132
+ {
133
+ name:,
134
+ deprecated: action.deprecated?,
135
+ description: action.description,
136
+ method: action.method.to_s,
137
+ operation_id: action.operation_id,
138
+ path: transform_path(action.path),
139
+ raises: action.raises.map(&:to_s),
140
+ request: {
141
+ body: serialize_shape(action.request.body),
142
+ description: action.request.description,
143
+ query: serialize_shape(action.request.query),
144
+ },
145
+ response: {
146
+ body: serialize_response_body(action.response),
147
+ description: action.response.description,
148
+ no_content: action.response.no_content?,
149
+ },
150
+ summary: action.summary,
151
+ tags: action.tags,
152
+ }
153
+ end
154
+
155
+ def serialize_response_body(response)
156
+ return unless response.body?
157
+
158
+ serialize_param(response.body)
159
+ end
160
+
161
+ def serialize_shape(params)
162
+ params.sort_by { |name, _| name.to_s }.map do |name, param|
163
+ { name: transform_key(name) }.merge(serialize_param(param))
164
+ end
165
+ end
166
+
167
+ def serialize_param(param)
168
+ result = {
169
+ deprecated: param.deprecated?,
170
+ description: param.description,
171
+ nullable: param.nullable?,
172
+ optional: param.optional?,
173
+ type: param.type.to_s,
174
+ }
175
+
176
+ case param.type
177
+ when :string, :integer
178
+ result[:default] = param.default if param.default?
179
+ result[:enum] = param.enum.to_s if param.enum?
180
+ result[:example] = param.example
181
+ result[:format] = param.format
182
+ result[:max] = param.max
183
+ result[:min] = param.min
184
+ when :number, :decimal
185
+ result[:default] = param.default if param.default?
186
+ result[:enum] = param.enum.to_s if param.enum?
187
+ result[:example] = param.example
188
+ result[:max] = param.max
189
+ result[:min] = param.min
190
+ when :boolean, :date, :datetime, :time, :uuid, :binary
191
+ result[:default] = param.default if param.default?
192
+ result[:enum] = param.enum.to_s if param.enum?
193
+ result[:example] = param.example
194
+ when :literal
195
+ result[:value] = param.value
196
+ when :array
197
+ result[:default] = param.default if param.default?
198
+ result[:example] = param.example
199
+ result[:max] = param.max
200
+ result[:min] = param.min
201
+ result[:of] = param.of ? serialize_param(param.of) : nil
202
+ when :record
203
+ result[:default] = param.default if param.default?
204
+ result[:example] = param.example
205
+ result[:of] = param.of ? serialize_param(param.of) : nil
206
+ when :object
207
+ result[:partial] = param.partial?
208
+ result[:shape] = serialize_shape(param.shape)
209
+ when :union
210
+ result[:discriminator] = transform_key(param.discriminator)
211
+ result[:variants] = param.variants.map do |variant|
212
+ serialized = serialize_param(variant)
213
+ serialized[:tag] = variant.tag if variant.respond_to?(:tag) && variant.tag
214
+ serialized
215
+ end
216
+ when :reference
217
+ result[:reference] = param.reference.to_s
218
+ end
219
+
220
+ result
221
+ end
222
+
223
+ def transform_path(path)
224
+ path.to_s.gsub(/:(\w+)/) { ":#{transform_key(::Regexp.last_match(1))}" }
225
+ end
226
+
227
+ def transform_key(key)
228
+ @export.transform_key(key)
229
+ end
230
+ end
231
+ end
232
+ end
@@ -324,6 +324,8 @@ module Apiwork
324
324
 
325
325
  schema[:format] = param.format.to_s if param.formattable? && param.format
326
326
 
327
+ schema[:default] = param.default if param.respond_to?(:default) && param.default?
328
+
327
329
  apply_nullable(schema, param.nullable?)
328
330
  end
329
331
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Apiwork
4
4
  module Export
5
- class Registry < Apiwork::Registry
5
+ class Registry < ::Apiwork::Registry
6
6
  class << self
7
7
  def register(export_class)
8
8
  raise ArgumentError, 'Export must inherit from Apiwork::Export::Base' unless export_class < Base