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

fix: swagger documentation authentication #1037

Merged
merged 3 commits into from
Apr 15, 2024
Merged

Conversation

catalinpit
Copy link
Contributor

@catalinpit catalinpit commented Mar 19, 2024

Summary by CodeRabbit

  • Refactor
    • Enhanced the API specification generation process to include operation IDs, security schemes, and security definitions more efficiently.

Copy link
Contributor

coderabbitai bot commented Mar 19, 2024

Walkthrough

The recent update enhances the OpenAPIV1 export functionality within the openapi.ts file. It introduces the use of Object.assign to seamlessly integrate additional configurations into the generated OpenAPI specification. This enhancement facilitates the customization of operation IDs, security schemes, and security definitions according to the ApiContractV1, streamlining the process of generating more detailed and tailored API documentation.

Changes

File(s) Change Summary
packages/api/v1/openapi.ts Enhanced OpenAPIV1 export to use Object.assign for adding custom operation IDs, security schemes, and security definitions based on ApiContractV1.

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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

vercel bot commented Mar 19, 2024

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

Name Status Preview Comments Updated (UTC)
stg-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 6:31am
stg-marketing ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 15, 2024 6:31am
2 Ignored Deployments
Name Status Preview Comments Updated (UTC)
prd-app ⬜️ Ignored (Inspect) Apr 15, 2024 6:31am
prd-marketing ⬜️ Ignored (Inspect) Apr 15, 2024 6:31am

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e7071f1 and 2b9882c.
Files selected for processing (1)
  • packages/api/v1/openapi.ts (1 hunks)
Additional comments: 1
packages/api/v1/openapi.ts (1)
  • 5-33: The use of Object.assign to merge configurations for the OpenAPI specification is a good approach for enhancing flexibility and maintainability. However, there are a few considerations and improvements to be made:
  1. Security Schemes and Definitions: The addition of security schemes is crucial for API documentation, especially for APIs that require authentication. The configuration provided for the authorization security scheme is well-defined, specifying it as an apiKey type in the header. This is a common and recommended practice for APIs requiring a simple API key for authentication.

  2. Operation IDs: Setting setOperationId: true is a good practice as it helps in generating more readable and accessible API documentation. It ensures that each operation in the API documentation has a unique identifier, which can be beneficial for generating client SDKs or for documentation purposes.

  3. Documentation Completeness and Accuracy: Ensure that the security definitions and other configurations accurately reflect the API's authentication mechanisms. It's important that the documentation provides clear and precise information on how to authenticate API requests to prevent confusion and errors.

  4. Maintainability: While Object.assign is used effectively here, consider the future scalability of your OpenAPI specification. As your API grows, you might find it beneficial to adopt a more structured approach to managing your OpenAPI configuration, such as modularizing different parts of the specification or using a library designed for building OpenAPI specifications in a more declarative way.

  5. Validation and Testing: It's not visible in the provided code, but ensure that the generated OpenAPI specification is validated against the OpenAPI standard. Tools like Swagger Editor or Swagger UI can be used to validate and visually inspect the API documentation. Additionally, consider adding automated tests to verify that the OpenAPI specification remains valid and accurate as the API evolves.

Overall, the changes made to the OpenAPI documentation are a step in the right direction for improving the developer experience by providing clearer and more detailed authentication documentation.

@Mythie
Copy link
Collaborator

Mythie commented Mar 21, 2024

This seems to have mostly solved the issue but now we use the authorization value from the top of the swagger ui and ignore the ones passed in the "try it out" section despite it being marked as required.

Not sure how to solve but we should try just a little bit extra to see if we can make this just a tiny bit smoother.

@catalinpit
Copy link
Contributor Author

This seems to have mostly solved the issue but now we use the authorization value from the top of the swagger ui and ignore the ones passed in the "try it out" section despite it being marked as required.

Not sure how to solve but we should try just a little bit extra to see if we can make this just a tiny bit smoother.

Yeah... I realised that, but I couldn't think of a better solution. I can remove the authorization param from the "Try it out" section, but I don't think that's a good solution. This way, it might be confusing to users. Similarly, I can make it non-required, but again, I don't think it's a good idea.

Will think of a better solution.

@dguyen dguyen merged commit 0f87dc0 into main Apr 15, 2024
13 checks passed
@dguyen dguyen deleted the fix/swagger-documentation-auth branch April 15, 2024 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants