Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model -> Schema for runtime #277

Merged
merged 3 commits into from
Feb 22, 2025
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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Naming/FileName:
- '**/spec/**/*.rb'
- 'gems/smithy-client/lib/smithy-client.rb'
- 'gems/smithy-server/lib/smithy-server.rb'
- 'gems/smithy-model/lib/smithy-model.rb'
- 'gems/smithy-schema/lib/smithy-schema.rb'

Style/BlockComments:
Exclude:
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ gem 'rake', require: false
gem 'smithy', path: 'gems/smithy'
gem 'smithy-client', path: 'gems/smithy-client'
# gem 'smithy-server', path: 'gems/smithy-server'
gem 'smithy-model', path: 'gems/smithy-model'
gem 'smithy-schema', path: 'gems/smithy-schema'

group :development do
gem 'byebug', platforms: :ruby
Expand Down
16 changes: 8 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace :smithy do
include_paths = []
plans = []
rbs_targets = %w[Smithy Smithy::* Smithy::Client]
sig_paths = %w[gems/smithy-client/sig gems/smithy-model/sig]
sig_paths = %w[gems/smithy-client/sig gems/smithy-schema/sig]
Dir.glob('gems/smithy/spec/fixtures/endpoints/*/model.json') do |model_path|
test_name = model_path.split('/')[-2]
test_module = test_name.gsub('-', '').camelize
Expand Down Expand Up @@ -122,7 +122,7 @@ namespace 'smithy-client' do

desc 'Run RBS validation.'
task 'rbs:validate' do
sh('bundle exec rbs -I gems/smithy-client/sig -I gems/smithy-model/sig validate')
sh('bundle exec rbs -I gems/smithy-client/sig -I gems/smithy-schema/sig validate')
end

desc 'Run RBS spy tests on all unit tests.'
Expand All @@ -131,7 +131,7 @@ namespace 'smithy-client' do
'RUBYOPT' => '-r bundler/setup -r rbs/test/setup',
'RBS_TEST_RAISE' => 'true',
'RBS_TEST_LOGLEVEL' => 'error',
'RBS_TEST_OPT' => '-I gems/smithy-client/sig -I gems/smithy-model/sig',
'RBS_TEST_OPT' => '-I gems/smithy-client/sig -I gems/smithy-schema/sig',
'RBS_TEST_TARGET' => '"Smithy::Client,Smithy::Client::*"',
'RBS_TEST_DOUBLE_SUITE' => 'rspec'
}
Expand All @@ -144,16 +144,16 @@ namespace 'smithy-client' do
task 'rbs' => %w[rbs:validate rbs:test]
end

namespace 'smithy-model' do
namespace 'smithy-schema' do
RSpec::Core::RakeTask.new do |t|
t.pattern = 'gems/smithy-model/spec/**/*_spec.rb'
t.ruby_opts = '-I gems/smithy-model/spec'
t.pattern = 'gems/smithy-schema/spec/**/*_spec.rb'
t.ruby_opts = '-I gems/smithy-schema/spec'
t.rspec_opts = '--format documentation'
end

desc 'Run RBS validation.'
task 'rbs:validate' do
sh('bundle exec rbs -I gems/smithy-model/sig validate')
sh('bundle exec rbs -I gems/smithy-schema/sig validate')
end

desc 'Run RBS spy tests on all unit tests.'
Expand All @@ -167,7 +167,7 @@ namespace 'smithy-model' do
'RBS_TEST_DOUBLE_SUITE' => 'rspec'
}
sh(env,
'bundle exec rspec gems/smithy-model/spec -I gems/smithy-model/lib -I gems/smithy-model/spec ' \
'bundle exec rspec gems/smithy-schema/spec -I gems/smithy-schema/lib -I gems/smithy-schema/spec ' \
"--require spec_helper --tag '~rbs_test:skip'")
end

Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-client/lib/smithy-client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'jmespath'

