0.0
The project is in a healthy, maintained state
Generate Http client and rbs files
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

>= 0
 Project Readme

Install

gem install swagger-to-rbs

Usage

Dowload swagger spec

Example:

curl https://petstore3.swagger.io/api/v3/openapi.json > swagger.json

Generate http client based on Httparty gem

swagger-to-rbs generate --name PetApi --spec swagger.json

Result:

require 'httparty'

class PetApi
  include HTTParty
  base_uri "/api/v3"
  #...

  def initialize
    self.class.headers({ 'Content-Type' => 'application/json' })
  end

  def getPetById(petId, options = {})
    self.class.get("/pet/#{petId}", options)
  end

  def updatePet(body, options = {})
    self.class.put("/pet", { body: body.to_json }.merge(options))
  end

  def addPet(body, options = {})
    self.class.post("/pet", { body: body.to_json }.merge(options))
  end
  #...
end

Send default header in all request

Authorization example:

api = PetApi.new

MyApi.headers(Authorization: "Bearer #{access_token}")
MyApi.base_uri("http://otherurl.test/api/v1)

api.getPetById(1)