Skip to content

Feature Request: support operationRef or operationId references in the fragment identifier #1625

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

Open
mjpieters opened this issue May 20, 2021 · 1 comment

Comments

@mjpieters
Copy link

Please support operationId:<opId> and operationRef:<opRef> as additional fragment identifiers to move the view to a specific operation. I believe that this could be implemented with a hashchanged event handler.

  • document#operationId:<opId> would scroll to the operation with operationId set to opId.
  • document#operationRef:<opRef> would scroll to the operation at the specific reference path. This would be limited to #/paths/<encodedPath>/<operationName>, or possibly just <encodedPath>/<operationName> as the #/paths/ component of the path is implied in the operationRef: prefix, and there is no real option to support relative paths here.

Examples for the Petshop demo document would be:

  • https://redocly.github.io/redoc/#operationId:getPetById
  • https://redocly.github.io/redoc/#operationRef:#/paths/~1pet~1{petId}/get

Both would end up at the same location as the #operation/getPetById anchor.

motivation

We would like to reliably deeplink, from markdown documentation within the API or from other locations, to the operations an API document regardless of the OpenAPI renderer used.

Currently, ReDoc will generate anchors for a given operation, in one of two forms:

  • if the operationId key is set: operation/{operationId}
  • otherwise: tags/{tagName}/{operationRef}/, where the operationRef is relative to the document root (not prefixed with #/paths/... but with paths/). I am assuming that the tagName used is the first registered tag listed in the operation tags list.

You can use these anchor identifiers as fragment identifiers in the URL (../#operation/getPetById), and so you can link to these from Markdown too.

However, these paths are very specific to ReDoc, even though they have a direct relationship to the OpenAPI specification rendering of the doc. Relying on this by explicitly using the same format in markdown links feels like we'd be relying on implementation details.

existing OpenAPI discussion

I see that there is a [related discussion on the OAI spec repository, where there is a proposal to have an OpenAPI documentation to explicitly document how operationIds and operationRefs could be used as fragment identifiers.

@DavidBiesack
Copy link

in particular, injecting the sluggified version of the operation's tags into the anchor name ( #tag/Sluggified-Tag-Text/operation/operationId makes this harder and is not necessary. One should be able to reference the section for an operation using just the operation ID and not know the tag (and not know how ReDoc converts tag names to anchor slugs)

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

3 participants