openapi 3.1: Illegal character in fragment when path reference contains paramneters

Open
#2,159 0 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, openapi

Research direction

Start with the supplied OpenAPI 3.1 YAML and reproduce the failure through OpenAPIV3Parser.resolve. Read ReferenceUtils.java, ReferenceVisitor.java, and the OpenAPI31Traverser path-item flow shown in the stack trace. Done means both path references containing {tid} no longer fail with a URI syntax exception, while the external missing-file behavior remains observable.

Written by the indexing model from the issue text.

Description

Using openapi-generator-maven-plugin 7.12.0 and swagger-parser 2.1.25, use the follwijhg small test case as input spec:


---
servers:
- url: "http://localhost:8080"
openapi: "3.1.0"
paths:

  /v1/test/{tid}:
    $ref: "./anyFile.yaml#/paths/~1v1~1test~1{tid}"

  /v2/test/{tid}:
    $ref: "#/paths/~1v1~1test~1{tid}"  
info:
      title: "test case"
      description: "bug reprduction test case "
      version: "1.0.0"

Both path reference examples get a URI syntax exception complaining about the opening curly bracket. Stack trace is like:

[ERROR] Error resolving #/paths/~1v1~1test~1{tid}
java.net.URISyntaxException: Illegal character in fragment at index 20: #/paths/~1v1~1test~1{tid}
	at java.base/java.net.URI$Parser.fail(URI.java:2995)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3166)
	at java.base/java.net.URI$Parser.parse(URI.java:3210)
	at java.base/java.net.URI.<init>(URI.java:645)
	at io.swagger.v3.parser.reference.ReferenceUtils.toBaseURI(ReferenceUtils.java:15)
	at io.swagger.v3.parser.reference.ReferenceVisitor.toBaseURI(ReferenceVisitor.java:65)
	at io.swagger.v3.parser.reference.ReferenceVisitor.toReference(ReferenceVisitor.java:69)
	at io.swagger.v3.parser.reference.ReferenceVisitor.resolveRef(ReferenceVisitor.java:205)
	at io.swagger.v3.parser.reference.ReferenceVisitor.visitPathItem(ReferenceVisitor.java:108)
	at io.swagger.v3.parser.reference.OpenAPI31Traverser.traversePathItem(OpenAPI31Traverser.java:383)
	at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseMap(OpenAPI31Traverser.java:947)
	at io.swagger.v3.parser.reference.OpenAPI31Traverser.traversePaths(OpenAPI31Traverser.java:197)
	at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverseOpenApi(OpenAPI31Traverser.java:124)
	at io.swagger.v3.parser.reference.OpenAPI31Traverser.traverse(OpenAPI31Traverser.java:65)
	at io.swagger.v3.parser.reference.OpenAPIDereferencer31.dereference(OpenAPIDereferencer31.java:74)
	at io.swagger.v3.parser.OpenAPIV3Parser.resolve(OpenAPIV3Parser.java:227)

with openapi: "3.0.0" it works fine, only compaining about the nonexistance of the referenced file..

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

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.

More from swagger-api/swagger-parser

All issues in swagger-api/swagger-parser

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.