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

Pass ReDoc UI Parameters using the JavaScript API instead of HTML Tags #25

Merged

Conversation

eltoder
Copy link
Contributor

@eltoder eltoder commented Jun 13, 2024

Currently passing redoc UI parameters has the following issues:

  • It puts json-ed values of parameters in single quotes, which breaks if the value itself contains single quotes.
  • If the value is falsy, only the name of the parameter is used. This syntax is not treated as falsy by redoc.

The latter causes the download button to be always hidden, because the default parameters have "hide-download-button": False. There is no way to un-hide it with the current code.

Change this to use the javascript API to pass UI parameters[1], which is much simpler and more robust.

Also, stop using the "next" version of redoc, as suggested here[2]. This was an old release candidate for version 2. Use the officially released version 2.

[1] https://redocly.com/docs/redoc/deployment/html/#the-redoc-object
[2] fastapi/fastapi#9700

Summary by Sourcery

This pull request fixes issues with passing Redoc UI parameters by using the JavaScript API and updates the Redoc version to the officially released version 2. It also includes updates to the tests to ensure the changes are correctly implemented.

  • Bug Fixes:
    • Fixed issue with passing Redoc UI parameters where JSON values were incorrectly wrapped in single quotes, causing errors if the value contained single quotes.
    • Resolved issue where falsy values for Redoc UI parameters were not correctly handled, leading to the download button being always hidden.
  • Enhancements:
    • Updated the method of passing Redoc UI parameters to use the JavaScript API for improved robustness and simplicity.
    • Replaced the usage of the 'next' version of Redoc with the officially released version 2.
  • Tests:
    • Updated tests to verify the correct version of Redoc is used and that the 'hideDownloadButton' parameter is correctly set.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed an issue where the Redoc download button configuration was not properly recognized by renaming the key to hideDownloadButton.
  • Improvements

    • Updated the Redoc CDN URL to improve stability and ensure compatibility with the latest version.
    • Enhanced the handling of UI parameters for Redoc, ensuring more reliable rendering.
  • Tests

    • Updated test cases to verify changes in Redoc configurations and ensure correct initialization of the UI.

Copy link

sourcery-ai bot commented Jun 13, 2024

Reviewer's Guide by Sourcery

This pull request addresses issues with passing ReDoc UI parameters by switching to the JavaScript API for parameter handling and updating the ReDoc version from an old release candidate to the officially released version 2. The changes ensure that parameters are passed correctly, even if they contain single quotes or falsy values, and fix the issue with the download button being always hidden.

File-Level Changes

Files Changes
src/openapipages/redoc.py
tests/test_redoc.py
Updated ReDoc version and parameter handling to use the JavaScript API, ensuring correct parameter passing and fixing the download button visibility issue.

Tips
  • Trigger a new Sourcery review by commenting @sourcery-ai review on the pull request.
  • You can change your review settings at any time by accessing your dashboard:
    • Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    • Change the review language;
  • You can always contact us if you have any questions or feedback.

Copy link

coderabbitai bot commented Jun 13, 2024

Walkthrough

The changes in the src/openapipages/redoc.py and tests/test_redoc.py files focus on enhancing the ReDoc configuration and template rendering. Key updates include renaming a configuration parameter, updating the CDN URL for Redoc, streamlining how ReDoc UI parameters are handled using json.dumps, and adjusting corresponding tests to match these modifications.

Changes

Files Change Summary
src/openapipages/redoc.py Renamed hide-download-button property, updated CDN URL, refactored parameter handling with json.dumps, and modified HTML template initialization.
tests/test_redoc.py Updated test assertions to reflect changes in CDN URL and parameter name (hideDownloadButton).

Poem

In the code of Redoc, changes bloom,
Parameters renamed, leaving no room,
The CDN now points to version two,
With json.dumps, it’s all brand new.
Tests updated, code refined,
A cleaner ReDoc, perfectly aligned.
🌸🎨💻


Tip

Early access features: enabled

