docusaurus-openapi-docs icon indicating copy to clipboard operation
docusaurus-openapi-docs copied to clipboard

[FR] Relative urls for `downloadUrl`

Open jasikpark opened this issue 2 years ago • 5 comments

Describe the bug

Passing "/openapi.yaml" to the downloadUrl config value fails to generate a download link, it'd be great to update the isUrl() function to accept relative urls..

https://github.com/PaloAltoNetworks/docusaurus-openapi-docs/blob/7c7db724055db181c672c8d265daa86a4ee91350/packages/docusaurus-plugin-openapi-docs/src/index.ts#L22

Expected behavior

I would like the download link to work in development, rather than just passing a full url

Current behavior

downloadUrl only accepts fully qualified urls

Possible solution

Loosen the isUrl() function to accept urls, or allow changing the url behavior in dev v.s. in prod

Steps to reproduce

  1. pass downloadUrl to an api config in docusaurus && fail to receive a download link in the UI.
  2. I can confirm that I get a download link if I set a fully qualified url in that config value.

jasikpark avatar Feb 13 '23 18:02 jasikpark

:tada: Thanks for opening your first issue here! Welcome to the community!

Hi @jasikpark, this feature is currently not supported but you are welcome to convert this issue into a feature request by adding "[FR]" to the title and changing the label to "enhancement". Thanks!

sserrata avatar Feb 17 '23 15:02 sserrata

don't think I have perms for changing labels, but i've updated the title

jasikpark avatar Feb 17 '23 15:02 jasikpark

The downloadUrl should also support relative URL's that are pointing @site/ files. Current solution is only viable for final deploy.

drejc avatar May 31 '23 08:05 drejc

A good enough workaround that I'm using:

diff --git a/packages/docusaurus-plugin-openapi-docs/src/index.ts b/packages/docusaurus-plugin-openapi-docs/src/index.ts
index 6f7c488..a7a18c6 100644
--- a/packages/docusaurus-plugin-openapi-docs/src/index.ts
+++ b/packages/docusaurus-plugin-openapi-docs/src/index.ts
@@ -311,7 +311,7 @@ custom_edit_url: null
 
       loadedApi.map(async (item) => {
         if (item.type === "info") {
-          if (downloadUrl && isURL(downloadUrl)) {
+          if (downloadUrl) {
             item.downloadUrl = downloadUrl;
           }
         }

Would love not to have to patch the package, though.

Ugzuzg avatar Apr 19 '24 08:04 Ugzuzg

adding to roadmap with goal of supporting relative URL paths

sserrata avatar Jun 28 '24 20:06 sserrata