Sha256: fa57ee17b99b3e2a07fef4582377655db2d08a2662cca5dd13f13f745b29595d
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
module OasParser class Pointer def initialize(raw_pointer) @raw_pointer = raw_pointer end def resolve(document) return document if escaped_pointer == "" tokens.reduce(document) do |nested_doc, token| token = token.to_i if token[/^-?\d+$/] nested_doc.fetch(token) end end # Detect circular reference by checking whether the ref exists in current path. # # Example: # components: # schemas: # Pet: # type: object # properties: # name: # type: string # children: # type: array # items: # <--- parsing here # - $ref: '#/components/schemas/Pet' # # path: "/components/schemas/Pet/properties/children/items" # raw_pointer: "#/components/schemas/Pet" # # It'd return true when we're parsing the pet children items where the ref points back to itself. def circular_reference?(path) path.include?("#{escaped_pointer}/") end def escaped_pointer if @raw_pointer.start_with?("#") Addressable::URI.unencode(@raw_pointer[1..-1]) else @raw_pointer end end private def parse_token(token) token.gsub("~0", "~").gsub("~1", "/") end def tokens tokens = escaped_pointer[1..-1].split("/") if @raw_pointer.end_with?("/") tokens << "" end tokens.map do |token| parse_token(token) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
oas_parser-0.25.3 | lib/oas_parser/pointer.rb |