api_openai 0.3.0

OpenAI's API for accessing large language models (LLMs).
Documentation
# Clippy Configuration Documentation

This document describes the custom clippy configuration for the `api_openai` crate and its rationale.

## Overview

The `clippy.toml` file defines project-specific clippy rules that extend the workspace-level configuration. These rules are specifically tailored for an API client library that needs to balance code quality, maintainability, and API integration requirements.

## Configuration File Location

- **File**: `clippy.toml` (in the crate root)
- **Scope**: Applies to the `api_openai` crate only
- **Priority**: Overrides workspace-level clippy configuration where conflicts exist

## Rule Categories

### 1. Project-Specific Quality Rules

```toml
enum-variant-names-threshold = 3
struct-excessive-bools = 3
too-many-arguments = 7
too-many-lines = 150
```

**Rationale**: API clients often need complex structures to represent API responses accurately. These limits are set to be more permissive than defaults while still maintaining code quality.

### 2. Error Handling Rules

```toml
missing-errors-doc = "warn"
missing-panics-doc = "warn"
```

**Rationale**: API client libraries must have comprehensive error documentation since users need to understand when and why operations might fail.

### 3. Documentation Rules

```toml
missing-docs-in-private-items = "warn"
doc-markdown = "warn"
```

**Rationale**: API clients are primarily used by external developers, so comprehensive documentation is critical for adoption and proper usage.

### 4. Performance Rules

```toml
unnecessary-wraps = "warn"
redundant-clone = "warn"
needless-collect = "warn"
string-add = "warn"
string-add-assign = "warn"
```

**Rationale**: API clients perform network operations and data serialization frequently, making performance optimizations important.

### 5. Security Rules

```toml
print-stdout = "warn"
print-stderr = "warn"
dbg-macro = "warn"
```

**Rationale**: API clients handle sensitive data like API keys. Accidental logging of sensitive information must be prevented.

## Allowed Patterns

The configuration allows certain patterns that are necessary or common in API client development:

### Large Enum Variants
```toml
large-enum-variant = "allow"
```
API response structures can be large and complex, matching the external API schema.

### Complex Types
```toml
type-complexity = "allow"
```
API clients often need complex generic types to provide type-safe interfaces.

### Many Arguments
```toml
too-many-arguments = "allow"
```
Builder patterns and comprehensive API methods may require many parameters.

### Cognitive Complexity
```toml
cognitive-complexity = "allow"
```
Comprehensive API handling logic can be complex but necessary for proper error handling and response processing.

## Usage Instructions

### Running Clippy with Custom Configuration

1. **From workspace root:**
   ```bash
   cd /path/to/workspace
   cargo clippy --package api_openai --all-targets -- -D warnings
   ```

2. **From crate directory:**
   ```bash
   cd api/openai
   cargo clippy --all-targets -- -D warnings
   ```

3. **With specific config file (if needed):**
   ```bash
   cargo clippy --all-targets -- -D warnings --config-file clippy.toml
   ```

### Integration with CI/CD

Add to your CI/CD pipeline:

```yaml
# Example GitHub Actions step
- name: Run Clippy
  run: |
    cd api/openai
    cargo clippy --all-targets -- -D warnings
```

### Development Workflow

1. **Before committing:**
   ```bash
   cargo clippy --all-targets --fix -- -D warnings
   ```

2. **For comprehensive checking:**
   ```bash
   cargo clippy --all-targets --all-features -- -D warnings
   ```

## Maintenance

### Adding New Rules

When adding new clippy rules:

1. Consider the API client context
2. Test against existing codebase
3. Document the rationale
4. Update this documentation

### Rule Conflicts

If workspace and project rules conflict:
- Project-specific rules take precedence
- Document any overrides in this file
- Consider if workspace rules should be updated instead

### Regular Review

Review the configuration periodically:
- When clippy releases new lints
- After major codebase refactoring
- When API patterns change
- Based on team feedback

## Troubleshooting

### Common Issues

1. **Configuration not loading:**
   - Ensure `clippy.toml` is in the crate root
   - Check file permissions
   - Verify TOML syntax

2. **Rule conflicts:**
   - Project rules override workspace rules
   - Check for typos in rule names
   - Verify rule priority settings

3. **False positives:**
   - Use `#[ allow( clippy::rule_name ) ]` for specific cases
   - Consider updating the configuration
   - Document exceptions

### Getting Help

- Check clippy documentation: https://doc.rust-lang.org/clippy/
- Review available lints: `cargo clippy --help`
- Test specific rules: `cargo clippy -- -W clippy::rule_name`

## Examples

### Allowing Specific Patterns in Code

```rust
// Allow complex API response structures
#[ allow( clippy::large_enum_variant ) ]
pub enum ApiResponse {
    Success(LargeSuccessResponse),
    Error(ErrorResponse),
}

// Allow many arguments for comprehensive API methods
#[ allow( clippy::too_many_arguments ) ]
pub fn create_complex_request(
    model: String,
    messages: Vec<Message>,
    temperature: f32,
    max_tokens: Option<u32>,
    // ... more parameters as needed
) -> Request {
    // Implementation
}
```

### Configuration Testing

```bash
# Test specific rule
cargo clippy -- -W clippy::missing_errors_doc

# Test all custom rules
cargo clippy --all-targets -- -D warnings

# Check rule explanations
cargo clippy -- -W help
```

This configuration ensures consistent code quality while accommodating the specific requirements of an API client library.