-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Generate RBS #2950
Comments
Thanks for reaching out! We met with Soutaro at RubyConf and he told us about your project. We would love to get RBS typing into v3 and would appreciate any help doing so. This would certainly be a large project and may take some time. As far as generation goes, v3 code generation uses Mustache templates. Looking at aws-sdk-rbs-generator, I think most of the logic goes away when using the existing aws-sdk-code-generator. I think we should get a simple gem working, like lambda, as a proof of concept. There's no need to be backwards compatible inside aws-sdk-code-generator within reason. You can test builds with |
Issue1 We need RBS for aws-sdk-coreThere are RBS that should be defined in aws-sdk-core, such as |
Yes. That's fine! A minimal set would be appreciated, as we will have to maintain this going forward as a small team. When we are done, we can setup the minimum version constraints between gems and core. We should also setup steep on CI to check new features are added. |
OK. Since aws-sdk-core is outside the scope of automatic generation and has a broad impact, I intend to limit it to only the minimum necessary RBS. |
Issue2 CI for RBS filesWe should be able to automatically verify the correctness of the output RBS for maintainability. SummaryI recommend implementing the following
DetailsThere are 4 possible methods for testing RBS.
|
it 'can be used with a Resource client' do | |
resource = S3::Resource.new(client: client) | |
expect(resource.client.config).to eq(api_client.config) | |
end |
aws-sdk-ruby/gems/aws-sdk-s3/spec/encryptionV2/client_spec.rb
Lines 179 to 182 in a2d399e
it 'can be used with a Resource client' do | |
resource = S3::Resource.new(client: client) | |
expect(resource.client.config).to eq(api_client.config) | |
end |
That is, when the Encryption client is used as the Resource class.
If we try to express this behavior precisely with types, we would lose the convenience of types in many cases or have to generate distorted RBS.
small modify spec file
Another idea is to tag test files to skip test cases only when using this RBS::Test
.
it '...', rbs_skip: true do
# ...
end
$ rspec --tag '~rbs_skip'
In total there are 90 spec files that are not auto-generated, and 43 aws-sdk-s3 spec files.
Since we found 2 cases in aws-sdk-s3, we can simply calculate that there are about 5 such cases in total.
$ steep check
There are methods to perform this on the implementation and on the sample code.
However, I do not recommend either for this project.
On the implementation
Applying steep check
to the implementation can assist in development and check for correctness in types.
However, there are several issues with this project, which is why I personally do not recommend using it within this project.
The Project is Too Large
Using steep in CI implies the need for high RBS coverage and knowledge of RBS.
This project is large, so it takes time to prepare all types without any omissions.
Auto-Generated Code
Most of the code is auto-generated, so using it for development support offers little benefit.
Keyword Arguments
In many cases, this project uses Hash options instead of keyword arguments.
Therefore, even if RBS uses keyword arguments, the implementation does not, so steep will report an error.
If you stop using keyword arguments in RBS, it will then lose convenience on the user side.
RBS::UnitTest
This is how to write type-specific test code as described below.
https://github.com/ruby/rbs/blob/master/docs/gem.md#testing-your-type-definition
We can ensure the accuracy of RBS against the actual behavior.
However, additional test code needs to be written. Knowledge about types and maintenance costs are required.
Therefore, I don't think it's a suitable option for this project.
My guess is that the S3 tests are likely the most complex/likely to have tests that need to be skipped. I would lean towards adding an rbs_skip tag and just skipping those tests. Though to be honest looking at those two specific test cases - I don't see significant benefit in them (they're only testing that you can pass in the client - not that it is actually api equivalent, since the Resource client does no validation on what is passed in) - I actually think for these two specific cases, we should just remove those test cases. But I think a general strategy of an |
@alextwoods |
Issue3 Handwritten code typeSome services have handwritten custom code. |
I have created a branch here with the generated results for all services at this time. https://github.com/ksss/aws-sdk-ruby/tree/rbs-full-generated |
Thank you! We will check this out this or next week, please allow time for vacation. |
I think code generation cases are fine for now. |
No problem at all. Have a happy New Year 🐉 |
Merged with #2961 |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Describe the feature
Currently, Ruby code generation is done by build_tools, but I propose that RBS files also be generated during this Ruby code generation. RBS refers to Ruby's standard type files and tools, which can be bundled with the gem itself.
I have already been conducting experimental operations for over a year.
In a repository similar to DefinitelyTyped for RBS, I have been generating RBS from
apis/**/*.json
, and it has been used within the RBS community.https://github.com/ruby/gem_rbs_collection/tree/main/generators/aws-sdk-rbs-generator
Use Case
Using LSP (Language Server Protocol) in recent years, we can receive coding assistance as follows:
Moreover, by being incorporated into the upstream, it becomes possible to accurately manage the Ruby code and corresponding RBS for each version.
Proposed Solution
I will integrate the existing
aws-sdk-code-generator
and theaws-sdk-rbs-generator
that I implemented, and organize the workflow so that both Ruby code and RBS code are generated and released simultaneously.Prepare a
sig
directory in each gem and generate RBS files within this directory. This will not affect the Ruby code at all.Other Information
Since I have made numerous commits to RBS, I can provide detailed support regarding RBS.
https://github.com/ruby/rbs/graphs/contributors
https://github.com/ruby/gem_rbs_collection/tree/main/generators/aws-sdk-rbs-generator
Acknowledgements
SDK version used
3
Environment details (OS name and version, etc.)
any
The text was updated successfully, but these errors were encountered: