Two $ref containing "~1" (escaped slash) cause "Invalid reference token:"
Describe the bug Redoc shows an error screen when,
- there are two
$refpointing external file (I'm not sure about more than two) - both of them include
~1, escaped slash character, in its JSON pointer tokens - both of them referencing different files (or JSON pointer tokens?)
This does not happen if the value of two $refs references are same or the path does not include ~1.
The error message for
$ref: "./responses.yml#/StringResponse/application~1json/schema"
is
Something went wrong...
Invalid reference token: application/json-schema
Expected behavior Docs appears without an error, or shows an error that a user can fix or work-around the problem.
Minimal reproducible OpenAPI snippet(if possible)
# oas.yml
openapi: "3.1.0"
info:
title: "Redoc JSON pointer parsing bug"
version: "0.0.1"
paths:
/foo:
get:
responses:
"200":
content:
application/json:
schema:
$ref: "./responses.yml#/StringResponse/application~1json/schema"
/bar:
get:
responses:
"200":
content:
application/json:
schema:
$ref: "./responses.yml#/NumberResponse/application~1json/schema"
# Using this ref instead of the NumberResponse works
#$ref: "./responses.yml#/StringResponse/application~1json/schema"
# Using this (no slash in pointer tokens) ref instead of the NumberResponse works
#$ref: "./responses.yml#/ObjectResponse/application-json/schema"
# responses.yml
StringResponse:
application/json:
schema:
type: string
NumberResponse:
application/json:
schema:
type: number
ObjectResponse:
application-json:
schema:
type: object
properties:
foo:
type: string
Screenshots None.
Additional context None.
Hi @pocka, thank you for the reporting issue. we'll check that.
Hi @pocka, after small investigation, we know where is the problem. It is hard to fix. We should decode $ref before get it. But if we cover current case we broke others. Before we fix that, please, avoid using escape characters in ref. You can do it like that:
# openapi.yaml
...
responses:
"200":
$ref: "./responses.yml#/StringResponse"
# responses.yml
StringResponse:
content:
application/json:
schema:
type: string
Hi, I'm also running into this issue (IntelliJ IDEA changed their openapi editor preview to use redocly instead of swagger-ui).
For my use case I am $referencing a path as follows:
/health:
$ref: cbss/common/v1/common-v1.yaml#/paths/~1health
So I don't immediately see any workaround for avoiding the ~1 as paths need to start with a slash? Except for upgrading to OpenAPI 3.1 which supports named reusable path objects.
@AlexVarchuk I think it should be fixed in openapi-core package we use. Let's discuss it.
I raised the priority to p1.