adobe / aio-theme

The Adobe I/O theme for building markdown powered sites
Apache License 2.0
73 stars 43 forks source link

feat: request interceptor #1588

Closed melissag-ensemble closed 2 months ago

melissag-ensemble commented 2 months ago

Description

Enable adding of request interceptor to RedoclyAPIBlock

Related Issue

https://jira.corp.adobe.com/browse/DEVSITE-1190

Motivation and Context

Things I tried that didn't work:

  1. https://redocly.com/docs/developer-portal/guides/reference-docs-hooks/#steps. The RedoclyAPIBlock setup doesn't work with this.

  2. Also attempted to dynamically import the callback function, placing it in the static folder, similar to how we place open api spec in the static folder so we can access them within gatsby: <RedoclyAPIBlock src="/redocly-test/openapi/openapi.yaml" requestInterceptorSrc="/redocly-test/_override/ReferenceDocsHooks.js" />

But that resulted in the following error being thrown: Cannot find module '/redocly-test/_override/ReferenceDocsHooks.js'

It looks like this isn't supported in Gatsby yet:

So the only option left is to pass the function as a string. However, due to limitations in gatsby and markdown, the function string can't contain comments nor empty lines. This is mentioned in the readme.

How Has This Been Tested?

  1. https://github.com/AdobeDocs/redocly-test/blob/c33c1cb9ea2a38274d4c36563f3798f2bd5e5e17/src/pages/api-full/index.md?plain=1#L7-L11
  2. https://developer-stage.adobe.com/redocly-test/api-full/#operation/getInventory
  3. click Try It button
  4. enter api-key: secret-key
  5. click Send
  6. confirm status 200 and you get a response back
  7. confirm request interceptor has been invoked by checking the console log

Screenshots (if appropriate):

Untitled

Types of changes

Checklist: