Sha256: e073c8d1c6f6b2a43f7b47db3e9c54f91a8f62290e20b4057bf77b356efb1455

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

autoload :YAML, 'yaml'
autoload :JSON, 'json'

module Swagger
  # Provides classes for loading Swagger from YAML or JSON.
  module Parsers
    def self.parser_for(format)
      case format
      when '.yaml', '.yml', :yaml
        YAMLParser
      when '.json', '.js', :json
        JSONParser
      end
    end

    # Parses YAML content
    class YAMLParser
      # Parses a YAML document
      # @param content [String] The YAML content to parse
      # @return [Hash] the parsed content
      def self.parse(content)
        if YAML.respond_to? :safe_load
          YAML.safe_load(content)
        else
          # rubocop:disable Security/YAMLLoad
          YAML.load(content)
        end
      end
    end

    # Parses JSON content
    class JSONParser
      # Parses a JSON document
      # @param content [String] The JSON content to parse
      # @return [Hash] the parsed content
      def self.parse(content)
        JSON.parse(content)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
swagger-core-0.3.0 lib/swagger/parsers.rb