smithy 2.0.0.pre0 → 2.0.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/smithy-ruby +1 -4
  4. data/lib/smithy/command.rb +68 -0
  5. data/lib/smithy/generators/base.rb +19 -0
  6. data/lib/smithy/generators/client.rb +106 -0
  7. data/lib/smithy/generators/schema.rb +61 -0
  8. data/lib/smithy/generators.rb +29 -0
  9. data/lib/smithy/model/flattener.rb +114 -0
  10. data/lib/smithy/model/operation_parser.rb +42 -0
  11. data/lib/smithy/model/rbs.rb +57 -0
  12. data/lib/smithy/model/service_index.rb +51 -0
  13. data/lib/smithy/model/service_parser.rb +74 -0
  14. data/lib/smithy/model/shape.rb +49 -0
  15. data/lib/smithy/model/structure_parser.rb +43 -0
  16. data/lib/smithy/model/yard.rb +100 -0
  17. data/lib/smithy/model.rb +54 -0
  18. data/lib/smithy/plan.rb +79 -3
  19. data/lib/smithy/templates/client/auth_parameters.erb +29 -0
  20. data/lib/smithy/templates/client/auth_parameters_rbs.erb +14 -0
  21. data/lib/smithy/templates/client/auth_plugin.erb +115 -0
  22. data/lib/smithy/templates/client/auth_resolver.erb +16 -0
  23. data/lib/smithy/templates/client/auth_resolver_rbs.erb +5 -0
  24. data/lib/smithy/templates/client/client.erb +142 -0
  25. data/lib/smithy/templates/client/client_rbs.erb +29 -0
  26. data/lib/smithy/templates/client/customizations.erb +3 -0
  27. data/lib/smithy/templates/client/endpoint_parameters.erb +65 -0
  28. data/lib/smithy/templates/client/endpoint_parameters_rbs.erb +13 -0
  29. data/lib/smithy/templates/client/endpoint_plugin.erb +58 -0
  30. data/lib/smithy/templates/client/endpoint_provider.erb +15 -0
  31. data/lib/smithy/templates/client/endpoint_provider_rbs.erb +5 -0
  32. data/lib/smithy/templates/client/endpoint_provider_spec.erb +70 -0
  33. data/lib/smithy/templates/client/errors.erb +69 -0
  34. data/lib/smithy/templates/client/errors_rbs.erb +17 -0
  35. data/lib/smithy/templates/client/gemspec.erb +17 -0
  36. data/lib/smithy/templates/client/module.erb +22 -0
  37. data/lib/smithy/templates/client/module_rbs.erb +7 -0
  38. data/lib/smithy/templates/client/paginators.erb +33 -0
  39. data/lib/smithy/templates/client/protocol_spec.erb +144 -0
  40. data/lib/smithy/templates/client/rubocop_yml.erb +33 -0
  41. data/lib/smithy/templates/client/schema.erb +76 -0
  42. data/lib/smithy/templates/client/schema_rbs.erb +13 -0
  43. data/lib/smithy/templates/client/spec_helper.erb +10 -0
  44. data/lib/smithy/templates/client/types.erb +64 -0
  45. data/lib/smithy/templates/client/types_rbs.erb +47 -0
  46. data/lib/smithy/templates/client/waiters.erb +42 -0
  47. data/lib/smithy/util/hash_formatter.rb +124 -0
  48. data/lib/smithy/util/underscore.rb +18 -0
  49. data/lib/smithy/util.rb +9 -0
  50. data/lib/smithy/views/client/auth_parameter.rb +29 -0
  51. data/lib/smithy/views/client/auth_parameters.rb +23 -0
  52. data/lib/smithy/views/client/auth_parameters_rbs.rb +23 -0
  53. data/lib/smithy/views/client/auth_plugin.rb +35 -0
  54. data/lib/smithy/views/client/auth_resolver.rb +125 -0
  55. data/lib/smithy/views/client/auth_resolver_rbs.rb +19 -0
  56. data/lib/smithy/views/client/client.rb +208 -0
  57. data/lib/smithy/views/client/client_rbs.rb +231 -0
  58. data/lib/smithy/views/client/customizations.rb +10 -0
  59. data/lib/smithy/views/client/endpoint_parameter.rb +156 -0
  60. data/lib/smithy/views/client/endpoint_parameters.rb +43 -0
  61. data/lib/smithy/views/client/endpoint_parameters_rbs.rb +28 -0
  62. data/lib/smithy/views/client/endpoint_plugin.rb +27 -0
  63. data/lib/smithy/views/client/endpoint_provider.rb +241 -0
  64. data/lib/smithy/views/client/endpoint_provider_rbs.rb +19 -0
  65. data/lib/smithy/views/client/endpoint_provider_spec.rb +137 -0
  66. data/lib/smithy/views/client/errors.rb +88 -0
  67. data/lib/smithy/views/client/errors_rbs.rb +12 -0
  68. data/lib/smithy/views/client/gemspec.rb +36 -0
  69. data/lib/smithy/views/client/module.rb +107 -0
  70. data/lib/smithy/views/client/module_rbs.rb +20 -0
  71. data/lib/smithy/views/client/operation_examples.rb +157 -0
  72. data/lib/smithy/views/client/paginators.rb +108 -0
  73. data/lib/smithy/views/client/plugin.rb +29 -0
  74. data/lib/smithy/views/client/plugin_list.rb +57 -0
  75. data/lib/smithy/views/client/protocol_spec.rb +254 -0
  76. data/lib/smithy/views/client/request_response_example.rb +179 -0
  77. data/lib/smithy/views/client/rubocop_yml.rb +19 -0
  78. data/lib/smithy/views/client/schema.rb +356 -0
  79. data/lib/smithy/views/client/schema_rbs.rb +84 -0
  80. data/lib/smithy/views/client/shape_to_hash.rb +99 -0
  81. data/lib/smithy/views/client/spec_helper.rb +19 -0
  82. data/lib/smithy/views/client/types.rb +293 -0
  83. data/lib/smithy/views/client/types_rbs.rb +67 -0
  84. data/lib/smithy/views/client/waiters.rb +82 -0
  85. data/lib/smithy/views/client.rb +47 -0
  86. data/lib/smithy/views/view.rb +30 -0
  87. data/lib/smithy/views.rb +9 -0
  88. data/lib/smithy/weld.rb +109 -0
  89. data/lib/smithy/welds/auth/anonymous_auth.rb +31 -0
  90. data/lib/smithy/welds/auth/http_api_key_auth.rb +34 -0
  91. data/lib/smithy/welds/auth/http_basic_auth.rb +34 -0
  92. data/lib/smithy/welds/auth/http_bearer_auth.rb +34 -0
  93. data/lib/smithy/welds/auth/http_digest_auth.rb +34 -0
  94. data/lib/smithy/welds/plugins.rb +54 -0
  95. data/lib/smithy/welds/rpc_v2_cbor.rb +20 -0
  96. data/lib/smithy/welds/rubocop.rb +33 -0
  97. data/lib/smithy/welds/transforms/default_endpoint_rules.json +35 -0
  98. data/lib/smithy/welds/transforms/default_endpoint_tests.json +24 -0
  99. data/lib/smithy/welds/transforms/endpoints.rb +68 -0
  100. data/lib/smithy/welds/transforms/synthetic_input_output.rb +60 -0
  101. data/lib/smithy/welds.rb +29 -0
  102. data/lib/smithy.rb +33 -2
  103. metadata +144 -9
