Skip to content

Commit

Permalink
Refactor weld testing with protocol welds
Browse files Browse the repository at this point in the history
  • Loading branch information
mullermp committed Feb 22, 2025
1 parent 7ba096f commit 8ea5ea0
Show file tree
Hide file tree
Showing 18 changed files with 253 additions and 193 deletions.
14 changes: 10 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,12 @@ namespace :smithy do
Dir.glob('gems/smithy/spec/fixtures/**/model.smithy') do |model_path|
out_path = model_path.sub('.smithy', '.json')
config_files = smithy_build_files.map do |file|
" --config #{file}" if model_path.include?(File.dirname(file))
if model_path.include?(File.dirname(file))
FileUtils.touch(file) # https://github.com/smithy-lang/smithy/issues/2537
" --config #{file}"
end
end
sh("smithy ast#{config_files.join(' ')} #{model_path} > #{out_path}")
sh("smithy ast#{config_files.join} #{model_path} > #{out_path}")
end
end

Expand All @@ -77,9 +80,12 @@ namespace :smithy do
Dir.glob('gems/smithy/spec/fixtures/**/model.smithy') do |model_path|
old = JSON.load_file(model_path.sub('.smithy', '.json'))
config_files = smithy_build_files.map do |file|
" --config #{file}" if model_path.include?(File.dirname(file))
if model_path.include?(File.dirname(file))
FileUtils.touch(file) # https://github.com/smithy-lang/smithy/issues/2537
" --config #{file}"
end
end
new = JSON.parse(`smithy ast#{config_files.join(' ')} #{model_path}`)
new = JSON.parse(`smithy ast#{config_files.join} #{model_path}`)
failures << model_path if old != new
end
if failures.any?
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy/spec/fixtures/no_protocol/model.smithy
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ $version: "2"

namespace smithy.ruby.tests

service NoProtocol {}
service NoProtocolService {}
58 changes: 58 additions & 0 deletions gems/smithy/spec/fixtures/rpcv2_protocol/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"smithy": "2.0",
"shapes": {
"smithy.protocols#StringList": {
"type": "list",
"member": {
"target": "smithy.api#String"
},
"traits": {
"smithy.api#documentation": "A list of String shapes.",
"smithy.api#private": {}
}
},
"smithy.protocols#rpcv2Cbor": {
"type": "structure",
"members": {
"http": {
"target": "smithy.protocols#StringList",
"traits": {
"smithy.api#documentation": "Priority ordered list of supported HTTP protocol versions."
}
},
"eventStreamHttp": {
"target": "smithy.protocols#StringList",
"traits": {
"smithy.api#documentation": "Priority ordered list of supported HTTP protocol versions\nthat are required when using event streams."
}
}
},
"traits": {
"smithy.api#documentation": "An RPC-based protocol that serializes CBOR payloads.",
"smithy.api#protocolDefinition": {
"traits": [
"smithy.api#cors",
"smithy.api#endpoint",
"smithy.api#hostLabel",
"smithy.api#httpError"
]
},
"smithy.api#trait": {
"selector": "service"
},
"smithy.api#traitValidators": {
"rpcv2Cbor.NoDocuments": {
"selector": "service ~> member :test(> document)",
"message": "This protocol does not support document types"
}
}
}
},
"smithy.ruby.tests#Rpcv2CborService": {
"type": "service",
"traits": {
"smithy.protocols#rpcv2Cbor": {}
}
}
}
}
8 changes: 8 additions & 0 deletions gems/smithy/spec/fixtures/rpcv2_protocol/model.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$version: "2"

namespace smithy.ruby.tests

use smithy.protocols#rpcv2Cbor

