Skip to content

Test and Update API Client Module #126

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

Draft
wants to merge 114 commits into
base: develop
Choose a base branch
from

Conversation

codegen-sh[bot]
Copy link

@codegen-sh codegen-sh bot commented May 17, 2025

Overview

This PR implements comprehensive tests and updates for the API Client module as part of the ZAM-411 issue.

Changes

  1. Added Comprehensive Test Suite:

    • Unit tests for the OpenAPI client components (API implementations, models, configuration, exceptions, etc.)
    • Unit tests for the CLI API client
    • Integration tests for the API client module
  2. Improved Configuration:

    • Added support for reading API key from environment variables
    • Updated default host URL to use HTTPS
    • Enhanced error handling for API key management
    • Added better documentation for configuration options
  3. Added Documentation:

    • Created README.md for the OpenAPI client module
    • Created README.md for the CLI API client module
    • Added detailed documentation for authentication, API operations, error handling, and customization
  4. Fixed Issues:

    • Fixed authentication handling in the Configuration class
    • Improved error handling in the API client
    • Enhanced API versioning support

Testing

The PR includes a comprehensive test suite that covers:

  • API client interfaces and implementation
  • Request formatting and validation
  • Authentication and authorization flow
  • Response parsing and error handling
  • API versioning support

Related Issues


💻 View my workAbout Codegen

Note

I'm currently writing a description for your pull request. I should be done shortly (<1 minute). Please don't edit the description field until I'm finished, or we may overwrite each other. If I find nothing to write about, I'll delete this message.

Summary by Sourcery

Add extensive test coverage for both OpenAPI and CLI API client modules and update the API client configuration to use secure defaults and environment-based API key management

New Features:

  • Support reading API key from the CODEGEN_API_KEY environment variable in the Configuration class

Bug Fixes:

  • Correct default host URL to use HTTPS instead of HTTP
  • Fix authentication handling and return value in get_api_key_with_prefix

Enhancements:

  • Improve error handling for API key management and network errors
  • Include host information in the debug report
  • Enhance API versioning support and default host settings

Build:

  • Update package.json to specify the packageManager and format release branch configuration

Documentation:

  • Add user-facing README.md documentation for the OpenAPI client module
  • Add user-facing README.md documentation for the CLI API client module

Tests:

  • Add comprehensive unit tests for OpenAPI client models, configuration, REST client, and generated API implementations
  • Add comprehensive unit tests for CLI API client, including schemas, endpoints, and error handling
  • Add integration tests covering Agents, Organizations, Users APIs and end-to-end CLI API client workflows

clee-codegen and others added 30 commits February 26, 2025 23:54
# Motivation

The **Codegen on OSS** package provides a pipeline that:

- **Collects repository URLs** from different sources (e.g., CSV files
or GitHub searches).
- **Parses repositories** using the codegen tool.
- **Profiles performance** and logs metrics for each parsing run.
- **Logs errors** to help pinpoint parsing failures or performance
bottlenecks.

<!-- Why is this change necessary? -->

# Content

