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
Support RBS for aws-sdk-core and service gems #2961
Merged
+1,657
−22
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
17320ef
Add RBS signature files to support static type checking
ksss adab340
Introduce RBS generator
ksss 87548aa
Build with RBS generator
ksss bda2499
Add CHANGELOG
ksss 469ccd5
Fix typo
ksss 2e266d8
Fixed to not use Client instance
ksss a412cf1
Direct reference type
ksss 76d5786
Return Success or Error interface on operation
ksss 4baf332
Remove unneeded argument
ksss 9cbacaa
Add rbs:test task
ksss c51f7b1
Adjust format
ksss ab5dc94
Fix core types
ksss c8f6f06
Error response should not include overloads
ksss be2e16e
Currently S3 is sufficient
ksss 2fab3e2
Add rspec tag `rbs_test: :skip`
ksss df16406
Add more method documentation
ksss 0e52449
Fix testing CI for RBS
ksss 60ff211
Regenerate sample result
ksss a65d569
Fix type
ksss 109ac5d
Fix skip by aws-sdk-amplifybackend
ksss 4b8bd59
Merge branch 'version-3' into rbs-aws-sdk-core
mullermp 47206a5
Add `rbs_type` attribute for PluginOption
ksss 7834758
Fix typo
ksss 238c219
Fix skip members
ksss af94b5c
Support empty identifiers
ksss 3d7c881
Avoid duplicate methods
ksss 9a1fe40
Allows some option
ksss 4b3ec10
Validate all at once
ksss 44907a8
Regenerate lambda
ksss 0d15fbb
Support Ruby v2.5~
ksss c54efd3
Merge branch 'version-3' into rbs-aws-sdk-core
ksss a67d217
Merge branch 'version-3' into rbs-aws-sdk-core
mullermp 6a5f0ba
Fix region spec
mullermp 9bbf038
Revert sample signatures for aws-sdk-lambda
ksss 83dfdf1
Revert generated code
ksss c07478f
Update ruby
ksss 7e99658
Set RBS type for undefined class
ksss 335a613
Merge branch 'version-3' into rbs-aws-sdk-core
mullermp 8b2a736
Undo more codegen and prepare version bump
mullermp 637a5a0
Merge branch 'version-3' into rbs-aws-sdk-core
mullermp File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/rbs.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
module AwsSdkCodeGenerator | ||
module RBS | ||
class << self | ||
def to_type(shape_ref, api) | ||
_, shape = Api.resolve(shape_ref, api) | ||
case shape['type'] | ||
when 'blob' then Api.streaming?(shape_ref, api) ? '::IO' : '::String' | ||
when 'boolean' then 'bool' | ||
when 'byte' then '::Integer' | ||
when 'character' then '::String' | ||
when 'double' then '::Float' | ||
when 'float' then '::Float' | ||
when 'integer' then '::Integer' | ||
when 'list' then "::Array[#{to_type(shape['member'], api)}]" | ||
when 'long' then '::Integer' | ||
when 'map' then "::Hash[#{to_type(shape['key'], api)}, #{to_type(shape['value'], api)}]" | ||
when 'string' | ||
if shape['enum'] | ||
"(#{shape['enum'].map { |e| "\"#{e}\"" }.join(" | ")})" | ||
elsif Api.streaming?(shape_ref, api) | ||
'::IO' | ||
else | ||
'::String' | ||
end | ||
when 'structure' | ||
if shape['document'] | ||
'untyped' | ||
else | ||
"Types::#{shape_ref['shape']}" | ||
end | ||
when 'timestamp' then '::Time' | ||
else | ||
raise "unhandled type #{shape['type'].inspect}" | ||
end | ||
end | ||
end | ||
end | ||
end |
38 changes: 38 additions & 0 deletions
38
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/rbs/error_list.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# frozen_string_literal: true | ||
|
||
module AwsSdkCodeGenerator | ||
module RBS | ||
class ErrorList | ||
include Enumerable | ||
|
||
def initialize(api:, module_name:) | ||
@api = api | ||
@module_name = module_name | ||
@errors = @api['shapes'].inject([]) do |es, (name, shape)| | ||
if error_struct?(shape) | ||
members = shape["members"].map do |member_name, member_body| | ||
MethodSignature.new( | ||
method_name: Underscore.underscore(member_name), | ||
overloads: ["() -> #{Docstring.ucfirst(member_body['type'] ||'::String')}"] | ||
) | ||
end | ||
es << { | ||
name: name, | ||
members: members, | ||
} | ||
end | ||
es | ||
end | ||
end | ||
|
||
def error_struct?(shape) | ||
shape['type'] == 'structure' && !!!shape['event'] && | ||
(shape['error'] || shape['exception']) | ||
end | ||
|
||
def to_a | ||
@errors | ||
end | ||
end | ||
end | ||
end |
159 changes: 159 additions & 0 deletions
159
...d_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/rbs/keyword_argument_builder.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# frozen_string_literal: true | ||
|
||
module AwsSdkCodeGenerator | ||
module RBS | ||
# similar to SyntaxExampleHash | ||
class KeywordArgumentBuilder | ||
include Helper | ||
|
||
attr_reader :newline | ||
|
||
def initialize(api:, shape:, newline:) | ||
@api = api | ||
@shape = shape | ||
@newline = newline | ||
end | ||
|
||
def format(indent: '') | ||
members_str = struct_members(@shape, indent, [], keyword: true) | ||
result = [] | ||
result << '' if newline | ||
result << members_str if !members_str.empty? | ||
result << indent if newline | ||
result.join(joint) | ||
end | ||
|
||
def struct(struct_shape, i, visited) | ||
members_str = struct_members(struct_shape, i, visited, keyword: false) | ||
result = ["{"] | ||
result << members_str if struct_shape['members']&.empty?&.! | ||
result << "#{i}}" | ||
result.join(joint) | ||
end | ||
|
||
def struct_members(struct_shape, i, visited, keyword:) | ||
lines = [] | ||
unless struct_shape['members'].nil? | ||
n = 0 | ||
struct_shape['members'].each do |member_name, member_ref| | ||
next if member_ref['documented'] === false | ||
more_indent = newline ? " " : "" | ||
if @api['shapes'][member_ref['shape']]['eventstream'] === true | ||
# FIXME: "input_event_stream_hander: EventStreams::#{member_ref['shape']}.new" | ||
lines << "#{i}#{more_indent}input_event_stream_hander: untyped," | ||
else | ||
lines << "#{i}#{more_indent}#{struct_member(struct_shape, member_name, member_ref, i, visited, keyword: keyword)}" | ||
end | ||
end | ||
end | ||
if lines.empty? | ||
"" | ||
else | ||
lines.join(joint).chomp(",") | ||
end | ||
end | ||
|
||
def struct_member(struct, member_name, member_ref, i, visited, keyword:) | ||
required = (struct['required'] || []).include?(member_name) | ||
if keyword | ||
"#{required ? '' : '?'}#{underscore(member_name)}: #{ref_value(member_ref, i + more_indent, visited)}," | ||
else | ||
"#{underscore(member_name)}: #{ref_value(member_ref, i + more_indent, visited)}#{required ? '' : '?'}," | ||
end | ||
end | ||
|
||
def ref_value(ref, i, visited) | ||
if visited.include?(ref['shape']) | ||
return "untyped" | ||
else | ||
visited = visited + [ref['shape']] | ||
end | ||
|
||
s = shape(ref) | ||
case s['type'] | ||
when 'structure' | ||
if ref['shape'] == 'AttributeValue' | ||
'untyped' | ||
else | ||
struct(s, i, visited) | ||
end | ||
when 'blob' | ||
if ref['streaming'] | ||
"::String | ::StringIO | ::File" # input only | ||
else | ||
"::String" | ||
end | ||
when 'list' then list(s, i, visited) | ||
when 'map' then map(s, i, visited) | ||
when 'boolean' then "bool" | ||
when 'integer', 'long' then '::Integer' | ||
when 'float', 'double' then '::Float' | ||
when 'byte' then '::Integer' | ||
when 'character' then '::String' | ||
when 'string' then string(ref) | ||
when 'timestamp' then '::Time' | ||
else raise "unsupported shape #{s['type'].inspect}" | ||
end | ||
end | ||
|
||
def list(list_shape, i, visited) | ||
member_ref = list_shape['member'] | ||
if complex?(member_ref) | ||
complex_list(member_ref, i, visited) | ||
else | ||
scalar_list(member_ref, i, visited) | ||
end | ||
end | ||
|
||
def scalar_list(member_ref, i, visited) | ||
"Array[#{ref_value(member_ref, i, visited)}]" | ||
end | ||
|
||
def complex_list(member_ref, i, visited) | ||
newline_indent = newline ? "\n#{i}" : "" | ||
"Array[#{newline_indent}#{more_indent}#{ref_value(member_ref, i + more_indent, visited)},#{newline_indent}]" | ||
end | ||
|
||
def complex?(ref) | ||
s = shape(ref) | ||
if s['type'] == 'structure' | ||
!ddb_av?(ref) | ||
else | ||
s['type'] == 'list' || s['type'] == 'map' | ||
end | ||
end | ||
|
||
def ddb_av?(ref) | ||
s = shape(ref) | ||
case s['type'] | ||
when 'list' then ddb_av?(s['member']) | ||
when 'structure' then ref['shape'] == 'AttributeValue' | ||
else false | ||
end | ||
end | ||
|
||
def map(map_shape, i, visited) | ||
key = string(map_shape['key']) | ||
value = ref_value(map_shape['value'], i + more_indent, visited) | ||
"Hash[#{key}, #{value}]" | ||
end | ||
|
||
def string(ref) | ||
string_shape = shape(ref) | ||
if string_shape['enum'] | ||
"(#{string_shape['enum'].map { |s| "\"#{s}\"" }.join(" | ")})" | ||
else ref['shape'] | ||
"::String" | ||
end | ||
end | ||
|
||
def more_indent | ||
newline ? " " : "" | ||
end | ||
|
||
def joint | ||
newline ? "\n" : " " | ||
end | ||
end | ||
end | ||
end |
11 changes: 11 additions & 0 deletions
11
build_tools/aws-sdk-code-generator/lib/aws-sdk-code-generator/rbs/method_signature.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module AwsSdkCodeGenerator | ||
module RBS | ||
class MethodSignature < Struct.new(:method_name, :overloads, keyword_init: true) | ||
def signature | ||
"def #{method_name}: #{overloads.join("\n #{" " * method_name.length}| ")}" | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you want to check
@service.support_rbs?
here, similar toif @service.smoke_tests
above, sincerbs_files
method entirely relies on it being enabled.