Skip to content

Commit 4267bba

Browse files
authored
Fix build issues with AWS models, and remove enum types (#325)
1 parent 206ab4a commit 4267bba

12 files changed

Lines changed: 225 additions & 261 deletions

File tree

gems/smithy/lib/smithy/templates/client/schema.erb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,20 @@ module <%= module_name %>
3434
<% shape.members.each do |member| -%>
3535
<%= shape.name %>.add_member(:<%= member.name %>, <%= shape.union_type(member) %>, <%= member.initializer %>)
3636
<% end -%>
37-
<%= shape.name %>.add_member(:unknown, Types::<%= shape.name %>::Unknown, Smithy::Schema::Shapes::ShapeRef.new(shape: Smithy::Schema::Shapes::Prelude::Unit))
37+
<%= shape.name %>.add_member(:unknown, Types::<%= shape.name %>::Unknown, ::Smithy::Schema::Shapes::ShapeRef.new(shape: ::Smithy::Schema::Shapes::Prelude::Unit))
3838
<%= shape.name %>.type = <%= shape.type_class %>
3939
<% end -%>
4040
<% end -%>
4141

42-
<%= service_shape.name %> = Smithy::Schema::Shapes::ServiceShape.new do |service|
42+
<%= service_shape.name %> = ::Smithy::Schema::Shapes::ServiceShape.new do |service|
4343
service.id = "<%= service_shape.id %>"
4444
service.name = "<%= service_shape.name %>"
4545
<% if service_shape.version -%>
4646
service.version = "<%= service_shape.version %>"
4747
<% end -%>
4848
service.traits = <%= service_shape.traits %>
4949
<% operation_shapes.each do |shape| -%>
50-
service.add_operation(:<%= shape.name.underscore %>, Smithy::Schema::Shapes::OperationShape.new do |operation|
50+
service.add_operation(:<%= shape.name.underscore %>, ::Smithy::Schema::Shapes::OperationShape.new do |operation|
5151
operation.id = "<%= shape.id %>"
5252
operation.name = "<%= shape.name %>"
5353
operation.input = <%= shape.input.initializer %>
@@ -68,8 +68,8 @@ module <%= module_name %>
6868
def type_registry
6969
return @type_registry if @type_registry
7070

71-
shapes = constants.map { |sym| const_get(sym) }.select { |const| const.is_a?(Smithy::Schema::Shapes::StructureShape) }
72-
@type_registry = Smithy::Schema::TypeRegistry.new(shapes)
71+
shapes = constants.map { |sym| const_get(sym) }.select { |const| const.is_a?(::Smithy::Schema::Shapes::StructureShape) }
72+
@type_registry = ::Smithy::Schema::TypeRegistry.new(shapes)
7373
end
7474
end
7575
end

gems/smithy/lib/smithy/templates/client/types.erb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@ module <%= module_name %>
1111
# <%= docstring %>
1212
<% end -%>
1313
<% case type.type -%>
14-
<% when 'enum', 'intEnum' -%>
15-
module <%= type.name %>
16-
<% type.members.each do |member| -%>
17-
<% member.docstrings.each do |docstring| -%>
18-
# <%= docstring %>
19-
<% end -%>
20-
<%= member.name %> = <%= member.value %>
21-
<% end -%>
22-
end
2314
<% when 'structure' -%>
2415
<% type.attribute_docstrings.each do |docstring| -%>
2516
# <%= docstring %>
@@ -29,7 +20,7 @@ module <%= module_name %>
2920
:<%= member.name.underscore %>,
3021
<% end -%>
3122
keyword_init: true)
32-
include Smithy::Schema::Structure
23+
include ::Smithy::Schema::Structure
3324
<% if !type.input? && type.defaults.any? -%>
3425

3526
def initialize(options = {})
@@ -50,7 +41,7 @@ module <%= module_name %>
5041
<% end -%>
5142
:unknown,
5243
keyword_init: true)
53-
include Smithy::Schema::Union
44+
include ::Smithy::Schema::Union
5445

5546
<% type.members.each do |member| -%>
5647
class <%= member.name.camelize %> < <%= type.name %>; end

gems/smithy/lib/smithy/views/client/paginators.rb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ def paginators
2323
.operations_for(@plan.service)
2424
.map do |id, operation|
2525
operation_trait = paginated_trait(operation)
26-
next if operation_trait.empty?
27-
2826
resolved_trait = @service_trait.merge(operation_trait)
27+
next if resolved_trait.empty?
28+
2929
Paginator.new(Model::Shape.name(id), resolved_trait)
3030
end
3131
.compact
@@ -52,7 +52,6 @@ def next_tokens_code
5252
next_token_getter = output_getter(@output_token)
5353
code = ["next_token = #{next_token_getter}"]
5454
code << 'return {} if next_token.nil? || next_token.empty?'
55-
code << ''
5655
code << 'tokens = Hash.new { |h, k| h[k] = {} }'
5756
next_token_setter = input_getter(@input_token, 'tokens')
5857
code << "#{next_token_setter} = next_token"
@@ -64,7 +63,6 @@ def prev_tokens_code
6463
prev_token_getter = input_getter(@input_token)
6564
code = ["prev_token = #{prev_token_getter}"]
6665
code << 'return {} if prev_token.nil? || prev_token.empty?'
67-
code << ''
6866
code << 'tokens = Hash.new { |h, k| h[k] = {} }'
6967
prev_token_setter = input_getter(@input_token, 'tokens')
7068
code << "#{prev_token_setter} = prev_token"

gems/smithy/lib/smithy/views/client/schema.rb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def initialize(service, id, shape)
169169

170170
def initializer
171171
traits_str = ", traits: #{@traits}" unless @traits.empty?
172-
"Smithy::Schema::Shapes::#{SHAPE_CLASS_MAP[@type]}.new(id: '#{@id}', name: '#{@name}'#{traits_str})"
172+
"::Smithy::Schema::Shapes::#{SHAPE_CLASS_MAP[@type]}.new(id: '#{@id}', name: '#{@name}'#{traits_str})"
173173
end
174174
end
175175

@@ -275,7 +275,7 @@ def type_class
275275
end
276276

277277
def union_type(shape_ref)
278-
"#{type_class}::#{shape_ref.name.camelize}"
278+
"#{type_class}::#{shape_ref.location_name.camelize}"
279279
end
280280

281281
private
@@ -289,7 +289,6 @@ def build_shape_refs(members)
289289
class ShapeRef
290290
OMITTED_TRAITS = %w[
291291
smithy.api#documentation
292-
smithy.api#httpPayload
293292
].freeze
294293

295294
PRELUDE_SHAPES_MAP = {
@@ -321,28 +320,24 @@ def initialize(service, location_name, shape_ref)
321320
@name = location_name.underscore if location_name
322321
@location_name = location_name
323322
@shape = shape(shape_ref['target'])
324-
@traits = shape_ref.fetch('traits', {})
323+
@traits = shape_ref.fetch('traits', {}).except(*OMITTED_TRAITS)
325324
end
326325

327-
attr_reader :name
326+
attr_reader :name, :location_name
328327

329328
def initializer
330329
options_str = "shape: #{@shape}"
331330
options_str += ", location_name: '#{@location_name}'" if @location_name
332331
options_str += ", traits: #{@traits}" unless @traits.empty?
333-
"Smithy::Schema::Shapes::ShapeRef.new(#{options_str})"
332+
"::Smithy::Schema::Shapes::ShapeRef.new(#{options_str})"
334333
end
335334

336335
def shape(id)
337-
return "Smithy::Schema::Shapes::#{PRELUDE_SHAPES_MAP[id]}" if PRELUDE_SHAPES_MAP.key?(id)
336+
return "::Smithy::Schema::Shapes::#{PRELUDE_SHAPES_MAP[id]}" if PRELUDE_SHAPES_MAP.key?(id)
338337

339338
(@service.dig('rename', id) || Model::Shape.name(id)).camelize
340339
end
341340

342-
def traits
343-
@traits.except(*OMITTED_TRAITS)
344-
end
345-
346341
def http_payload?
347342
@traits.key?('smithy.api#httpPayload')
348343
end

gems/smithy/lib/smithy/views/client/types.rb

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def types
1919
Model::ServiceIndex
2020
.new(@model)
2121
.shapes_for(@plan.service)
22-
.select { |_key, shape| %w[enum intEnum structure union].include?(shape['type']) }
22+
.select { |_key, shape| %w[structure union].include?(shape['type']) }
2323
.map { |id, shape| build_type(id, shape) }
2424
end
2525

@@ -28,7 +28,6 @@ def types
2828
def build_type(id, shape)
2929
args = [@plan.service, @model, id, shape]
3030
case shape['type']
31-
when 'enum', 'intEnum' then EnumType.new(*args)
3231
when 'structure' then StructureType.new(*args)
3332
when 'union' then UnionType.new(*args)
3433
end
@@ -99,15 +98,6 @@ def unstable_docstrings
9998
end
10099
end
101100

102-
# @api private
103-
class EnumType < Type
104-
private
105-
106-
def build_members(members)
107-
members.map { |name, member| EnumMember.new(@service, @model, name, member) }
108-
end
109-
end
110-
111101
# @api private
112102
class StructureType < Type
113103
def input?
@@ -208,21 +198,6 @@ def unstable_docstrings
208198
end
209199
end
210200

211-
# @api private
212-
class EnumMember < Member
213-
def value
214-
value = @traits['smithy.api#enumValue']
215-
case value
216-
when String then "'#{value}'"
217-
else value
218-
end
219-
end
220-
221-
def documentation_docstrings
222-
@member.fetch('traits', {}).fetch('smithy.api#documentation', '').split("\n")
223-
end
224-
end
225-
226201
# @api private
227202
class StructMember < Member
228203
def docstrings # rubocop:disable Metrics/AbcSize
@@ -244,9 +219,10 @@ def default?
244219

245220
def default
246221
default = @member.dig('traits', 'smithy.api#default')
222+
return 'nil' if default.nil?
223+
247224
case @target['type']
248225
when 'blob' then "Base64.strict_decode64('#{default}')"
249-
when 'bigDecimal' then "BigDecimal('#{default}')"
250226
when 'document' then document_default(default)
251227
when 'enum', 'string' then "'#{default}'"
252228
when 'timestamp' then timestamp_default(default)
@@ -273,7 +249,6 @@ def return_docstrings
273249

274250
def document_default(default)
275251
case default
276-
when nil then 'nil'
277252
when String then "'#{default}'"
278253
else default
279254
end
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"smithy": "2.0",
3+
"shapes": {
4+
"smithy.ruby.tests#InheritedTraitOperation": {
5+
"type": "operation",
6+
"input": {
7+
"target": "smithy.ruby.tests#OperationInputOutput"
8+
},
9+
"output": {
10+
"target": "smithy.ruby.tests#OperationInputOutput"
11+
}
12+
},
13+
"smithy.ruby.tests#Items": {
14+
"type": "list",
15+
"member": {
16+
"target": "smithy.api#String"
17+
}
18+
},
19+
"smithy.ruby.tests#MergedTraitOperation": {
20+
"type": "operation",
21+
"input": {
22+
"target": "smithy.ruby.tests#OperationInputOutput"
23+
},
24+
"output": {
25+
"target": "smithy.ruby.tests#OperationInputOutput"
26+
},
27+
"traits": {
28+
"smithy.api#paginated": {
29+
"inputToken": "outputToken",
30+
"outputToken": "inputToken",
31+
"items": "items"
32+
}
33+
}
34+
},
35+
"smithy.ruby.tests#OperationInputOutput": {
36+
"type": "structure",
37+
"members": {
38+
"inputToken": {
39+
"target": "smithy.api#String"
40+
},
41+
"outputToken": {
42+
"target": "smithy.api#String"
43+
},
44+
"pageSize": {
45+
"target": "smithy.api#Integer"
46+
},
47+
"items": {
48+
"target": "smithy.ruby.tests#Items"
49+
}
50+
}
51+
},
52+
"smithy.ruby.tests#PaginatedService": {
53+
"type": "service",
54+
"operations": [
55+
{
56+
"target": "smithy.ruby.tests#InheritedTraitOperation"
57+
},
58+
{
59+
"target": "smithy.ruby.tests#MergedTraitOperation"
60+
}
61+
],
62+
"traits": {
63+
"smithy.api#paginated": {
64+
"inputToken": "inputToken",
65+
"outputToken": "outputToken",
66+
"pageSize": "pageSize"
67+
}
68+
}
69+
}
70+
}
71+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
$version: "2.0"
2+
3+
namespace smithy.ruby.tests
4+
5+
@paginated(inputToken: "inputToken", outputToken: "outputToken", pageSize: "pageSize")
6+
service PaginatedService {
7+
operations: [
8+
InheritedTraitOperation,
9+
MergedTraitOperation
10+
]
11+
}
12+
13+
operation InheritedTraitOperation {
14+
input: OperationInputOutput
15+
output: OperationInputOutput
16+
}
17+
18+
@paginated(inputToken: "outputToken", outputToken: "inputToken", items: "items")
19+
operation MergedTraitOperation {
20+
input: OperationInputOutput
21+
output: OperationInputOutput
22+
}
23+
24+
structure OperationInputOutput {
25+
inputToken: String
26+
outputToken: String
27+
pageSize: Integer
28+
items: Items
29+
}
30+
31+
list Items {
32+
member: String
33+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"smithy": "2.0",
3+
"shapes": {
4+
"smithy.ruby.tests#OperationInputOutput": {
5+
"type": "structure",
6+
"members": {
7+
"inputToken": {
8+
"target": "smithy.api#String"
9+
},
10+
"outputToken": {
11+
"target": "smithy.api#String"
12+
}
13+
}
14+
},
15+
"smithy.ruby.tests#PaginatedOperation": {
16+
"type": "operation",
17+
"input": {
18+
"target": "smithy.ruby.tests#OperationInputOutput"
19+
},
20+
"output": {
21+
"target": "smithy.ruby.tests#OperationInputOutput"
22+
},
23+
"traits": {
24+
"smithy.api#paginated": {
25+
"inputToken": "inputToken",
26+
"outputToken": "outputToken"
27+
}
28+
}
29+
},
30+
"smithy.ruby.tests#PaginatedService": {
31+
"type": "service",
32+
"operations": [
33+
{
34+
"target": "smithy.ruby.tests#PaginatedOperation"
35+
},
36+
{
37+
"target": "smithy.ruby.tests#UnpaginatedOperation"
38+
}
39+
]
40+
},
41+
"smithy.ruby.tests#UnpaginatedOperation": {
42+
"type": "operation",
43+
"input": {
44+
"target": "smithy.ruby.tests#OperationInputOutput"
45+
},
46+
"output": {
47+
"target": "smithy.ruby.tests#OperationInputOutput"
48+
}
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)