swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

DocCache doesnt work when baseDoc or url contains a capital letter

Open aherrmann13 opened this issue 7 years ago • 0 comments

Q&A (please complete the following information)

  • OS: Windows 10
  • Environment: Chrome 67
  • Method of installation: npm
  • Swagger-Client version: 3.8.7
  • Swagger/OpenAPI version: OpenAPI 3.0

Describe the bug you're encountering

using a swagger doc with a capital letter in the URL will not cache properly.

in resolver.js

   if (baseDoc) {
      plugins.refs.docCache[baseDoc] = _spec
    }

in ref.js

    let basePath
    try {
      basePath = (baseDoc || refPath) ? absoluteify(refPath, baseDoc) : null
    }

basepath will be set to all lower case from absolutify because

function absoluteify(path, basePath) {
  if (!ABSOLUTE_URL_REGEXP.test(path)) {
    if (!basePath) {
      throw new JSONRefError(`Tried to resolve a relative URL, without having a basePath. path: '${path}' basePath: '${basePath}'`)
    }
    return url.resolve(basePath, path)
  }
  return path
}

will return a url with all lower case and will not find the doc in the getDoc call, as it passes in the basePath to extractFromDoc(basePath, pointer)

To reproduce...

use a baseDoc or url for swagger.json with a capital letter

Expected behavior

caches doc properly

Additional context or thoughts

This is mainly an issue with recursive models. I was not able to step through the code to find out the actual cause but recursive models will break (infinitely loop) when it is not able to cache the document

aherrmann13 avatar Jul 06 '18 19:07 aherrmann13