Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jobs:
with:
gem-name: 'smithy-json'

smithy-xml:
needs: [smithy-schema]
uses: ./.github/workflows/test.yml
with:
gem-name: 'smithy-xml'

smithy-client:
needs: [smithy-schema]
uses: ./.github/workflows/test.yml
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gem 'smithy-client', path: 'gems/smithy-client'
gem 'smithy-json', path: 'gems/smithy-json'
# gem 'smithy-server', path: 'gems/smithy-server'
gem 'smithy-schema', path: 'gems/smithy-schema'
gem 'smithy-xml', path: 'gems/smithy-xml'

group :development do
gem 'byebug', platforms: :ruby
Expand Down
6 changes: 3 additions & 3 deletions gems/smithy-cbor/lib/smithy-cbor/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def structure(ref, values)
value = values[member_name]
next if value.nil?

data[member_ref.member_name] = shape(member_ref, value)
data[member_ref.location_name] = shape(member_ref, value)
end
end

Expand All @@ -71,12 +71,12 @@ def union(ref, values) # rubocop:disable Metrics/AbcSize
data = {}
if values.is_a?(Schema::Union)
_name, member_ref = ref.shape.member_by_type(values.class)
data[member_ref.member_name] = shape(member_ref, values.value)
data[member_ref.location_name] = shape(member_ref, values.value)
else
key, value = values.first
if ref.shape.member?(key)
member_ref = ref.shape.member(key)
data[member_ref.member_name] = shape(member_ref, value)
data[member_ref.location_name] = shape(member_ref, value)
end
end
data
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-cbor/lib/smithy-cbor/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ def map(ref, values, target = nil)
def structure(ref, values, target = nil)
target = ref.shape.type.new if target.nil?
ref.shape.members.each do |member_name, member_ref|
value = values[member_ref.member_name]
value = values[member_ref.location_name]
target[member_name] = shape(member_ref, value) unless value.nil?
end
target
end

def union(ref, values, target = nil) # rubocop:disable Metrics/AbcSize
ref.shape.members.each do |member_name, member_ref|
value = values[member_ref.member_name]
value = values[member_ref.location_name]
next if value.nil?

target = ref.shape.member_type(member_name) if target.nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def label_value(input, label, params)
name = nil
input.shape.members.each do |member_name, member_ref|
next unless member_ref.traits.key?('smithy.api#hostLabel')
next unless member_ref.member_name == label
next unless member_ref.location_name == label

name = member_name
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def union(ref, visited)
def scalar(ref)
case ref.shape
when BigDecimalShape then BigDecimal(0)
when BlobShape, EnumShape, StringShape then ref.member_name
when BlobShape, EnumShape, StringShape then ref.location_name
when BooleanShape then false
when IntegerShape, IntEnumShape then 0
when FloatShape then 0.0
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-json/lib/smithy-json/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def union(ref, values) # rubocop:disable Metrics/AbcSize
end

def location_name(ref)
return ref.member_name unless @json_name
return ref.location_name unless @json_name

ref.traits['smithy.api#jsonName'] || ref.member_name
ref.traits['smithy.api#jsonName'] || ref.location_name
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-json/lib/smithy-json/codec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Smithy
module Json
# @api private
# Codec that builds and parses in JSON format.
class Codec
# @param [Hash] options
def initialize(options = {})
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-json/lib/smithy-json/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ def union(ref, values, target = nil) # rubocop:disable Metrics/AbcSize
end

def location_name(ref)
return ref.member_name unless @json_name
return ref.location_name unless @json_name

ref.traits['smithy.api#jsonName'] || ref.member_name
ref.traits['smithy.api#jsonName'] || ref.location_name
end

def sparse?(shape)
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-json/spec/smithy-json/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module Json
expect(subject.parse(structure_shape, bytes).to_h).to eq(expected)
end

it 'builds and parses structures with jsonName' do
it 'parses structures with jsonName' do
subject = described_class.new(json_name: true)
shapes['smithy.ruby.tests#Structure']['members']['string'] = {
'target' => 'smithy.api#String',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ def union(ref, values, target = nil) # rubocop:disable Metrics/AbcSize
end

def location_name(ref)
return ref.member_name unless @json_name
return ref.location_name unless @json_name

ref.traits['smithy.api#jsonName'] || ref.member_name
ref.traits['smithy.api#jsonName'] || ref.location_name
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def union(ref, values)
end

def location_name(ref)
return ref.member_name unless @json_name
return ref.location_name unless @json_name

ref.traits['smithy.api#jsonName'] || ref.member_name
ref.traits['smithy.api#jsonName'] || ref.location_name
end

def normalize_timestamp_value(value)
Expand All @@ -164,7 +164,7 @@ def resolve_member_ref(ref, name)
return ref.shape.member(name) if ref.shape.member?(name)

ref.shape.members.values.find do |member_ref|
member_ref.traits['smithy.api#jsonName'] == name || member_ref.member_name == name
member_ref.traits['smithy.api#jsonName'] == name || member_ref.location_name == name
end
end

Expand All @@ -173,7 +173,7 @@ def resolve_value(member_name, member_ref, values)
value = values[json_name]
return value unless value.nil?
end
values[member_name] || values[member_ref.member_name]
values[member_name] || values[member_ref.location_name]
end
end
end
Expand Down
38 changes: 23 additions & 15 deletions gems/smithy-schema/lib/smithy-schema/shapes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def []=(key, value)
class ShapeRef
def initialize(options = {})
@shape = options[:shape]
@member_name = options[:member_name]
@location_name = options[:location_name]
@traits = options[:traits] || {}
@metadata = {}
end
Expand All @@ -47,7 +47,7 @@ def initialize(options = {})
attr_accessor :shape

# @return [String, nil]
attr_accessor :member_name
attr_accessor :location_name

# @return [Hash<String, Object>]
attr_accessor :traits
Expand Down Expand Up @@ -326,49 +326,57 @@ def member_by_type(type)

# Prelude shape definitions.
module Prelude
BigDecimal = BigDecimalShape.new(id: 'smithy.api#BigDecimal')
BigInteger = IntegerShape.new(id: 'smithy.api#BigInteger')
Blob = BlobShape.new(id: 'smithy.api#Blob')
Boolean = BooleanShape.new(id: 'smithy.api#Boolean')
Byte = IntegerShape.new(id: 'smithy.api#Byte')
Document = DocumentShape.new(id: 'smithy.api#Document')
Double = FloatShape.new(id: 'smithy.api#Double')
Float = FloatShape.new(id: 'smithy.api#Float')
Integer = IntegerShape.new(id: 'smithy.api#Integer')
Long = IntegerShape.new(id: 'smithy.api#Long')
BigDecimal = BigDecimalShape.new(id: 'smithy.api#BigDecimal', name: 'BigDecimal')
BigInteger = IntegerShape.new(id: 'smithy.api#BigInteger', name: 'BigInteger')
Blob = BlobShape.new(id: 'smithy.api#Blob', name: 'Blob')
Boolean = BooleanShape.new(id: 'smithy.api#Boolean', name: 'Boolean')
Byte = IntegerShape.new(id: 'smithy.api#Byte', name: 'Byte')
Document = DocumentShape.new(id: 'smithy.api#Document', name: 'Document')
Double = FloatShape.new(id: 'smithy.api#Double', name: 'Double')
Float = FloatShape.new(id: 'smithy.api#Float', name: 'Float')
Integer = IntegerShape.new(id: 'smithy.api#Integer', name: 'Integer')
Long = IntegerShape.new(id: 'smithy.api#Long', name: 'Long')
PrimitiveBoolean = BooleanShape.new(
id: 'smithy.api#PrimitiveBoolean',
name: 'PrimitiveBoolean',
traits: { 'smithy.api#default' => false }
)
PrimitiveByte = IntegerShape.new(
id: 'smithy.api#PrimitiveByte',
name: 'PrimitiveByte',
traits: { 'smithy.api#default' => 0 }
)
PrimitiveDouble = FloatShape.new(
id: 'smithy.api#PrimitiveDouble',
name: 'PrimitiveDouble',
traits: { 'smithy.api#default' => 0 }
)
PrimitiveFloat = FloatShape.new(
id: 'smithy.api#PrimitiveFloat',
name: 'PrimitiveFloat',
traits: { 'smithy.api#default' => 0 }
)
PrimitiveInteger = IntegerShape.new(
id: 'smithy.api#PrimitiveInteger',
name: 'PrimitiveInteger',
traits: { 'smithy.api#default' => 0 }
)
PrimitiveShort = IntegerShape.new(
id: 'smithy.api#PrimitiveShort',
name: 'PrimitiveShort',
traits: { 'smithy.api#default' => 0 }
)
PrimitiveLong = IntegerShape.new(
id: 'smithy.api#PrimitiveLong',
name: 'PrimitiveLong',
traits: { 'smithy.api#default' => 0 }
)
Short = IntegerShape.new(id: 'smithy.api#Short')
String = StringShape.new(id: 'smithy.api#String')
Timestamp = TimestampShape.new(id: 'smithy.api#Timestamp')
Short = IntegerShape.new(id: 'smithy.api#Short', name: 'Short')
String = StringShape.new(id: 'smithy.api#String', name: 'String')
Timestamp = TimestampShape.new(id: 'smithy.api#Timestamp', name: 'Timestamp')
Unit = StructureShape.new(
id: 'smithy.api#Unit',
name: 'Unit',
traits: { 'smithy.api#unitType' => {} }
)
Unit.type = EmptyStructure
Expand Down
6 changes: 6 additions & 0 deletions gems/smithy-schema/lib/smithy-schema/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def empty?
values.compact == []
end

# @param [Symbol] member_name
# @return [Boolean]
def key?(member_name)
!self[member_name].nil?
end

private

def _to_h_structure(obj)
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-schema/sig/smithy-schema/shapes.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module Smithy
def initialize: (?Hash[Symbol, untyped]) -> void

attr_accessor shape: Shape
attr_accessor member_name: String?
attr_accessor location_name: String?
attr_accessor traits: Hash[String, untyped]
def []: (Symbol) -> Object
def []=: (Symbol, Object) -> void
Expand Down
1 change: 1 addition & 0 deletions gems/smithy-schema/sig/smithy-schema/structure.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Smithy
module Structure
def to_h: () -> ::Hash[Symbol, ::Object]
def empty?: () -> bool
def key?: (Symbol) -> bool
end
end
end
8 changes: 4 additions & 4 deletions gems/smithy-schema/spec/smithy-schema/shapes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ module Shapes
end

it 'defaults a location name to nil' do
expect(subject.member_name).to be_nil
expect(subject.location_name).to be_nil
end

it 'stores the member name as a location name' do
subject = ShapeRef.new(member_name: 'foo')
expect(subject.member_name).to eq('foo')
it 'stores a location name' do
subject = ShapeRef.new(location_name: 'foo')
expect(subject.location_name).to eq('foo')
end

it 'defaults traits to empty hash' do
Expand Down
11 changes: 11 additions & 0 deletions gems/smithy-schema/spec/smithy-schema/structure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ module Schema
expect(structure.new(value: 'not nil').empty?).to be false
end
end

describe '#key?' do
it 'returns false if the value is nil' do
empty_struct = structure.new
expect(empty_struct.key?(:value)).to be false
end

it 'returns true if the value is not nil' do
expect(subject.key?(:value)).to be true
end
end
end
end
end
Loading