<!-- Please include a summary of the change -->
see
[codegen-on-oss/README.md](https://github.com/codegen-sh/codegen-sdk/blob/acfe3dc07b65670af33b977fa1e7bc8627fd714e/codegen-on-oss/README.md)

# Testing

<!-- How was the change tested? -->
`uv run modal run modal_run.py`
No unit tests yet 😿 

# Please check the following before marking your PR as ready for review

- [ ] I have added tests for my changes
- [x] I have updated the documentation or added new documentation as
needed
Original commit by Tawsif Kamal: Revert "Revert "Adding Schema for Tool Outputs"" (codegen-sh#894)

Reverts codegen-sh#892

---------

Co-authored-by: Rushil Patel <[email protected]>
Co-authored-by: rushilpatel0 <[email protected]>
Original commit by Ellen Agarwal: fix: Workaround for relace not adding newlines (codegen-sh#907)
Copy link

korbit-ai bot commented May 17, 2025

By default, I don't review pull requests opened by bots. If you would like me to review this pull request anyway, you can request a review via the /korbit-review command in a comment.

Copy link

sourcery-ai bot commented May 17, 2025

Reviewer's Guide

This PR expands the API client modules with a full test harness, hardens configuration by switching to HTTPS and environment‐driven API keys while improving auth and error handling, adds usage documentation for both the CLI and OpenAPI clients, and updates package.json for release management.

Sequence Diagram: Retrieving Authentication Settings for API Calls

sequenceDiagram
    title Sequence Diagram: Retrieving Authentication Settings for API Calls
    participant ApiClient as API Client Component
    participant ConfigInstance as Configuration Instance

    ApiClient->>ConfigInstance: auth_settings()
    activate ConfigInstance
    alt "Authorization" key exists in ConfigInstance.api_key
        ConfigInstance->>ConfigInstance: get_api_key_with_prefix("Authorization")
        activate ConfigInstance
        Note right of ConfigInstance: Returns "Bearer <key_value>" if key_value is non-empty, <br/>"Bearer " if key_value is empty, <br/>or "" if 'Authorization' key is missing in api_key_prefix.
        ConfigInstance-->>ConfigInstance: prefixed_api_key
        deactivate ConfigInstance
        ConfigInstance->>ConfigInstance: Create AuthSettings entry for "Authorization" using prefixed_api_key
    else "Authorization" key does not exist in ConfigInstance.api_key
        Note over ConfigInstance: No "Authorization" entry added to AuthSettings dictionary by this check.
    end
    ConfigInstance-->>ApiClient: auth_settings_dict
    deactivate ConfigInstance
Loading

File-Level Changes

Change Details Files
Added comprehensive test coverage for both CLI and OpenAPI clients
  • Unit tests for OpenAPI models and REST module
  • Unit tests for CLI client methods, schemas, and endpoints
  • Integration tests for end-to-end API client flows
tests/unit/codegen/cli/api/test_client.py
tests/unit/codegen/cli/api/test_schemas.py
tests/unit/codegen/cli/api/test_endpoints.py
tests/unit/codegen/agents/client/openapi_client/models/test_models.py
tests/unit/codegen/agents/client/openapi_client/api/test_users_api.py
tests/unit/codegen/agents/client/openapi_client/api/test_organizations_api.py
tests/unit/codegen/agents/client/openapi_client/api/test_agents_api.py
tests/unit/codegen/agents/client/openapi_client/test_configuration.py
tests/unit/codegen/agents/client/openapi_client/test_rest.py
tests/unit/codegen/agents/client/openapi_client/test_api_response.py
tests/unit/codegen/agents/client/openapi_client/test_exceptions.py
tests/integration/codegen/api/test_api_client_integration.py
Enhanced configuration to support HTTPS and environment-based API keys
  • Switched default host URL to HTTPS
  • Read CODEGEN_API_KEY env var into api_key with Bearer prefix
  • Changed get_api_key_with_prefix to return empty string instead of None
  • Injected Authorization header in auth_settings
  • Included host in debug report
  • Refined host settings defaults
src/codegen/agents/client/openapi_client/configuration.py
Added user-facing documentation for both client modules
  • Created README for CLI API client
  • Created README for OpenAPI client module
src/codegen/cli/api/README.md
src/codegen/agents/client/openapi_client/README.md
Updated release configuration in package.json
  • Normalized release.branches array formatting
  • Added packageManager field
package.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

coderabbitai bot commented May 17, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Join our Discord community for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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
Author

codegen-sh bot commented May 17, 2025

I see a check failed - I'm on it! 🫡

💻 View my work

Copy link
Author

codegen-sh bot commented May 17, 2025

✅ Fixed the failing mypy checks in PR #126. The issue was in the configuration.py file where there was an unterminated string literal and several type annotation issues. I also had to update the agent.py file to match the changes in the Configuration class.

The main fixes included:

  1. Fixed an unterminated string literal in configuration.py (missing closing quote)
  2. Updated the return type of get_api_key_with_prefix to return an empty string instead of None
  3. Added environment variable support for the API key
  4. Updated the default host URL to use HTTPS
  5. Updated the Agent class to use the new Configuration API

I've pushed these changes to the PR branch. The mypy checks should now pass.

View the commit

💻 View my work • React 👍 or 👎

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