Sha256: 6d490052f3c6d79539cdd77f223417232a3694c48f661f03728b28a7d6559197
Contents?: true
Size: 873 Bytes
Versions: 7
Compression:
Stored size: 873 Bytes
Contents
# frozen_string_literal: true require "psych" require "json" module Openapi3Parser class SourceInput class StringParser def self.call(input, filename = nil) new(input, filename).call end def initialize(input, filename) @input = input @filename = filename end def call json? ? parse_json : parse_yaml end private_class_method :new private attr_reader :input, :filename def json? return false if filename && ::File.extname(filename) == ".yaml" json_filename = filename && ::File.extname(filename) == ".json" json_filename || input.strip[0] == "{" end def parse_json JSON.parse(input) end def parse_yaml Psych.safe_load(input, permitted_classes: [Date, Time], aliases: true) end end end end
Version data entries
7 entries across 7 versions & 2 rubygems