@rpcv2Cbor
service Rpcv2CborService {}
8 changes: 8 additions & 0 deletions gems/smithy/spec/fixtures/rpcv2_protocol/smithy-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": "1.0",
"maven": {
"dependencies": [
"software.amazon.smithy:smithy-protocol-traits:[1.0,2.0)"
]
}
}
86 changes: 43 additions & 43 deletions gems/smithy/spec/fixtures/weather/model.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"smithy": "2.0",
"shapes": {
"smithy.ruby.tests.weather#City": {
"smithy.ruby.tests#City": {
"type": "resource",
"identifiers": {
"cityId": {
"target": "smithy.ruby.tests.weather#CityId"
"target": "smithy.ruby.tests#CityId"
}
},
"properties": {
"coordinates": {
"target": "smithy.ruby.tests.weather#CityCoordinates"
"target": "smithy.ruby.tests#CityCoordinates"
}
},
"read": {
"target": "smithy.ruby.tests.weather#GetCity"
"target": "smithy.ruby.tests#GetCity"
},
"list": {
"target": "smithy.ruby.tests.weather#ListCities"
"target": "smithy.ruby.tests#ListCities"
},
"resources": [
{
"target": "smithy.ruby.tests.weather#Forecast"
"target": "smithy.ruby.tests#Forecast"
}
]
},
"smithy.ruby.tests.weather#CityCoordinates": {
"smithy.ruby.tests#CityCoordinates": {
"type": "structure",
"members": {
"latitude": {
Expand All @@ -42,23 +42,23 @@
}
}
},
"smithy.ruby.tests.weather#CityId": {
"smithy.ruby.tests#CityId": {
"type": "string",
"traits": {
"smithy.api#pattern": "^[A-Za-z0-9 ]+$"
}
},
"smithy.ruby.tests.weather#CitySummaries": {
"smithy.ruby.tests#CitySummaries": {
"type": "list",
"member": {
"target": "smithy.ruby.tests.weather#CitySummary"
"target": "smithy.ruby.tests#CitySummary"
}
},
"smithy.ruby.tests.weather#CitySummary": {
"smithy.ruby.tests#CitySummary": {
"type": "structure",
"members": {
"cityId": {
"target": "smithy.ruby.tests.weather#CityId",
"target": "smithy.ruby.tests#CityId",
"traits": {
"smithy.api#required": {}
}
Expand All @@ -73,16 +73,16 @@
"traits": {
"smithy.api#references": [
{
"resource": "smithy.ruby.tests.weather#City"
"resource": "smithy.ruby.tests#City"
}
]
}
},
"smithy.ruby.tests.weather#Forecast": {
"smithy.ruby.tests#Forecast": {
"type": "resource",
"identifiers": {
"cityId": {
"target": "smithy.ruby.tests.weather#CityId"
"target": "smithy.ruby.tests#CityId"
}
},
"properties": {
Expand All @@ -91,31 +91,31 @@
}
},
"read": {
"target": "smithy.ruby.tests.weather#GetForecast"
"target": "smithy.ruby.tests#GetForecast"
}
},
"smithy.ruby.tests.weather#GetCity": {
"smithy.ruby.tests#GetCity": {
"type": "operation",
"input": {
"target": "smithy.ruby.tests.weather#GetCityInput"
"target": "smithy.ruby.tests#GetCityInput"
},
"output": {
"target": "smithy.ruby.tests.weather#GetCityOutput"
"target": "smithy.ruby.tests#GetCityOutput"
},
"errors": [
{
"target": "smithy.ruby.tests.weather#NoSuchResource"
"target": "smithy.ruby.tests#NoSuchResource"
}
],
"traits": {
"smithy.api#readonly": {}
}
},
"smithy.ruby.tests.weather#GetCityInput": {
"smithy.ruby.tests#GetCityInput": {
"type": "structure",
"members": {
"cityId": {
"target": "smithy.ruby.tests.weather#CityId",
"target": "smithy.ruby.tests#CityId",
"traits": {
"smithy.api#required": {}
}
Expand All @@ -125,7 +125,7 @@
"smithy.api#input": {}
}
},
"smithy.ruby.tests.weather#GetCityOutput": {
"smithy.ruby.tests#GetCityOutput": {
"type": "structure",
"members": {
"name": {
Expand All @@ -136,7 +136,7 @@
}
},
"coordinates": {
"target": "smithy.ruby.tests.weather#CityCoordinates",
"target": "smithy.ruby.tests#CityCoordinates",
"traits": {
"smithy.api#required": {}
}
Expand All @@ -146,19 +146,19 @@
"smithy.api#output": {}
}
},
"smithy.ruby.tests.weather#GetCurrentTime": {
"smithy.ruby.tests#GetCurrentTime": {
"type": "operation",
"input": {
"target": "smithy.api#Unit"
},
"output": {
"target": "smithy.ruby.tests.weather#GetCurrentTimeOutput"
"target": "smithy.ruby.tests#GetCurrentTimeOutput"
},
"traits": {
"smithy.api#readonly": {}
}
},
"smithy.ruby.tests.weather#GetCurrentTimeOutput": {
"smithy.ruby.tests#GetCurrentTimeOutput": {
"type": "structure",
"members": {
"time": {
Expand All @@ -172,23 +172,23 @@
"smithy.api#output": {}
}
},
"smithy.ruby.tests.weather#GetForecast": {
"smithy.ruby.tests#GetForecast": {
"type": "operation",
"input": {
"target": "smithy.ruby.tests.weather#GetForecastInput"
"target": "smithy.ruby.tests#GetForecastInput"
},
"output": {
"target": "smithy.ruby.tests.weather#GetForecastOutput"
"target": "smithy.ruby.tests#GetForecastOutput"
},
"traits": {
"smithy.api#readonly": {}
}
},
"smithy.ruby.tests.weather#GetForecastInput": {
"smithy.ruby.tests#GetForecastInput": {
"type": "structure",
"members": {
"cityId": {
"target": "smithy.ruby.tests.weather#CityId",
"target": "smithy.ruby.tests#CityId",
"traits": {
"smithy.api#required": {}
}
Expand All @@ -198,7 +198,7 @@
"smithy.api#input": {}
}
},
"smithy.ruby.tests.weather#GetForecastOutput": {
"smithy.ruby.tests#GetForecastOutput": {
"type": "structure",
"members": {
"chanceOfRain": {
Expand All @@ -209,13 +209,13 @@
"smithy.api#output": {}
}
},
"smithy.ruby.tests.weather#ListCities": {
"smithy.ruby.tests#ListCities": {
"type": "operation",
"input": {
"target": "smithy.ruby.tests.weather#ListCitiesInput"
"target": "smithy.ruby.tests#ListCitiesInput"
},
"output": {
"target": "smithy.ruby.tests.weather#ListCitiesOutput"
"target": "smithy.ruby.tests#ListCitiesOutput"
},
"traits": {
"smithy.api#paginated": {
Expand All @@ -224,7 +224,7 @@
"smithy.api#readonly": {}
}
},
"smithy.ruby.tests.weather#ListCitiesInput": {
"smithy.ruby.tests#ListCitiesInput": {
"type": "structure",
"members": {
"nextToken": {
Expand All @@ -238,14 +238,14 @@
"smithy.api#input": {}
}
},
"smithy.ruby.tests.weather#ListCitiesOutput": {
"smithy.ruby.tests#ListCitiesOutput": {
"type": "structure",
"members": {
"nextToken": {
"target": "smithy.api#String"
},
"items": {
"target": "smithy.ruby.tests.weather#CitySummaries",
"target": "smithy.ruby.tests#CitySummaries",
"traits": {
"smithy.api#required": {}
}
Expand All @@ -255,7 +255,7 @@
"smithy.api#output": {}
}
},
"smithy.ruby.tests.weather#NoSuchResource": {
"smithy.ruby.tests#NoSuchResource": {
"type": "structure",
"members": {
"resourceType": {
Expand All @@ -269,17 +269,17 @@
"smithy.api#error": "client"
}
},
"smithy.ruby.tests.weather#Weather": {
"smithy.ruby.tests#Weather": {
"type": "service",
"version": "2006-03-01",
"operations": [
{
"target": "smithy.ruby.tests.weather#GetCurrentTime"
"target": "smithy.ruby.tests#GetCurrentTime"
}
],
"resources": [
{
"target": "smithy.ruby.tests.weather#City"
"target": "smithy.ruby.tests#City"
}
],
"traits": {
Expand Down
Loading

0 comments on commit 8ea5ea0

Please sign in to comment.