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
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Naming/FileName:
- 'gems/smithy-json/lib/smithy-json.rb'
- 'gems/smithy-schema/lib/smithy-schema.rb'
- 'gems/smithy-server/lib/smithy-server.rb'
- 'gems/smithy-xml/lib/smithy-xml.rb'

Style/BlockComments:
Exclude:
Expand Down
24 changes: 16 additions & 8 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,31 @@ group :development do
gem 'byebug', platforms: :ruby
end

group :docs do
gem 'yard'
gem 'yard-sitemap', '~> 1.0'
end

group :json do
gem 'json'
gem 'oj'
end

group :rbs do
gem 'rbs', platforms: :ruby
gem 'steep', platforms: :ruby
end

group :test do
gem 'rspec'
gem 'simplecov'
gem 'webmock'
end

group :rbs do
gem 'rbs', platforms: :ruby
gem 'steep', platforms: :ruby
end

group :docs do
gem 'yard'
gem 'yard-sitemap', '~> 1.0'
group :xml do
gem 'libxml-ruby'
gem 'nokogiri'
gem 'oga'
gem 'ox'
gem 'rexml'
end
7 changes: 7 additions & 0 deletions gems/smithy-cbor/lib/smithy-cbor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@

require 'smithy-schema'

require_relative 'smithy-cbor/builder'
require_relative 'smithy-cbor/codec'
require_relative 'smithy-cbor/decoder'
require_relative 'smithy-cbor/encoder'
require_relative 'smithy-cbor/parser'

module Smithy
# Smithy::Cbor is a purpose-built set of utilities for working with CBOR.
# It does not support all features of generic CBOR parsing and serialization.
module Cbor
VERSION = File.read(File.expand_path('../VERSION', __dir__.to_s)).strip

# TODO: make this an instance and flatten errors
# def initialize(options = {})
# @engine = options[:engine] || self.class.engine
# end

# CBOR Tagged data (Major type 6).
# A Tag consists of a tag number and a value.
# In the extended generic data model, a tag number's definition
Expand Down
11 changes: 4 additions & 7 deletions gems/smithy-cbor/lib/smithy-cbor/codec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_relative 'builder'
require_relative 'parser'

module Smithy
module Cbor
# Codec that builds and parses in CBOR format.
Expand All @@ -12,17 +9,17 @@ def initialize(options = {})
@options = options
end

# @param [Shape] shape
# @param [ShapeRef, Shape] shape
# @param [Object] data
# @return [String, nil]
def build(shape, data)
Builder.new(@options).build(shape, data)
end

# @param [Shape] shape
# @param [ShapeRef, Shape] shape
# @param [String] bytes
# @param [Object] target
# @return [Object]
# @param [Object, nil] target (nil)
# @return [Object, nil]
def parse(shape, bytes, target = nil)
Parser.new(@options).parse(shape, bytes, target)
end
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-cbor/lib/smithy-cbor/decoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def read_bignum(tag_value)
end
end

def read_boolean # rubocop:disable Naming/PredicateMethod
def read_boolean
_major_type, add_info = read_info
case add_info
when 20 then false
Expand Down
5 changes: 2 additions & 3 deletions gems/smithy-cbor/sig/smithy-cbor/codec.rbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Smithy
module Cbor
module Codec
def build: (Schema::Shapes::Shape shape, untyped data) -> (nil | String)
def parse: (Schema::Shapes::Shape shape, String bytes, ?Struct[untyped] ?target) ->
(Hash[untyped, untyped] | ::Struct[untyped] | Schema::Union)
def build: (Schema::Shapes::Shape | Schema::Shapes::ShapeRef shape, Object data) -> (nil | String)
def parse: (Schema::Shapes::Shape | Schema::Shapes::ShapeRef shape, String bytes, ?Object ?target) -> Object?
end
end
end
11 changes: 9 additions & 2 deletions gems/smithy-client/lib/smithy-client/protocol_spec_matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
# rubocop:disable Metrics/BlockLength
RSpec::Matchers.define :match_data do |expected|
match do |actual|
return true if actual == expected

def match_hash(actual, expected)
expect(actual).to be_a(Hash)
expect(expected).to be_a(Hash)

expected.each do |key, value|
match_data(actual[key], value)
end
Expand All @@ -19,12 +20,18 @@ def match_hash(actual, expected)
end

def match_array(actual, expected)
expect(actual).to be_a(Array)
expect(expected).to be_a(Array)

actual.each_with_index do |value, index|
match_data(value, expected[index])
end
end

def match_float(actual, expected)
expect(actual).to be_a(Float)
expect(expected).to be_a(Float)

return if actual.nan? && expected.nan?
return if actual.infinite? && expected.infinite?

Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-client/lib/smithy-client/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Smithy
module Client
# @api private
module Util
def self.str_to_bool(str) # rubocop:disable Naming/PredicateMethod
def self.str_to_bool(str)
case str
when 'true' then true
when 'false' then false
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-client/spec/smithy-client/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ module Client
response = Response.new(context: HandlerContext.new(http_response: http_response))
yielded = false

resp = response.on_done(200..299) do |resp|
expect(resp).to be(response)
resp = response.on_done(200..299) do |r|
expect(r).to be(response)
yielded = true
end
http_response.signal_done(status_code: 200, headers: {}, body: '')
Expand Down
9 changes: 8 additions & 1 deletion gems/smithy-json/lib/smithy-json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require 'smithy-schema'

require_relative 'smithy-json/builder'
require_relative 'smithy-json/codec'
require_relative 'smithy-json/parser'

module Smithy
# Smithy::Json is a purpose-built set of utilities for working with JSON.
Expand All @@ -19,8 +21,13 @@ def initialize(error)
attr_reader :error
end