require 'smithy-model'
require 'smithy-schema'

# client

Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-client/lib/smithy-client/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def plugins
Array(@plugins).freeze
end

# @return [Model::Shapes::ServiceShape]
# @return [Schema::Shapes::ServiceShape]
def service
@service ||= Model::Shapes::ServiceShape.new
@service ||= Schema::Shapes::ServiceShape.new
end

# @param [ServiceShape] service
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-client/lib/smithy-client/codecs/cbor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Codecs
# * Update implementation to handle event streams
# * Handle query_compatible trait
class CBOR
include Model::Shapes
include Schema::Shapes

def initialize(options = {}); end

Expand Down
6 changes: 3 additions & 3 deletions gems/smithy-client/lib/smithy-client/param_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Smithy
module Client
# @api private
class ParamConverter
include Model::Shapes
include Schema::Shapes

@mutex = Mutex.new
@converters = Hash.new { |h, k| h[k] = {} }
Expand Down Expand Up @@ -51,7 +51,7 @@ def structure(shape, values)

def union(shape, values)
values = c(shape, values)
if values.is_a?(Model::Union) || values.is_a?(Hash)
if values.is_a?(Schema::Union) || values.is_a?(Hash)
values.each_pair do |k, v|
next if v.nil?
next unless shape.member?(k)
Expand Down Expand Up @@ -247,7 +247,7 @@ def each_base_class(shape_class, &)
end

add(UnionShape, Hash) { |h, _| h.dup }
add(UnionShape, Model::Union)
add(UnionShape, Schema::Union)
end
end
end
2 changes: 1 addition & 1 deletion gems/smithy-client/lib/smithy-client/param_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Smithy
module Client
# @api private
class ParamValidator
include Smithy::Model::Shapes
include Smithy::Schema::Shapes

EXPECTED_GOT = 'expected %s to be %s, got class %s instead.'

Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-client/lib/smithy-client/protocols/rpc_v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def apply_accept_header(context)
end

def apple_content_type(context)
return if context.operation.input == Model::Shapes::Prelude::Unit
return if context.operation.input == Schema::Shapes::Prelude::Unit

# TODO: Needs an update when streaming is handled
context.request.headers['Content-Type'] = 'application/cbor'
Expand Down
4 changes: 2 additions & 2 deletions gems/smithy-client/sig/smithy-client/codec/cbor.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module Smithy
class CBOR
def initialize: (?::Hash[untyped, untyped] options) -> void

def serialize: (untyped data, Model::Shapes::Shape shape) -> (nil | String)
def serialize: (untyped data, Schema::Shapes::Shape shape) -> (nil | String)

def deserialize: (String bytes, Model::Shapes::Shape shape, ?Struct[untyped] target) -> (Hash[untyped, untyped] | Object)
def deserialize: (String bytes, Schema::Shapes::Shape shape, ?Struct[untyped] target) -> (Hash[untyped, untyped] | Object)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-client/sig/smithy-client/handler_context.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Smithy
class HandlerContext
def initialize: (?::Hash[untyped, untyped] options) -> void
attr_accessor operation_name: (Symbol | String)?
attr_accessor operation: Model::Shapes::OperationShape?
attr_accessor operation: Schema::Shapes::OperationShape?
attr_accessor client: Base?
attr_accessor params: Hash[Symbol | String, untyped]
attr_accessor config: Struct[untyped]?
Expand Down
2 changes: 1 addition & 1 deletion gems/smithy-client/smithy-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|

spec.add_dependency('jmespath', '~> 1', '>= 1.6.1') # necessary for secure jmespath JSON parsing

spec.add_dependency('smithy-model', '1.0.0.pre0')
spec.add_dependency('smithy-schema', '1.0.0.pre0')

spec.required_ruby_version = '>= 3.3'
end
12 changes: 6 additions & 6 deletions gems/smithy-client/spec/smithy-client/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Smithy
module Client
describe Base do
let(:service) { Model::Shapes::ServiceShape.new }
let(:service) { Schema::Shapes::ServiceShape.new }
let(:client_class) { Base.define(service: service) }
let(:plugin_a) { Plugin.new }
let(:plugin_b) { Plugin.new }
Expand Down Expand Up @@ -46,7 +46,7 @@ module Client
let(:input) { subject.build_input(:operation) }

before(:each) do
service.add_operation(:operation, Model::Shapes::OperationShape.new)
service.add_operation(:operation, Schema::Shapes::OperationShape.new)
end

it 'returns an Input' do
Expand Down Expand Up @@ -101,7 +101,7 @@ module Client
let(:input) { Input.new }

before(:each) do
service.add_operation(:operation, Model::Shapes::OperationShape.new)
service.add_operation(:operation, Schema::Shapes::OperationShape.new)
allow(subject).to receive(:build_input).and_return(input)
allow(input).to receive(:send_request)
end
Expand Down Expand Up @@ -237,13 +237,13 @@ module Client

describe '.service' do
it 'defaults to a ServiceShape' do
expect(client_class.service).to be_kind_of(Model::Shapes::ServiceShape)
expect(client_class.service).to be_kind_of(Schema::Shapes::ServiceShape)
end
end

describe '.service=' do
it 'can be set' do
service = Model::Shapes::ServiceShape.new
service = Schema::Shapes::ServiceShape.new
client_class.service = service
expect(client_class.service).to be(service)
end
Expand All @@ -256,7 +256,7 @@ module Client
end

it 'sets the service on the client class' do
service = Model::Shapes::ServiceShape.new
service = Schema::Shapes::ServiceShape.new
client_class = Base.define(service: service)
expect(client_class.service).to be(service)
end
Expand Down
18 changes: 9 additions & 9 deletions gems/smithy-client/spec/smithy-client/codecs/cbor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ module Smithy
module Client
module Codecs
describe CBOR do
let(:string_shape) { Model::Shapes::StringShape.new(id: 'string') }
let(:string_shape) { Schema::Shapes::StringShape.new(id: 'string') }

let(:list_shape) do
shape = Model::Shapes::ListShape.new(id: 'list')
shape.set_member(Model::Shapes::Prelude::String)
shape = Schema::Shapes::ListShape.new(id: 'list')
shape.set_member(Schema::Shapes::Prelude::String)
shape
end

let(:map_shape) do
shape = Model::Shapes::MapShape.new(id: 'map')
shape.set_key(Model::Shapes::Prelude::String)
shape.set_value(Model::Shapes::Prelude::Blob)
shape = Schema::Shapes::MapShape.new(id: 'map')
shape.set_key(Schema::Shapes::Prelude::String)
shape.set_value(Schema::Shapes::Prelude::Blob)
shape
end

let(:typed_struct) do
Struct.new(:s, :l, :m, keyword_init: true) do
include Model::Structure
include Schema::Structure
end
end

let(:structure_shape) do
struct = Model::Shapes::StructureShape.new(id: 'structure')
struct = Schema::Shapes::StructureShape.new(id: 'structure')
struct.add_member(:s, 's', string_shape)
struct.add_member(:l, 'l', list_shape)
struct.add_member(:m, 'm', map_shape)
Expand All @@ -35,7 +35,7 @@ module Codecs
end

it 'serializes returns nil when given shape is Prelude::Unit' do
expect(subject.serialize('', Model::Shapes::Prelude::Unit)).to be_nil
expect(subject.serialize('', Schema::Shapes::Prelude::Unit)).to be_nil
end

it 'deserializes returns an empty hash when given bytes are empty' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module Client
end

it 'can be set in the constructor' do
operation = Model::Shapes::OperationShape.new
operation = Schema::Shapes::OperationShape.new
context = HandlerContext.new(operation: operation)
expect(context.operation).to be(operation)
end
Expand Down
Loading