Sha256: afdfe18a4275bd8f278f1aaff33d12ecac5a1d8cbd6fcaf01281870433dabffa

Contents?: true

Size: 1.18 KB

Versions: 10

Compression:

Stored size: 1.18 KB

Contents

require 'tomograph/tomogram/action'

module Tomograph
  module ApiBlueprint
    class JsonSchema
      def initialize(prefix, json_schema_path)
        @prefix = prefix
        @documentation = MultiJson.load(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'],
                        request: action['request'],
                        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-2.5.4 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.5.3 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.5.2 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.5.1 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.5.0 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.4.2 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.4.1 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.4.0 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.3.0 lib/tomograph/api_blueprint/json_schema.rb
tomograph-2.2.1 lib/tomograph/api_blueprint/json_schema.rb