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

Added Code Generator For Ruby (Faraday) #374

Merged
merged 8 commits into from
Apr 6, 2024

Conversation

AcousticDeveloper
Copy link
Contributor

PR Description

This PR adds automated code generation for Ruby's Faraday library and also tests the generated code.

Related Issues

Checklist

  • I have gone through the contributing guide
  • I have updated my branch and synced it with project main branch before making this PR
  • I have run the tests (flutter test) and all tests are passing

Added/updated tests?

  • Yes, I have added and tested all the test cases and the generated code behaves as expected.

Instructions to run the generated code in local computer

  1. Install ruby and setup path so that ruby and gem executable are available.
  2. Run
gem install bundler

to install bundle as a command line tool.
4. Inside a directory create one GemFile and main.rb file.
5. Add faraday as mentioned in the Documentation and Faraday Multipart for sending multipart form requests. Add them inside the GemFile along with one source attribute at the top of the GemFile. Then run

bundle install

to install the dependencies.
6. Copy the generated code inside main.rb file.
7. Run ruby ./main.rb to run the generated code.

Note: For HEAD 2 test case, the initial response has status code 301 but faraday_middleware gem, which was previously required for following redirections, is deprecated and a curated list has been published under awesome-faraday by the maintainers. The redirection middleware is now bundled as it's own gem faraday-follow-redirects which is an external dependency which I have not included in code generator.

I wish to add that after discussing that with maintainers. Integrating redirection following is mentioned in the documentation as
image
and can be achieved by adding the faraday.response :follow_redirects statement above adapter setup.

image

Along with that, we need to add the require statement with the existing require statements so that the respective code is imported.

Thus currently running generated code for HEAD 2 returns 301 but API Dash returns 405, which can be modified accordingly for both to return 405 and get the desired output of the user. If required, I am willing to add the support for redirection and modify the required code.

@animator
Copy link
Member

animator commented Apr 6, 2024

Thanks for the PR

@animator animator merged commit 90eed29 into foss42:main Apr 6, 2024
@AcousticDeveloper
Copy link
Contributor Author

AcousticDeveloper commented Apr 6, 2024

Thanks for the PR

You are welcome @animator . I had a query though. I was reviewing the changes made to the PR before getting merged, and saw that application/x-www-form-urlencoded content type header setup was removed. I wanted to ask whether this should be totally avoided from next time onwards and #337 should be used to set it up automatically? In that case, I'll try to fix #337 before raising any other code generator PRs.

Regarding the implementation, as far as I could understand, the content type is set using the dropdown for text/json/formdata.
image

So I think there are two ways to fix the issue, either we can restrict the use of requestModel.requestBodyContentType.header in code generators as this value is directly set while creating the enum.

image

Instead we can use a custom requestModel.getContentTypeString() method (yet to be implemented) which can generate the string depending upon request model contents. Or we can follow a more Postman centric approach by giving the users a separate window for application/x-www-url-encoded body type.

image

PS: We can further discuss about the approaches under #377.

Thanks again for merging the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add CodeGen for Ruby (faraday)
2 participants