Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions gems/smithy/lib/smithy/anvil/client/views/client_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def gem_version
end

def operations
service = Vise::ServiceIndex.new(@model).service
Vise::OperationIndex.new(@model).for(service).map { |id, shape| Operation.new(id, shape) }
Vise::OperationIndex.new(@model).for(@plan.service)
.map { |id, shape| Operation.new(id, shape) }
end

# @api private
Expand Down
14 changes: 14 additions & 0 deletions gems/smithy/lib/smithy/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(model, type, options = {})
@model = model
@type = type
@options = options
@service = find_service(model['shapes'])

Welds.load!(self)
Polishes.load!(self)
Expand All @@ -31,5 +32,18 @@ def initialize(model, type, options = {})

# @return [Array<Polish>] The polishes that apply to this plan.
attr_reader :polishes

# @return [Hash<String, Hash>] The service shape for the shapes.
attr_reader :service

private

def find_service(shapes)
service = shapes.select { |_, shape| shape['type'] == 'service' }
raise 'Multiple service shapes found' if service.size > 1
raise 'No service shape found' if service.empty?

service
end
end
end
1 change: 0 additions & 1 deletion gems/smithy/lib/smithy/vise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require_relative 'vise/shape'
require_relative 'vise/operation_index'
require_relative 'vise/service_index'

module Smithy
# A module that parses the Smithy JSON model.
Expand Down
26 changes: 0 additions & 26 deletions gems/smithy/lib/smithy/vise/service_index.rb

This file was deleted.

8 changes: 8 additions & 0 deletions gems/smithy/spec/fixtures/one_service/model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"smithy": "2.0",
"shapes": {
"smithy.ruby.tests#Service1": {
"type": "service"
}
}
}
5 changes: 5 additions & 0 deletions gems/smithy/spec/fixtures/one_service/model.smithy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$version: "2"

namespace smithy.ruby.tests

service Service1 {}
70 changes: 70 additions & 0 deletions gems/smithy/spec/smithy/plan_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# frozen_string_literal: true

module Smithy
describe Plan do
let(:fixture) { File.expand_path('../fixtures/weather/model.json', __dir__) }
let(:model) { JSON.load_file(fixture) }
let(:type) { :client }
let(:options) { {} }

subject { described_class.new(model, type, options) }

describe '#model' do
it 'returns the model' do
expect(subject.model).to eq(model)
end
end

describe '#type' do
it 'returns the type' do
expect(subject.type).to eq(type)
end
end

describe '#options' do
it 'returns the options' do
expect(subject.options).to eq(options)
end
end

describe '#welds' do
it 'returns the welds' do
expect(subject.welds).to eq(Welds.for(model))
end
end

describe '#polishes' do
it 'returns the polishes' do
expect(subject.polishes).to eq(Polishes.for(model))
end
end

describe '#service' do
context 'one service shape' do
let(:fixture) { File.expand_path('../fixtures/one_service/model.json', __dir__) }

it 'finds the service shape' do
expected = model['shapes'].select { |_, shape| shape['type'] == 'service' }
actual = subject.service
expect(actual.keys.first).to eq(expected.keys.first)
end
end

context 'no service shapes' do
let(:fixture) { File.expand_path('../fixtures/no_service/model.json', __dir__) }

it 'raises an error' do
expect { subject }.to raise_error('No service shape found')
end
end

context 'multiple service shapes' do
let(:fixture) { File.expand_path('../fixtures/multi_service/model.json', __dir__) }

it 'raises an error' do
expect { subject }.to raise_error('Multiple service shapes found')
end
end
end
end
end
39 changes: 0 additions & 39 deletions gems/smithy/spec/smithy/vise/service_index_spec.rb

This file was deleted.

Loading