# TODO: make this an instance
# def initialize(options = {})
# @engine = options[:engine] || self.class.engine
# end

class << self
# @param [Symbol,Class] engine
# @param [Symbol, Class] engine
# Must be one of the following values:
#
# * :oj
Expand Down
3 changes: 1 addition & 2 deletions gems/smithy-json/lib/smithy-json/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ def build(shape, data)
private

def shape(ref, value) # rubocop:disable Metrics/CyclomaticComplexity
shape = ref.shape
case shape
case ref.shape
when BlobShape then blob(value)
when FloatShape then float(value)
when ListShape then list(ref, value)
Expand Down
9 changes: 3 additions & 6 deletions gems/smithy-json/lib/smithy-json/codec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# frozen_string_literal: true

require_relative 'builder'
require_relative 'parser'

module Smithy
module Json
# @api private
Expand All @@ -12,16 +9,16 @@ def initialize(options = {})
@options = options
end

# @param [Shape] shape
# @param [ShapeRef, Shape] shape
# @param [Object] data
# @return [String, nil]
def build(shape, data)
Builder.new(@options).build(shape, data)
end

# @param [Shape] shape
# @param [ShapeRef, Shape] shape
# @param [String] bytes
# @param [Struct] target
# @param [Object, nil] target (nil)
# @return [Object, nil]
def parse(shape, bytes, target = nil)
Parser.new(@options).parse(shape, bytes, target)
Expand Down
5 changes: 2 additions & 3 deletions gems/smithy-json/sig/smithy-json/codec.rbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
module Smithy
module Json
class Codec
def build: (Schema::Shapes::Shape shape, untyped data) -> (nil | String)
def parse: (Schema::Shapes::Shape shape, String bytes, ?Struct[untyped] ?target) ->
(nil | Hash[untyped, untyped] | Array[untyped] | Time | Numeric | String | ::Struct[untyped] | Schema::Union)
def build: (Schema::Shapes::Shape | Schema::Shapes::ShapeRef shape, Object data) -> (nil | String)
def parse: (Schema::Shapes::Shape | Schema::Shapes::ShapeRef shape, String bytes, ?Object ?target) -> Object?
end
end
end
8 changes: 4 additions & 4 deletions gems/smithy-schema/lib/smithy-schema/shapes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def member(name)
end
end

# Represents both Float and Double shapes.
class FloatShape < Shape; end

# Represents the following shapes: Byte, Short, Integer, Long, BigInteger.
class IntegerShape < Shape; end

Expand Down Expand Up @@ -204,9 +207,6 @@ def member(name)
end
end

# Represents both Float and Double shapes.
class FloatShape < Shape; end

# Represents a List shape.
class ListShape < Shape
# @return [ShapeRef]
Expand Down Expand Up @@ -371,7 +371,7 @@ module Prelude
id: 'smithy.api#Unit',
traits: { 'smithy.api#unitType' => {} }
)
Unit.type = Schema::EmptyStructure
Unit.type = EmptyStructure
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions gems/smithy-schema/lib/smithy-schema/structure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ def to_h(obj = self)
end
alias to_hash to_h

# @return [Boolean]
def empty?
values.compact == []
end

private

def _to_h_structure(obj)
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-schema/sig/smithy-schema/shapes.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ module Smithy

class StructureShape < Shape
attr_accessor members: Hash[Symbol, ShapeRef]
attr_accessor type: Class
attr_accessor type: Class | Struct[untyped]
def add_member: (Symbol, ShapeRef) -> ShapeRef
def member?: (Symbol?) -> bool
def member: (Symbol) -> ShapeRef?
Expand All @@ -97,7 +97,7 @@ module Smithy
attr_accessor members: Hash[Symbol, ShapeRef]
attr_accessor member_types: Hash[Symbol, Class]
attr_accessor members_by_type: Hash[Class, [Symbol, ShapeRef]]
attr_accessor type: Class
attr_accessor type: Class | Struct[untyped]
def add_member: (Symbol, Class, ShapeRef) -> ShapeRef
def member?: (Symbol?) -> bool
def member: (Symbol) -> ShapeRef?
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 @@ -2,6 +2,7 @@ module Smithy
module Schema
module Structure
def to_h: () -> ::Hash[Symbol, ::Object]
def empty?: () -> bool
end
end
end
13 changes: 13 additions & 0 deletions gems/smithy-schema/spec/smithy-schema/structure_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ module Schema
expect(subject.to_h).to eq expected
end
end

describe '#empty?' do
it 'returns true if all values are nil' do
empty_struct = structure.new
expect(empty_struct.empty?).to be true
end

it 'returns false if any value is not nil' do
expect(subject.empty?).to be false
expect(structure.new(value: nil).empty?).to be true
expect(structure.new(value: 'not nil').empty?).to be false
end
end
end
end
end
4 changes: 4 additions & 0 deletions gems/smithy-xml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Unreleased Changes
------------------

* Feature - Initial version of this gem.
1 change: 1 addition & 0 deletions gems/smithy-xml/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0.pre1
30 changes: 30 additions & 0 deletions gems/smithy-xml/lib/smithy-xml.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require 'smithy-schema'

require_relative 'smithy-xml/builder'
require_relative 'smithy-xml/codec'
require_relative 'smithy-xml/doc_builder'
require_relative 'smithy-xml/parser'

module Smithy
# Smithy::Xml is a purpose-built set of utilities for working with XML.
module Xml
VERSION = File.read(File.expand_path('../VERSION', __dir__.to_s)).strip

# Raised when an XML parsing error occurs.
class ParseError < StandardError
def initialize(msg, line, column)
@line = line
@column = column
super(msg)
end

# @return [Integer, nil]
attr_reader :line

# @return [Integer, nil]
attr_reader :column
end
end
end
Loading