We are currently testing the following features in early access:

  • OpenAI gpt-4o model for code reviews and chat: OpenAI claims that this model is better at understanding and generating code than the previous models. We seek your feedback over the next few weeks before making it generally available.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues.
  • OSS projects are currently opted into early access features by default.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @eltoder - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟡 Testing: 1 issue found
  • 🟡 Complexity: 1 issue found

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.

tests/test_redoc.py Outdated Show resolved Hide resolved
src/openapipages/redoc.py Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 0bd7fa3 and d23df94.

Files selected for processing (2)
  • src/openapipages/redoc.py (5 hunks)
  • tests/test_redoc.py (1 hunks)
Additional comments not posted (5)
tests/test_redoc.py (1)

13-14: Updated assertions correctly reflect the new Redoc version and configuration key.

src/openapipages/redoc.py (4)

22-22: Updated configuration key to camelCase aligns with JavaScript conventions.


38-38: Updated CDN URL to the official release of Redoc version 2 enhances reliability.


76-76: Using JSON serialization for UI parameters enhances robustness and flexibility.


103-111: Correctly updated HTML template to use the new configuration key and CDN URL. The script initialization is properly formatted.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d23df94 and 5a66600.

Files selected for processing (2)
  • src/openapipages/redoc.py (5 hunks)
  • tests/test_redoc.py (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • src/openapipages/redoc.py
  • tests/test_redoc.py

@eltoder
Copy link
Contributor Author

eltoder commented Jun 26, 2024

@hasansezertasan could you please take a look?

@hasansezertasan
Copy link
Owner

hasansezertasan commented Jun 26, 2024

@hasansezertasan could you please take a look?

Thank you @eltoder for your interest 🙏.

I'm bit busy lately 🤖. I will take a look at this whem I get the chance 😇

@hasansezertasan
Copy link
Owner

Hey, @eltoder 👋. Thank you for your effort and interest 🚀. I just reviewed your other PR (#24), it would be awesome if you could take a look at that and resolve the conflict on this PR 😇.

Currently passing redoc UI parameters has the following issues:
* It puts json-ed values of parameters in single quotes, which breaks if
  the value itself contains single quotes.
* If the value is falsy, only the name of the parameter is used. This
  syntax is *not* treated as falsy by redoc.

The latter causes the download button to be always hidden, because the
default parameters have "hide-download-button": False. There is no way
to un-hide it with the current code.

Change this to use the javascript API to pass UI parameters[1], which is
much simpler and more robust.

Also, stop using the "next" version of redoc, as suggested here[2]. This
was an old release candidate for version 2. Use the officially released
version 2.

[1] https://redocly.com/docs/redoc/deployment/html/#the-redoc-object
[2] fastapi/fastapi#9700
@eltoder
Copy link
Contributor Author

eltoder commented Jul 1, 2024

Hi @hasansezertasan! I resolved the conflict. Please take another look.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5a66600 and 0b508eb.

Files selected for processing (2)
  • src/openapipages/redoc.py (5 hunks)
  • tests/test_redoc.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/test_redoc.py

src/openapipages/redoc.py Show resolved Hide resolved
src/openapipages/redoc.py Show resolved Hide resolved
@hasansezertasan
Copy link
Owner

Hi @hasansezertasan! I resolved the conflict. Please take another look.

I'll take a look at it when I get the chance. Thank you for the effort 🙏.

@hasansezertasan hasansezertasan changed the title Fix passing redoc UI parameters Pass ReDoc UI Parameters using the JavaScript API instead of HTML Tags Jul 22, 2024
Copy link
Owner

@hasansezertasan hasansezertasan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @eltoder 🎉🎉🎉

@hasansezertasan hasansezertasan merged commit 45257de into hasansezertasan:main Jul 22, 2024
17 checks passed
@eltoder eltoder deleted the feature/redoc-ui-params branch July 22, 2024 23:36
@hasansezertasan hasansezertasan added this to the 0.1.2 milestone Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants