Created
August 26, 2021 05:14
-
-
Save synth/1ea04df70fdb0d1af470394e3a4ae290 to your computer and use it in GitHub Desktop.
Convert Swagger2 to OpenApi3
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
require 'restclient' | |
class OpenapiConverter | |
CONVERTER_URL = "https://converter.swagger.io/api/convert" | |
CONVERTED_FILE_PATH = File.join(Rails.root, "/public/api/docs") | |
CONVERTED_FILENAME = "swagger-spec-v3.json" | |
LOGGER = Rails.logger | |
attr_accessor :url | |
def self.convert(url) | |
new(url).convert | |
end | |
def self.convert_and_write_to_public(url) | |
converted_api = convert(url) | |
full_filename = "#{CONVERTED_FILE_PATH}/#{CONVERTED_FILENAME}" | |
File.write(full_filename, converted_api) | |
end | |
def initialize(url) | |
@url = url | |
end | |
def convert | |
full_url = "#{CONVERTER_URL}?url=#{CGI.escape(url)}" | |
RestClient.get(full_url).body | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment