class MobileWorkflow::OpenApiSpec::Parser
Public Class Methods
new(open_api_spec_string)
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 5 def initialize(open_api_spec_string) @open_api_spec_string = open_api_spec_string end
Public Instance Methods
controller_name_to_actions()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 22 def controller_name_to_actions @controller_name_to_actions ||= parse_controller_names_to_actions end
model_name_to_properties()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 9 def model_name_to_properties @model_properties = {} schemas.each_pair do |model_name, schema| next if model_name.start_with?("MW") model_name = model_name.underscore model_properties = schema_model_properties(model_name, schema) @model_properties[model_name] = model_properties end @model_properties end
paths()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 26 def paths @paths ||= open_api_spec[:paths].keys end
schemas()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 30 def schemas @schemas ||= open_api_spec[:components][:schemas] end
Private Instance Methods
model_property_type(property)
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 59 def model_property_type(property) return property["type"] unless property["type"].blank? return 'attachment' if property['$ref'] == "#/components/schemas/MWAttachment" raise "Unknown property type: #{property}" end
open_api_spec()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 51 def open_api_spec @open_api_spec ||= read_openapi_spec end
parse_controller_names_to_actions()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 35 def parse_controller_names_to_actions controllers = {} paths.each do |path| path_items = path.split('/') controller_name = path_items[1] controllers[controller_name] = [] unless controllers.key?(controller_name) open_api_spec[:paths][path].keys.each do |method| controllers[controller_name] << 'create' if path_items.count == 2 && method == 'post' controllers[controller_name] << 'index' if path_items.count == 2 && method == 'get' controllers[controller_name] << 'show' if path_items.count == 3 && method == 'get' end end controllers end
read_openapi_spec()
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 66 def read_openapi_spec @read_openapi_spec ||= JSON.parse(@open_api_spec_string).with_indifferent_access end
schema_model_properties(name, schema)
click to toggle source
# File lib/mobile_workflow/open_api_spec/parser.rb, line 55 def schema_model_properties(name, schema) schema["properties"].keys.collect{|key| "#{key}:#{model_property_type(schema["properties"][key])}" }.join(" ") end