swagger-api / swagger-api/swagger-parser
Difference in resolving URI's causes difficult-to-find errors
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
So yesterday I ran into a problem that threw the following error:
Unable to load " + refFormat + " ref: " + file + " path: "+parentDirectory
And it lead me down a merry chase to the issue. Ultimatetely, it comes down to this.
Consider the following references:
./foo.yaml
./foo.yaml/
If I were to resolve this path as a URL, my server would resolve this as a full path: (...)/foo.yaml/. It would immediately result in an error.
However, (most) filesystems do not, they would resolve it as: (...)/foo.yaml. Correcting the 'mistake' of the trailing slash, and loading the schema anyway.
Now, let's assume that in foo.yaml we have a reference to another file, like ../bar.yaml. Now, we've got problems.
The URI resolver has the following outcomes:
./foo.yaml + ../bar.yaml = ../bar.yaml
./foo.yaml/ + ../bar.yaml = ./bar.yaml
I've been thinking about this since yesterday, and I have no good solution direction for this problem. There's a few things I considered:
- Do we know what exact filepath was eventually resolved when loading the
bar.yamlschema. If so, we could compare it to the path we thought it was at, and fix it if it was different. - Can we remove trailing slashes if we are resolving a file in the context of a file system? But how would you identify that file without explicit naming conventions?
- Is this not a actually a problem, but programmer error? The annoying thing is that the error is not in the reference to
bar.yamlfromfoo.yaml, but the reference tofoo.yaml. I wonder if we could at least clarify that.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no source file, test, or entry point. Start by reproducing the contrasting resolutions for ./foo.yaml, ./foo.yaml/, and ../bar.yaml, then trace the URI resolver and schema-loading path. Done should make the resulting error identify the problematic reference clearly and cover the behavior with regression tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100