Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two $ref containing "~1" (escaped slash) cause "Invalid reference token:" #2337

Open
pocka opened this issue Jun 13, 2023 · 4 comments
Open

Comments

@pocka
Copy link

pocka commented Jun 13, 2023

Describe the bug
Redoc shows an error screen when,

  • there are two $ref pointing 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 

(Reproduction CodeSandbox)

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.

@AlexVarchuk
Copy link
Collaborator

Hi @pocka, thank you for the reporting issue. we'll check that.

@AlexVarchuk
Copy link
Collaborator

AlexVarchuk commented Jun 15, 2023

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

@jpraet
Copy link

jpraet commented Aug 31, 2023

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.

@RomanHotsiy RomanHotsiy added the p1 label Sep 3, 2023
@RomanHotsiy
Copy link
Member

@AlexVarchuk I think it should be fixed in openapi-core package we use. Let's discuss it.

I raised the priority to p1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants