Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix: issues in api request viewer #1257
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
base: main
Are you sure you want to change the base?
Uh oh!
There was an error while loading. Please reload this page.
fix: issues in api request viewer #1257
Changes from all commits
1765fa0c84a1e4d0aefba0d028d2File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generated
curlcommands are malformed for common inputs (no URL-encoding, unsafe single-quote body wrapping).Three concrete defects in the new CURL branch will cause users who copy-paste the snippet to hit broken requests:
url.split(\{${k}}`).join(v)substitutes raw values, so anyvcontaining/,:,?,#`, space, etc. produces a malformed URL.${k}=${v}will silently break for values containing&,=,#,+, or spaces.-d '${JSON.stringify(body, null, 2)}'— if any JSON string value contains a single quote (e.g. a user name likeO'Brien), the shell single-quote string is terminated early and the resulting command is invalid. This is realistic for example data shown in docs.🛠️ Proposed fix
case SupportedLanguage.CURL: { let url = `$FGA_API_URL${path}`; if (pathParams) { for (const [k, v] of Object.entries(pathParams)) { - url = url.split(`{${k}}`).join(v); + url = url.split(`{${k}}`).join(encodeURIComponent(v)); } } if (queryParams && Object.keys(queryParams).length > 0) { const qs = Object.entries(queryParams) - .map(([k, v]) => `${k}=${v}`) + .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`) .join('&'); url += `?${qs}`; } let code = `curl -X ${method} '${url}' \\\n`; code += ` -H 'Content-Type: application/json' \\\n`; code += ` -H 'Authorization: Bearer $FGA_BEARER_TOKEN'`; if (body) { - code += ` \\\n -d '${JSON.stringify(body, null, 2)}'`; + // Escape single quotes so the shell-quoted -d body survives apostrophes in example data. + const json = JSON.stringify(body, null, 2).replace(/'/g, `'\\''`); + code += ` \\\n -d '${json}'`; } if (responseExample) { code += `\n\n# Response: ${responseExample}`; } return code; }📝 Committable suggestion
🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
curl streaming response no-buffer flag -N documentation💡 Result:
The -N or --no-buffer flag in curl disables output buffering, enabling real-time streaming of responses as data arrives, rather than in buffered chunks. This is particularly useful for streaming responses like Server-Sent Events (SSE), live updates, or piping to other commands without delays. From the official curl manual: "-N, --no-buffer: Disables the buffering of the output stream. In normal work situations, curl will use a standard buffered output stream that will have the effect that it will output the data in chunks, not necessarily exactly when the data arrives. Using this option will disable that buffering. Note that this is the negated option name documented. You can thus use --buffer to enforce the buffering."[1][2][3][4] Example usage for streaming: curl -N https://example.com/stream-endpoint[5][6] This flag affects stdout output and is key for progressive display or processing of long-running responses.[7][8]
Citations:
🏁 Script executed:
Repository: openfga/openfga.dev
Length of output: 125
🏁 Script executed:
Repository: openfga/openfga.dev
Length of output: 129
🏁 Script executed:
Repository: openfga/openfga.dev
Length of output: 3216
🏁 Script executed:
Repository: openfga/openfga.dev
Length of output: 3751
🏁 Script executed:
Repository: openfga/openfga.dev
Length of output: 609
Add
-Nflag and fix quote escaping in streaming CURL, plus handle missingresponseExamplecomment.The streaming CURL output has two issues:
Missing
-N/--no-bufferflag. Streaming endpoints require this flag to disable output buffering, otherwise users copying the command won't observe streaming behavior in real-time. Add-Nimmediately aftercurl.Inconsistent responseExample handling. The non-streaming CURL case (lines 271–304) includes
if (responseExample)to emit a# Response:comment, but the streaming case omits this block entirely. This leaves theresponseExamplefield silently unused in the streaming function's public API.Additionally, both cases need quote escaping for the JSON body (use
.replace(/'/g, "'\\''")when embedding in single-quoted shell strings), consistent with best practices for shell safety.🛠️ Proposed fix
case SupportedLanguage.CURL: { let url = `$FGA_API_URL${path}`; if (pathParams) { for (const [k, v] of Object.entries(pathParams)) { url = url.split(`{${k}}`).join(v); } } if (queryParams && Object.keys(queryParams).length > 0) { const qs = Object.entries(queryParams) .map(([k, v]) => `${k}=${v}`) .join('&'); url += `?${qs}`; } - let code = `curl -X ${method} '${url}' \\\n`; + let code = `curl -N -X ${method} '${url}' \\\n`; code += ` -H 'Content-Type: application/json' \\\n`; code += ` -H 'Authorization: Bearer $FGA_BEARER_TOKEN'`; if (body) { - code += ` \\\n -d '${JSON.stringify(body, null, 2)}'`; + const json = JSON.stringify(body, null, 2).replace(/'/g, `'\\''`); + code += ` \\\n -d '${json}'`; + } + if (responseExample) { + code += `\n\n# Response: ${responseExample}`; } return code; }Consider extracting the duplicated CURL builder logic (lines 271–304 and 465–490 are nearly identical) into a helper function that accepts a
streaming: booleanparameter. This would eliminate ~20 lines of duplication and ensure encoding/streaming fixes are applied consistently in one place.🤖 Prompt for AI Agents
Uh oh!
There was an error while loading. Please reload this page.