foss42 / apidash

API Dash is a beautiful open-source cross-platform API Client built using Flutter which can help you easily create & customize your API requests, visually inspect responses and generate API integration code. A lightweight alternative to postman/insomnia.
https://apidash.dev
Apache License 2.0
1.43k stars 269 forks source link

Added Code Generation For Ruby (Faraday) #366

Closed AcousticDeveloper closed 5 months ago

AcousticDeveloper commented 5 months ago

PR Description

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

Related Issues

Checklist

Added/updated tests?

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.

  3. Inside a directory create one GemFile and main.rb file.
  4. 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.

  5. Copy the generated code inside main.rb file.
  6. 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 whereas API Dash returns 405, which can be modified by the above way and changed to whichever output is desired by the user. If required, I am willing to add the support for redirection and modify the required code.

animator commented 5 months ago

There was some issue due to merging of the julia PR. This PR got automatically merged. Open a new PR for ruby faraday.

AcousticDeveloper commented 5 months ago

@animator I have created a new pull request #374 for ruby faraday.