question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails to resolve correct path/filename for extended $ref

See original GitHub issue

I recently ran into an issue testing some of my more complex schema documents where combination schema $refs cannot be resolved properly if they are part of an “extended” $ref. It is a little hard to explain the case, but I think I have found a simple enough schema that causes the problem to occur.

// base.json
{
  "type": "object",
  "properties": {
    "some_value": { "$ref": "defs.json#/definitions/astring" }
  }
}

//

{
  "definitions": {
    "astring": {
      "description": "astring",
      "$ref": "defs2.json#/definitions/bstring"
    }
  }
}


// defs2.json
{
  "definitions": {
    "bstring": {
      "oneOf": [
        {
          "$ref": "#/definitions/cstring"
        },
        {
          "$ref": "#/definitions/dstring"
        }
      ]
    },
    "cstring": {
      "type": "string"
    },
    "dstring": {
      "type": "number"
    }
  }
}

The error that I see when trying to resolve this looks like: Error while processing route: dynamic-form Token "cstring" does not exist. MissingPointerError: Token "cstring" does not exist.

This only seems to happen when the intermediate schema object is an “extended” ref. For example, if we remove the description from astring then we are able to dereference without issue. From doing some debugging it looks to me like our issue is that when resolving cstring, the path we resolve is defs.json#/definitions/cstring instead of looking in defs2.json. I think this is because when we resolve extended $refs, we explicitly do not update the pointer’s path.

For reference: https://github.com/APIDevTools/json-schema-ref-parser/blob/13b00923fb279cfcb2a72e0906f3eadc13199d08/lib/pointer.js#L240-L245

I would like to propose a fix, but feel ill-equipped to do so without some guidance. It does seem like updating the path in the above code fixes my specific issue, but clearly that decision was made for a reason so I’d rather not step on any toes without understanding the intent. Any thoughts would be greatly appreciated!

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
philsturgeoncommented, Jun 16, 2022

@y0n3r this isn’t a simple thing, and lets not just stamp our feet and talk about being disappointed. All time spent on this is entirely voluntary, and I already run a reforestation charity with about 40 hours of my free time each week, so sometimes issues dont get seen to as fast as we’d all like.

@karlvr thank you for submitting a pull request, I’ll talk to you over there about getting it moving.

Everyone else, if you’re seeing this issue, please give https://www.npmjs.com/package/@openapi-generator-plus/json-schema-ref-parser a try and see if it fixes that issue. We’ll get the changes merged upstream ASAP.

1reaction
btruhandcommented, Apr 7, 2021

@karlvr just got back to replying on this. I actually realized my problem is elsewhere (at least for the case that I was testing). Though I’ll try to give your solution a whirl and see how it goes and get back with results for future reference

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error message when you open or save a file in ...
Enter a shorter path. Error message 4. <Filename> could not be found. Check the spelling of the filename, and verify that the file...
Read more >
Can't push to GitHub because of large file which I already ...
It worked perfectly. I then got an error on a second file that I needed to remove: remote: error: File <path/filename> is 109.99...
Read more >
Error: Can't find the file: “[path\FileName]”. Mak...
Resolution. First, verify that the file is specified correctly in the tool. Check that the file is in the expected location.
Read more >
The specified path, file name, or both are too long - Support
Purpose You want to resolve the error "The file path is too long". Background A file name that was provided, either on the......
Read more >
Integrating Long Path Names in Windows Applications
If you pass a Long Path filename to a Windows or .NET API it'll work with the extended path syntax filename even when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found