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

docs: add link to Hono OpenAPI description for Mintlify to render as HTML link #2650

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

unrenamed
Copy link
Contributor

@unrenamed unrenamed commented Nov 6, 2024

What does this PR do?

This PR adds a link to the Hono OpenAPI POST /v1/keys.createKey description in the documentation, configured so that Mintlify will render it as an HTML link. This enhances accessibility to the API details directly from our docs.

Fixes #2573

⚠️ To ensure this change effectively updates the Unkey Docs, consider the following steps:

  1. Re-build and deploy the OpenAPI configuration to https://api.unkey.dev/openapi.json.
  2. After that, re-generate the openapi.d.ts file in packages/api and commit it to the repo.
  3. Finally, generate and deploy the Unkey Docs with Mintlify.

Following these steps should keep the documentation in sync with the latest OpenAPI configuration.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Chore (refactoring code, technical debt, workflow improvements)
  • Enhancement (small improvements)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • If a UI change was made: Added a screen recording or screenshots to this PR
  • Updated the Unkey Docs if changes were necessary

Summary by CodeRabbit

  • New Features

    • Introduced a new externalId field in the key creation process, enhancing customer record linkage.
  • Bug Fixes

    • Improved error handling for remaining and refill parameters to prevent invalid submissions.
  • Documentation

    • Updated API documentation to reflect changes in request and response schemas for clarity.

Copy link
Contributor

coderabbitai bot commented Nov 6, 2024

📝 Walkthrough

Walkthrough

The pull request modifies the createKey route in the v1_keys_createKey.ts file by replacing the deprecated ownerId field with a new externalId field. It updates error handling for the remaining and refill parameters, ensuring proper validation conditions. The response schema is also revised to align with these changes, maintaining consistency in the API documentation. Overall, the control flow remains unchanged, but the adjustments improve the clarity and functionality of the key creation process.

Changes

File Path Change Summary
apps/api/src/routes/v1_keys_createKey.ts - Replaced ownerId with externalId in request schema.
- Updated error handling for remaining and refill parameters.
- Revised response schema for consistency with request changes.

Assessment against linked issues

Objective Addressed Explanation
Clickable link to key recovery documentation (#2573) The PR does not address the documentation issue.

Possibly related PRs

Suggested reviewers

  • mcstepp
  • perkinsjr
  • chronark

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

vercel bot commented Nov 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 6, 2024 11:50pm

Copy link

vercel bot commented Nov 6, 2024

@unrenamed is attempting to deploy a commit to the Unkey Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

github-actions bot commented Nov 6, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@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

🧹 Outside diff range and nitpick comments (1)
apps/api/src/routes/v1_keys_createKey.ts (1)

Line range hint 385-385: Good backward compatibility for identity handling

The code gracefully handles the transition from ownerId to externalId by supporting both fields during the deprecation period.

Consider adding a deprecation warning in logs when ownerId is used to help track usage:

-    const externalId = req.externalId ?? req.ownerId;
+    const externalId = req.externalId ?? req.ownerId;
+    if (req.ownerId) {
+      logger.warn("deprecated_field_used", { 
+        field: "ownerId",
+        suggestion: "Use externalId instead"
+      });
+    }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between bc981d3 and ea7eca9.

📒 Files selected for processing (1)
  • apps/api/src/routes/v1_keys_createKey.ts (1 hunks)
🔇 Additional comments (3)
apps/api/src/routes/v1_keys_createKey.ts (3)

208-208: LGTM: Documentation link properly formatted

The URL has been correctly formatted as a markdown link, which will render as a clickable HTML link in Mintlify documentation.


Line range hint 326-344: Error handling improvements for refill parameters

The added validations prevent invalid parameter combinations:

  1. Prevents setting remaining to 0
  2. Ensures remaining is set when using refill
  3. Validates refillDay compatibility with daily interval

The error messages are clear and helpful for API users.


Line range hint 52-71: Field transition handled appropriately

The deprecation of ownerId and introduction of externalId is well documented:

  • Clear deprecation notice
  • Comprehensive documentation for the new field
  • Maintains backward compatibility

Let's verify the usage of these fields in the codebase:

✅ Verification successful

Let me analyze the usage of ownerId to verify if there are any concerns with its deprecation. I'll need to check the actual implementation of the field transition.


Based on the analysis of the codebase, I can now generate the final response regarding the field transition from ownerId to externalId.

Field transition is well-implemented and properly documented

The deprecation of ownerId and introduction of externalId is handled correctly throughout the codebase:

  • The deprecated ownerId field is properly marked with OpenAPI documentation directing users to use externalId
  • The code maintains backward compatibility by supporting both fields: externalId = req.externalId ?? req.ownerId
  • The transition is consistently implemented across all relevant endpoints (create, update, verify, etc.)
  • Comprehensive test coverage exists for both the old and new fields
  • The schema and database operations properly handle the transition with appropriate indexes and constraints
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining direct usage of ownerId that might need updating
rg "ownerId" --type ts

Length of output: 16616


Script:

#!/bin/bash
# Check how externalId is used in relation to ownerId
rg "externalId" --type ts -A 2 -B 2

Length of output: 79869

@harshsbhat
Copy link
Contributor

I did try this, but I missed this step, which is why the changes were not displayed on the documents. Nice work!

After that, re-generate the openapi.d.ts file in packages/api and commit it to the repo.

@chronark chronark merged commit f14de0e into unkeyed:main Nov 7, 2024
6 of 10 checks passed
@unrenamed
Copy link
Contributor Author

unrenamed commented Nov 7, 2024

@harshsbhat Just FYI, the first step is necessary to apply the changes because Mintlify OpenAPI docs rely on https://api.unkey.dev/openapi.json as per mint.json. To see changes locally, you'll need to create your own openapi.json and update mint.json.

Re-generating openapi.d.ts doesn’t affect the Mintlify docs, as far as I'm concerned. Yet, it's a required step to keep the types and OpenAPI up-to-date, which is why it comes after this PR is merged and deployed. Hope this clarifies any confusion!

Re-build and deploy the OpenAPI configuration to https://api.unkey.dev/openapi.json.

@harshsbhat
Copy link
Contributor

@unrenamed Thanks for clarification

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing Link to Key Recovery Documentation in API Reference
3 participants