@@ -0,0 +1,29 @@
1
+ module <%= module_name %>
2
+ class Client < Smithy::Client::Base
3
+ include Smithy::Client::Stubs
4
+
5
+ def self.new: (
6
+ <% option_types.each do |name, type| -%>
7
+ ?<%= name %>: <%= type %>,
8
+ <% end -%>
9
+ ) -> void | (?Hash[Symbol, untyped]) -> void
10
+ <% operations.each do |operation| -%>
11
+
12
+ interface <%= operation.response_interface %>
13
+ include Smithy::Client::_Response[<%= operation.output.type %>]
14
+ <% operation.output.member_types.each do |name, type| -%>
15
+ def <%= name %>: () -> <%= type %>?
16
+ <% end -%>
17
+ end
18
+ <% if operation.input.members? -%>
19
+ def <%= operation.name %>: (
20
+ <% operation.input.keyword_args.each do |line| -%>
21
+ <%= line %>
22
+ <% end -%>
23
+ ) -> <%= operation.response_interface %> | (?Hash[Symbol, untyped], ?Hash[Symbol, untyped]) -> <%= operation.response_interface %>
24
+ <% else -%>
25
+ def <%= operation.name %>: (?Hash[Symbol, untyped], ?Hash[Symbol, untyped]) -> <%= operation.response_interface %>
26
+ <% end -%>
27
+ <% end -%>
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Any customizations can be added here.
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ module <%= module_name %>
6
+ # Endpoint parameters used to resolve endpoints per request.
7
+ <% parameters.each do |param| -%>
8
+ # @!attribute <%= param.name %>
9
+ <% param.docstrings.each do |docstring| -%>
10
+ # <%= docstring %>
11
+ <% end -%>
12
+ #
13
+ # @return [<%= param.documentation_type %>]
14
+ #
15
+ <% end -%>
16
+ EndpointParameters = Struct.new(
17
+ <% parameters.each do |param| -%>
18
+ :<%= param.name %>,
19
+ <% end -%>
20
+ keyword_init: true
21
+ ) do
22
+
23
+ def initialize(options = {})
24
+ <% parameters.each do |param| -%>
25
+ self.<%= param.name %> = options.fetch(:<%= param.name %>, <%= param.default_value %>)
26
+ <% end -%>
27
+ <% parameters.select(&:validate_required?).each do |param| -%>
28
+ raise ArgumentError, "Missing required EndpointParameter: :<%= param.name %>" if <%= param.name %>.nil?
29
+ <% end -%>
30
+ end
31
+
32
+ # @api private
33
+ def self.create(context)
34
+ config = context.config
35
+ <% if operation_params.empty? -%>
36
+ new({
37
+ <% parameters.select(&:create_from_config?).each do |param| -%>
38
+ <%= param.name %>: <%= param.value %>,
39
+ <% end -%>
40
+ }.compact)
41
+ <% else -%>
42
+ params = context.params
43
+ operation_params =
44
+ case context.operation_name
45
+ <% operation_params.each do |name, params| -%>
46
+ when :<%= name %>
47
+ {
48
+ <% params.each do |param| -%>
49
+ <%= param.name %>: <%= param.value %>,
50
+ <% end -%>
51
+ }
52
+ <% end -%>
53
+ else
54
+ {}
55
+ end
56
+
57
+ new({
58
+ <% parameters.select(&:create_from_config?).each do |param| -%>
59
+ <%= param.name %>: <%= param.value %>,
60
+ <% end -%>
61
+ }.merge(operation_params).compact)
62
+ <% end -%>
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,13 @@
1
+ module <%= module_name %>
2
+ class EndpointParameters
3
+ def initialize: (
4
+ <% parameters.each do |param| -%>
5
+ <%= '?' unless param.validate_required? %><%= param.name %>: <%= param.rbs_type %>,
6
+ <% end -%>
7
+ ) -> void | (?Hash[Symbol, untyped]) -> void
8
+
9
+ <% parameters.each do |param| -%>
10
+ attr_accessor <%= param.name %>: <%= param.rbs_type %><%= '?' unless param.validate_required? %>
11
+ <% end -%>
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ module <%= module_name %>
6
+ module Plugins
7
+ # @api private
8
+ class Endpoint < Smithy::Client::Plugin
9
+ option(
10
+ :endpoint_provider,
11
+ doc_type: '<%= module_name %>::EndpointProvider',
12
+ docstring: <<~DOCS) do |config|
13
+ The endpoint provider used to resolve endpoints. Any object that responds to `#resolve(parameters)`.
14
+ DOCS
15
+ EndpointProvider.new
16
+ end
17
+
18
+ <% parameters.select(&:built_in?).each do |param| -%>
19
+ <% param.built_in_binding[:render_config].call(plan).split("\n").each do |line| -%>
20
+ <%= line %>
21
+ <% end -%>
22
+
23
+ <% end -%>
24
+ <% parameters.select(&:client_context?).each do |param| -%>
25
+ option(
26
+ :<%= param.name %>,
27
+ doc_type: "<%= param.documentation_type %>",
28
+ docstring: "<%= param.client_context_doc %>"
29
+ )
30
+
31
+ <% end -%>
32
+ # @api private
33
+ class Handler < Smithy::Client::Handler
34
+ def call(context)
35
+ params = EndpointParameters.create(context)
36
+ endpoint = context.config.endpoint_provider.resolve(params)\
37
+
38
+ context.http_request.endpoint = endpoint.uri
39
+ apply_endpoint_headers(context, endpoint.headers)
40
+
41
+ context[:endpoint_params] = params
42
+ context[:endpoint_properties] = endpoint.properties
43
+ @handler.call(context)
44
+ end
45
+
46
+ private
47
+
48
+ def apply_endpoint_headers(context, headers)
49
+ headers.each do |key, value|
50
+ context.http_request.headers[key] = value
51
+ end
52
+ end
53
+ end
54
+
55
+ handler(Handler, priority: 75)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ module <%= module_name %>
6
+ # Resolve an endpoint from {EndpointParameters}.
7
+ class EndpointProvider
8
+ # @param [EndpointParameters] parameters
9
+ # @return [Smithy::Client::EndpointRules::Endpoint]
10
+ # @raise [ArgumentError]
11
+ def resolve(parameters)
12
+ <%= endpoint_rules_code %>
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module <%= module_name %>
2
+ class EndpointProvider
3
+ def resolve: (EndpointParameters) -> Smithy::Client::EndpointRules::Endpoint
4
+ end
5
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ require_relative '../spec_helper'
6
+
7
+ module <%= module_name %>
8
+ describe EndpointProvider do
9
+ subject { EndpointProvider.new }
10
+ <% test_cases.each do |test_case| -%>
11
+
12
+ context "<%= test_case.documentation %>" do
13
+ let(:expected) do
14
+ <%= test_case.expect %>
15
+ end
16
+
17
+ it 'produces the expected output from the EndpointProvider' do
18
+ params = EndpointParameters.new(**<%= test_case.params %>)
19
+ <% if test_case.expect_error? -%>
20
+ expect do
21
+ subject.resolve(params)
22
+ end.to raise_error(ArgumentError, expected['error'])
23
+ <% else -%>
24
+ endpoint = subject.resolve(params)
25
+ expect(endpoint.uri).to eq(expected['endpoint']['url'])
26
+ expect(endpoint.headers).to eq(expected['endpoint']['headers'] || {})
27
+ expect(endpoint.properties).to eq(expected['endpoint']['properties'] || {})
28
+ <% end -%>
29
+ end
30
+
31
+ <% test_case.operation_inputs.each do |operation_input| -%>
32
+ it 'produces the correct output from the client when calling <%= operation_input.operation_name %>' do
33
+ client = Client.new(
34
+ stub_responses: true,
35
+ endpoint_provider: subject,
36
+ <% operation_input.client_params.each do |p| -%>
37
+ <%= p.param %>: <%= p.value %>,
38
+ <% end -%>
39
+ )
40
+ <% if test_case.expect_error? -%>
41
+ expect do
42
+ client.<%= operation_input.operation_name %>(
43
+ <% operation_input.operation_params.each do |p| -%>
44
+ <%= p.param %>: <%= p.value %>,
45
+ <% end -%>
46
+ )
47
+ end.to raise_error(ArgumentError, expected['error'])
48
+ <% else -%>
49
+ response = client.<%= operation_input.operation_name %>(
50
+ <% operation_input.operation_params.each do |p| -%>
51
+ <%= p.param %>: <%= p.value %>,
52
+ <% end -%>
53
+ )
54
+ expected_uri = URI.parse(expected['endpoint']['url'])
55
+ expect(response.context.http_request.endpoint.to_s).to include(expected_uri.host)
56
+ expect(response.context.http_request.endpoint.to_s).to include(expected_uri.scheme)
57
+ expect(response.context.http_request.endpoint.to_s).to include(expected_uri.path)
58
+
59
+ expected['endpoint'].fetch('headers', {}).each do |k,v|
60
+ expect(response.context.http_request.headers[k]).to eq(v)
61
+ end
62
+
63
+ # TODO: expect auth
64
+ <% end -%>
65
+ end
66
+ <% end -%>
67
+ end
68
+ <% end -%>
69
+ end
70
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ module <%= module_name %>
6
+ # When this service returns an error response, the SDK constructs and raises an error.
7
+ # These errors all extend <%= module_name %>::Errors::ServiceError < {Smithy::Client::ServiceError}
8
+ #
9
+ # You can rescue all errors using the ServiceError:
10
+ #
11
+ # begin
12
+ # # do stuff
13
+ # rescue <%= module_name %>::Errors::ServiceError
14
+ # # rescues all API errors
15
+ # end
16
+ #
17
+ # ## Request Context
18
+ #
19
+ # ServiceError objects have a {Smithy::Client::ServiceError#context #context} method
20
+ # that returns information about the request that generated the error.
21
+ # See {Smithy::Client::HandlerContext} for more information.
22
+ #
23
+ # ## Error Classes
24
+ #
25
+ <% errors.each do |error| -%>
26
+ # * {<%= error.name %>}
27
+ <% end -%>
28
+ #
29
+ # Additionally, error classes are dynamically generated for service errors based on the error code
30
+ # if they are not defined above.
31
+ module Errors
32
+ extend Smithy::Client::DynamicErrors
33
+ <% errors.each do |error| -%>
34
+
35
+ <% error.docstrings.each do |docstring| -%>
36
+ # <%= docstring %>
37
+ <% end -%>
38
+ class <%= error.name %> < Smithy::Client::ServiceError
39
+ # @param [Smithy::Client::HandlerContext] context
40
+ # @param [String] message
41
+ # @param [<%= module_name %>::Types::<%= error.name %>] data
42
+ def initialize(context, message, data = Smithy::Schema::EmptyStructure.new)
43
+ super(context, message, data)
44
+ end
45
+ <% error.members.each do |member| -%>
46
+
47
+ <% member.docstrings.each do |docstring| -%>
48
+ # <%= docstring %>
49
+ <% end -%>
50
+ def <%= member.name %>
51
+ <%= '@message || ' if member.message? %>@data[:<%= member.name %>]
52
+ end
53
+ <% end -%>
54
+ <% if error.retryable? -%>
55
+
56
+ def retryable?
57
+ true
58
+ end
59
+ <% end -%>
60
+ <% if error.throttling? -%>
61
+
62
+ def throttling?
63
+ true
64
+ end
65
+ <% end -%>
66
+ end
67
+ <% end -%>
68
+ end
69
+ end
@@ -0,0 +1,17 @@
1
+ module <%= module_name %>
2
+ module Errors
3
+ <% errors.each do |error| -%>
4
+ class <%= error.name %> < Smithy::Client::ServiceError
5
+ <% error.members.each do |member| -%>
6
+ def <%= member.name %>: () -> <%= Model::RBS.type(model, member.shape['target'], Model.shape(model, member.shape['target'])) %>?
7
+ <% end -%>
8
+ <% if error.retryable? -%>
9
+ def retryable?: () -> true
10
+ <% end -%>
11
+ <% if error.throttling? -%>
12
+ def throttling?: () -> true
13
+ <% end -%>
14
+ end
15
+ <% end -%>
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = '<%= gem_name %>'
7
+ spec.version = '<%= gem_version %>'
8
+ spec.summary = 'Generated gem using Smithy'
9
+ spec.authors = ['Smithy Ruby']
10
+ spec.files = Dir['lib/**/*.rb', base: __dir__]
11
+
12
+ <% dependencies.each do |dependency, version| -%>
13
+ spec.add_dependency('<%= dependency %>', '<%= version %>')
14
+ <% end -%>
15
+
16
+ spec.required_ruby_version = '>= 3.3'
17
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ <% requires.each do |require| -%>
6
+ require '<%= require %>'
7
+ <% end %>
8
+
9
+ <% ["Object"].concat(module_names).each_cons(2) do |parent, child| -%>
10
+ <%= parent %>.const_set('<%= child %>', Module.new) unless <%= parent %>.const_defined?('<%= child %>')
11
+ <% end -%>
12
+
13
+ <% docstrings.each do |docstring| -%>
14
+ # <%= docstring %>
15
+ <% end -%>
16
+ module <%= module_name %>
17
+ VERSION = '<%= gem_version %>'
18
+ end
19
+
20
+ <% relative_requires.each do |require| -%>
21
+ require_relative '<%= gem_name %>/<%= require %>'
22
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ <% module_names.each_with_index do |module_name, i| -%>
2
+ <%= ' ' * i %>module <%= module_name %>
3
+ <% end -%>
4
+ <%= ' ' * (module_names.size) %> VERSION: String
5
+ <% (0...module_names.size).reverse_each do |i| -%>
6
+ <%= ' ' * i %>end
7
+ <% end -%>
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is generated code!
4
+
5
+ module <%= module_name %>
6
+ # @api private
7
+ module Paginators
8
+
9
+ <% paginators.each do |paginator| -%>
10
+ # @api private
11
+ class <%= paginator.name %>
12
+ def next_tokens(data)
13
+ <% paginator.next_tokens_code.each do |line| -%>
14
+ <%= line %>
15
+ <% end -%>
16
+ end
17
+
18
+ def prev_tokens(params)
19
+ <% paginator.prev_tokens_code.each do |line| -%>
20
+ <%= line %>
21
+ <% end -%>
22
+ end
23
+
24
+ def items(data)
25
+ <% paginator.items_code.each do |line| -%>
26
+ <%= line %>
27
+ <% end -%>
28
+ end
29
+ end
30
+
31
+ <% end -%>
32
+ end
33
+ end
@@ -0,0 +1,144 @@
1
+ # This is generated code!
2
+
3
+ require_relative '../spec_helper'
4
+
5
+ <% additional_requires.each do |require| -%>
6
+ require '<%= require %>'
7
+ <% end -%>
8
+
9
+ module <%= module_name %>
10
+ describe Client do
11
+ let(:client_options) { { stub_responses: true } }
12
+ let(:client) { Client.new(client_options) }
13
+
14
+ <% all_operation_tests.each do |operation_tests| -%>
15
+ describe '#<%= operation_tests.name %>' do
16
+ <% unless operation_tests.request_tests.empty? -%>
17
+ describe 'requests' do
18
+ <% operation_tests.request_tests.each do |test| -%>
19
+ <% test.comments.each do |line| -%>
20
+ # <%= line %>
21
+ <% end -%>
22
+ <% if test.skip? -%>
23
+ it '<%= test.id %>', skip: '<%= test.skip_reason %>' do
24
+ <% else -%>
25
+ it '<%= test.id %>' do
26
+ <% end -%>
27
+ <% if test['host'] -%>
28
+ client = Client.new(client_options.merge(endpoint: '<%= test.endpoint %>'))
29
+ <% end -%>
30
+ <% if test.idempotency_token_trait? -%>
31
+ allow(SecureRandom).to receive(:uuid).and_return('00000000-0000-4000-8000-000000000000')
32
+ <% end -%>
33
+ response = client.<%= operation_tests.name %>(<%= test.params %>)
34
+ request = response.context.http_request
35
+ expect(request.http_method).to eq('<%= test['method'] %>')
36
+ expect(request.endpoint.path).to eq('<%= test['uri'] %>')
37
+ <% if test['resolvedHost'] -%>
38
+ expect(request.endpoint.host).to eq('<%= test['resolvedHost'] %>')
39
+ <% end -%>
40
+ <% if test.query_expect? -%>
41
+ actual_query = CGI.parse(request.endpoint.query || '')
42
+ <% if test['queryParams'] -%>
43
+ expected_query = CGI.parse("<%= test['queryParams'].join('&') %>")
44
+ expected_query.each do |k, v|
45
+ actual = actual_query[k].map { |s| s.force_encoding('utf-8') }
46
+ expect(actual).to eq(v)
47
+ end
48
+ <% end -%>
49
+ <% if test['forbidQueryParams'] -%>
50
+ <%= test['forbidQueryParams']%>.each do |query|
51
+ expect(actual_query.key?(query)).to be false
52
+ end
53
+ <% end -%>
54
+ <% if test['requireQueryParams'] -%>
55
+ <%= test['requireQueryParams']%>.each do |query|
56
+ expect(actual_query.key?(query)).to be true
57
+ end
58
+ <% end -%>
59
+ <% end -%>
60
+ <% test['headers']&.each do |k,v| -%>
61
+ expect(request.headers['<%= k %>']).to eq('<%= v %>')
62
+ <% end -%>
63
+ <% test['forbidHeaders']&.each do |k| -%>
64
+ expect(request.headers.key?('<%= k %>')).to be(false)
65
+ <% end -%>
66
+ <% test['requireHeaders']&.each do |k| -%>
67
+ expect(request.headers.key?('<%= k %>')).to be(true)
68
+ <% end -%>
69
+ <% if test['body'] -%>
70
+ <%= test.body_expect %>
71
+ <% end -%>
72
+ end
73
+ <% end -%>
74
+ end
75
+ <% end -%>
76
+ <% unless operation_tests.response_tests.empty? -%>
77
+ describe 'responses' do
78
+ <% operation_tests.response_tests.each do |test| -%>
79
+ <% test.comments.each do |line| -%>
80
+ # <%= line %>
81
+ <% end -%>
82
+ <% if test.skip? -%>
83
+ it '<%= test.id %>', skip: '<%= test.skip_reason %>' do
84
+ <% else -%>
85
+ it '<%= test.id %>' do
86
+ <% end -%>
87
+ response = { status_code: <%= test['code'] %> }
88
+ <% if test['headers'] -%>
89
+ response[:headers] = <%= test['headers'] %>
90
+ <% else -%>
91
+ response[:headers] = {}
92
+ <% end -%>
93
+ <% if test['body'] -%>
94
+ response[:body] = <%= test.stub_body %>
95
+ <% else -%>
96
+ response[:body] = nil
97
+ <% end -%>
98
+ client.stub_responses(:<%= operation_tests.name %>, response)
99
+ response = client.<%= operation_tests.name %>(<%= test.params %>)
100
+ <% if (member_name, _shape = test.streaming_member) -%>
101
+ response.data.<%= member_name.underscore %>.rewind
102
+ response.data.<%= member_name.underscore %> = response.data.<%= member_name.underscore %>.read
103
+ response.data.<%= member_name.underscore %> = nil if response.data.<%= member_name.underscore %>.empty?
104
+ <% end -%>
105
+ <%= test.data_expect %>
106
+ end
107
+ <% end -%>
108
+ end
109
+ <% end -%>
110
+ <% unless operation_tests.error_tests.empty? -%>
111
+ describe 'response errors' do
112
+ <% operation_tests.error_tests.each do |test| -%>
113
+ <% test.comments.each do |line| -%>
114
+ # <%= line %>
115
+ <% end -%>
116
+ <% if test.skip? -%>
117
+ it '<%= test.id %>: <%= test.error_name %>', skip: '<%= test.skip_reason %>' do
118
+ <% else -%>
119
+ it '<%= test.id %>: <%= test.error_name %>' do
120
+ <% end -%>
121
+ response = { status_code: <%= test['code'] %> }
122
+ <% if test['headers'] -%>
123
+ response[:headers] = <%= test['headers'] %>
124
+ <% else -%>
125
+ response[:headers] = {}
126
+ <% end -%>
127
+ <% if test['body'] -%>
128
+ response[:body] = <%= test.stub_body %>
129
+ <% else -%>
130
+ response[:body] = nil
131
+ <% end -%>
132
+ client.stub_responses(:<%= operation_tests.name %>, response)
133
+ expect { client.<%= operation_tests.name %> }.to raise_error do |e|
134
+ expect(e).to be_a(Errors::<%= test.error_name %>)
135
+ <%= test.data_expect %>
136
+ end
137
+ end
138
+ <% end -%>
139
+ end
140
+ <% end -%>
141
+ end
142
+ <% end -%>
143
+ end
144
+ end
@@ -0,0 +1,33 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ TargetRubyVersion: 3.3
4
+ SuggestExtensions: false
5
+
6
+ Gemspec/RequireMFA:
7
+ Enabled: false
8
+
9
+ Layout/LineLength:
10
+ Enabled: false
11
+
12
+ Lint/StructNewOverride:
13
+ Enabled: false
14
+
15
+ Metrics/AbcSize:
16
+ Enabled: false
17
+
18
+ Metrics/BlockLength:
19
+ Enabled: false
20
+
21
+ Metrics/MethodLength:
22
+ Enabled: false
23
+
24
+ Metrics/ModuleLength:
25
+ Enabled: false
26
+
27
+ Naming/FileName:
28
+ Exclude:
29
+ - 'lib/<%= gem_name %>.rb'
30
+
31
+ Style/Documentation:
32
+ Exclude:
33
+ - 'spec/**/*.rb'