class SwaggerYard::TypeParser

Public Class Methods

new(model_path = Type::MODEL_PATH) click to toggle source
# File lib/swagger_yard/type_parser.rb, line 142
def initialize(model_path = Type::MODEL_PATH)
  @parser = Parser.new
  @xform  = Transform.new
  @model_path = model_path
end

Public Instance Methods

json_schema(str) click to toggle source
# File lib/swagger_yard/type_parser.rb, line 152
def json_schema(str)
  @xform.apply(parse(str),
               model_path: @model_path,
               resolve_uri: ->(name, prefix) { resolve_uri(name, prefix) })
rescue Parslet::ParseFailed => e
  raise InvalidTypeError, "'#{str}': #{e.message}"
end
parse(str) click to toggle source
# File lib/swagger_yard/type_parser.rb, line 148
def parse(str)
  @parser.parse(str)
end
resolve_uri(name, prefix) click to toggle source
# File lib/swagger_yard/type_parser.rb, line 160
def resolve_uri(name, prefix)
  unless url = SwaggerYard.config.external_schema[prefix]
    raise UndefinedSchemaError, "unknown prefix #{prefix} for #{name}"
  end
  uri, fragment = url.split '#'
  fragment = fragment ? "##{fragment}" : @model_path
  fragment += '/' unless fragment.end_with?('/')
  [uri, fragment]
end