Skip to content

Commit

Permalink
Fix shapes_for to incldue list and map members (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextwoods authored Jan 3, 2025
1 parent 76a6801 commit 2a9c248
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 5 deletions.
15 changes: 14 additions & 1 deletion gems/smithy/lib/smithy/vise/structure_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,20 @@ def parse_member(member_ref, shapes, visited)
shape = @shapes[target]
shapes[target] = shape
visited[target] = true
shape['members']&.each_value { |member| parse_member(member, shapes, visited) }
parse_members(shape, shapes, visited)
end

def parse_members(shape, shapes, visited)
case shape['type']
when 'list'
parse_member(shape['member'], shapes, visited)
when 'map'
parse_member(shape['key'], shapes, visited)
parse_member(shape['value'], shapes, visited)
else
# covers all other shapes including structure, union, enum
shape['members']&.each_value { |member| parse_member(member, shapes, visited) }
end
end
end
end
Expand Down
37 changes: 36 additions & 1 deletion gems/smithy/spec/fixtures/service_index/model.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
"smithy.api#idempotent": {}
}
},
"smithy.ruby.tests#List": {
"type": "list",
"member": {
"target": "smithy.ruby.tests#ListMember"
}
},
"smithy.ruby.tests#ListMember": {
"type": "string"
},
"smithy.ruby.tests#ListResources": {
"type": "operation",
"input": {
Expand All @@ -43,6 +52,21 @@
"smithy.api#readonly": {}
}
},
"smithy.ruby.tests#Map": {
"type": "map",
"key": {
"target": "smithy.ruby.tests#MapKey"
},
"value": {
"target": "smithy.ruby.tests#MapValue"
}
},
"smithy.ruby.tests#MapKey": {
"type": "string"
},
"smithy.ruby.tests#MapValue": {
"type": "string"
},
"smithy.ruby.tests#NestedResource": {
"type": "resource",
"identifiers": {
Expand All @@ -68,7 +92,7 @@
"smithy.ruby.tests#Operation": {
"type": "operation",
"input": {
"target": "smithy.ruby.tests#Structure"
"target": "smithy.ruby.tests#OperationInput"
},
"output": {
"target": "smithy.ruby.tests#Structure"
Expand All @@ -90,6 +114,17 @@
"smithy.api#error": "client"
}
},
"smithy.ruby.tests#OperationInput": {
"type": "structure",
"members": {
"map": {
"target": "smithy.ruby.tests#Map"
},
"list": {
"target": "smithy.ruby.tests#List"
}
}
},
"smithy.ruby.tests#OrphanedError": {
"type": "structure",
"members": {},
Expand Down
23 changes: 22 additions & 1 deletion gems/smithy/spec/fixtures/service_index/model.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ resource NestedResource {
}

operation Operation {
input: Structure
input: OperationInput
output: Structure
errors: [OperationError]
}
Expand Down Expand Up @@ -68,13 +68,34 @@ operation NestedResourceOperation {
input: Structure
}

structure OperationInput {
map: Map
list: List
}


@documentation("This is a structure shape.")
structure Structure {
@required
id: String
name: String
}

list List {
member: ListMember
}

string ListMember

map Map {
key: MapKey
value: MapValue
}

string MapKey

string MapValue

@error("client")
structure ServiceError {
member: String
Expand Down
6 changes: 4 additions & 2 deletions gems/smithy/spec/interfaces/weld_spec.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# frozen_string_literal: true

describe 'Types: Welding' do
# rubocop:disable Lint/UselessAssignment
before(:all) do
# Define Weld classes (scoped to this block only)
Class.new(Smithy::Weld) do
used = Class.new(Smithy::Weld) do
def preprocess(model)
model['shapes']['example.weather#Weld'] = { 'type' => 'structure', 'members' => {} }
model['shapes']['example.weather#GetForecastOutput']['members']['chanceOfWelds'] =
{ 'target' => 'example.weather#Weld' }
end
end

Class.new(Smithy::Weld) do
unused = Class.new(Smithy::Weld) do
def for?(_model)
false
end
Expand All @@ -25,6 +26,7 @@ def preprocess(model)

@tmpdir = SpecHelper.generate(['Weather'], :types)
end
# rubocop:enable Lint/UselessAssignment

after(:all) do
SpecHelper.cleanup(['Weather'], @tmpdir)
Expand Down

0 comments on commit 2a9c248

Please sign in to comment.