export function parseReferenceInSwagger()

in src/lib/util/utils.ts [245:273]


export function parseReferenceInSwagger(reference: string) {
  if (!reference || (reference && reference.trim().length === 0)) {
    throw new Error("reference cannot be null or undefined and it must be a non-empty string.")
  }

  const result: References = {}
  if (reference.includes("#")) {
    // local reference in the doc
    if (reference.startsWith("#/")) {
      result.localReference = {
        value: reference,
        accessorProperty: reference.slice(2).replace("/", ".")
      }
    } else {
      // filePath+localReference
      const segments = reference.split("#")
      result.filePath = segments[0]
      result.localReference = {
        value: "#" + segments[1],
        accessorProperty: segments[1].slice(1).replace("/", ".")
      }
    }
  } else {
    // we are assuming that the string is a relative filePath
    result.filePath = reference
  }

  return result
}