Sha256: 7887cb6320a0d6fc77401355f7421d23f8b85191880c3fb2e67d966938c54ca4

Contents?: true

Size: 1.2 KB

Versions: 10

Compression:

Stored size: 1.2 KB

Contents

require 'tomograph/tomogram/action'

module Tomograph
  module ApiBlueprint
    class JsonSchema
      def initialize(prefix, json_schema_path)
        @prefix = prefix
        @documentation = JSON.parse(File.read(json_schema_path))
      end

      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

      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
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tomograph-3.2.7 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.2.6 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.2.5 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.2.4 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.2.1 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.2.0 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.1.6 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.1.5 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.1.4 lib/tomograph/api_blueprint/json_schema.rb
tomograph-3.1.3 lib/tomograph/api_blueprint/json_schema.rb