From 4b7b5868613fd9143ed13cb0ea87a063affd9a7d Mon Sep 17 00:00:00 2001 From: Blake Erickson Date: Thu, 6 May 2021 18:35:42 -0600 Subject: [PATCH] DEV: Remove unused rswag script We no longer use this script for helping generate rswag formatted docs because we can use json schema now. --- script/json_to_rswag.rb | 101 ---------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 script/json_to_rswag.rb diff --git a/script/json_to_rswag.rb b/script/json_to_rswag.rb deleted file mode 100644 index e3e25ea2dc7..00000000000 --- a/script/json_to_rswag.rb +++ /dev/null @@ -1,101 +0,0 @@ -# frozen_string_literal: true -require 'json' - -# This script is used for development to help document rswag api responses. It -# takes a json response string as an input and converts it to ruby in the format -# that rswag wants so that you can copy+paste it into the appropriate spec rather -# than typing it by hand. -# -# example: -# -# ruby script/json_to_rswag.rb '{"success":true,"active":true,"message":"Your account is activated and ready to use.","user_id":18}' -# -# will output: -# -# schema type: :object, properties: { -# success: { type: :boolean }, -# active: { type: :boolean }, -# message: { type: :string }, -# user_id: { type: :integer }, -# } - -class JsonToRswag - - def initialize - @output = Array.new - @output.push("schema type: :object, properties: {") - end - - def get_type(k, v) - type = "" - type = "integer" if v.is_a? Integer - type = "number" if v.is_a? Float - type = "object" if v.is_a? Hash - type = "array" if v.is_a? Array - type = "boolean" if v == true || v == false - type = "null" if v == nil - type = "string" if v.is_a? String - if type == "" - puts "Cannot determine type for:" - puts v - exit 1 - end - type - end - - def run(h, indent) - h.each do |k, v| - type = get_type(k, v) - - if type == "object" - @output << "#{' ' * indent}#{k}: {" - @output << "#{' ' * (indent + 2)}type: :object," - @output << "#{' ' * (indent + 2)}properties: {" - run(v, indent + 4) - @output << "#{' ' * indent}}," - end - - if type == "array" - @output << "#{' ' * indent}#{k}: {" - @output << "#{' ' * (indent + 2)}type: :array," - @output << "#{' ' * (indent + 2)}items: {" - a = v.first - if a.is_a? Hash - @output << "#{' ' * (indent + 4)}type: :object," - @output << "#{' ' * (indent + 4)}properties: {" - run(a , indent + 6) - @output << "#{' ' * (indent + 2)}}," - else - @output << "#{' ' * (indent + 2)}}," - end - @output << "#{' ' * indent}}," - end - - if type == "null" - @output << "#{' ' * indent}#{k}: { type: :string, nullable: true }," - elsif type != "object" && type != "array" - @output << "#{' ' * indent}#{k}: { type: :#{type} }," - end - end - - @output << "#{' ' * (indent - 2)}}" - end - - def print - puts @output - end - -end - -input = ARGV[0] - -if input == nil || input == "" - puts "Please pass in a json string." - exit 1 -end - -json = JSON.parse(input) - -json_to_rswag = JsonToRswag.new -json_to_rswag.run(json, 2) -json_to_rswag.print