swagger-api / swagger-api/swagger-parser
swagger-parser-v3 failed on Windows for relative $ref
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
On Windows for swagger-parver-v3 v2.0.24, we have StringIndexOutOfBoundsException for relative $ref like
$ref: './path/file.yaml#/components/schemas/Type'
Parsing problem is on ExternalRefProcessor.processRefToExternalSchema at line 113
String parent = file.substring(0, file.lastIndexOf(File.separatorChar));
I don't think that OS specific separator need to be use here.
In yaml, all paths are with '/' no ?
I think only lastIndexOf '/' is needed :
String parent = file.substring(0, file.lastIndexOf('/'));
But after this change, we have other problem on :
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
After normalise relative in file part "#/components/schemas/Type" is also convert to :
path\file.yaml#\components\schemas\Type
I made some change for adjust that with :
if (schemaFullRef.contains("#/")) {
String[] parts = schemaFullRef.split("#/");
String schemaFullRefFilePart = parts[0];
String schemaFullRefInternalRefPart = parts[1];
schemaFullRef = Paths.get(parent, schemaFullRefFilePart).normalize().toString() + "#/" + schemaFullRefInternalRefPart;
} else {
schemaFullRef = Paths.get(parent, schemaFullRef).normalize().toString();
}
This changes made build OK on Windows and Linux but I'm not sure to cover all case.
Someone see a better approch for a PR ?
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
Start in ExternalRefProcessor.processRefToExternalSchema around line 113 and trace how relative $ref values are split and normalized. Reproduce the reported relative reference on Windows and Linux, then verify that the file path is normalized without changing the #/components/schemas/Type fragment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100