class Tomograph::ApiBlueprint::JsonSchema

Public Class Methods

new(prefix, json_schema_path) click to toggle source
# File lib/tomograph/api_blueprint/json_schema.rb, line 6
def initialize(prefix, json_schema_path)
  @prefix = prefix
  @documentation = JSON.parse(File.read(json_schema_path))
end

Public Instance Methods

to_resources() click to toggle source
# File lib/tomograph/api_blueprint/json_schema.rb, line 23
def to_resources
  return @to_resources if @to_resources

  @to_resources = @documentation.group_by { |action| action['resource'] }
  @to_resources = @to_resources.each_with_object({}) do |(resource, actions), resource_map|
    requests = actions.map do |action|
      "#{action['method']} #{@prefix}#{action['path']}"
    end
    resource_map[resource] = requests
  end
end
to_tomogram() click to toggle source
# File lib/tomograph/api_blueprint/json_schema.rb, line 11
def to_tomogram
  @tomogram ||= @documentation.inject([]) do |result, action|
    result.push(Tomograph::Tomogram::Action.new(
                  path: "#{@prefix}#{action['path']}",
                  method:  action['method'],
                  content_type: action['content-type'],
                  requests: action['requests'],
                  responses: action['responses'],
                  resource: action['resource']))
  end
end