swagger-api / swagger-api/swagger-client

DocCache doesnt work when baseDoc or url contains a capital letter

Open
#1,340 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cat: resolver cat: specmap epic: fatal resolver edge cases P2 type: bug
Dominant language
JavaScript
Stars
2.7k
Forks
765
Avg merge
1d 1h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in resolver.js and ref.js, tracing how baseDoc or refPath reaches absoluteify, getDoc, and extractFromDoc. Reproduce the issue with a swagger.json URL containing a capital letter, then verify that the document is cached and recursive models no longer loop when resolving references.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.