Skip to content

Conversation

@kennyderek
Copy link
Contributor

@kennyderek kennyderek commented Dec 9, 2025

Description

Fixes an issue where AI-generated examples would override human-specified examples in OpenAPI specs. When users provide explicit examples in their OpenAPI specification, those should take precedence over AI-enhanced examples.

Changes Made

  • Added hasUserSpecifiedV2Examples() function to detect when an endpoint already has human-specified examples in the v2Examples structure
  • Modified collectWorkItems() to skip endpoints that have human-specified examples, preventing AI enhancement from overriding them
  • Added biome-ignore comments for necessary any casts when accessing v2Examples properties not in the type definition
  • Added comprehensive tests for AI examples behavior including:
    • Basic AI examples issue reproduction
    • Autogenerated examples analysis
    • Mixed examples conflict scenarios (human + AI)
    • Human example validation tests
  • Updated README.md generator (if applicable)

Updates Since Last Revision

  • Removed schema-change-test fixture directory and its related test/snapshots as requested

Testing

  • Unit tests added/updated
  • Manual testing completed
  • CI passing

Human Review Checklist

  • Verify hasUserSpecifiedV2Examples() correctly identifies all cases of human-specified examples (checks both v2Examples.userSpecifiedExamples and v2Responses.responses[].body.v2Examples.userSpecifiedExamples)
  • Confirm the fix doesn't accidentally skip endpoints that should be AI-enhanced (only skips when human examples exist)
  • Review the as any casts - these are necessary because v2Examples properties aren't in the EndpointV3 type definition

Link to Devin run: https://app.devin.ai/sessions/8e40cb0c83ce40558d484a30b606d10c
Requested by: [email protected] ([email protected])

kennyderek and others added 7 commits December 9, 2025 16:35
…I examples

The AI example enhancement system was incorrectly processing endpoints that already had
human-provided OpenAPI examples, potentially overriding carefully crafted examples.

**Root Cause:**
- System creates both human examples (in v2Examples.userSpecifiedExamples) and autogenerated
  examples (with generic placeholders) for the same endpoint
- AI enhancement collection only checked for autogenerated examples without verifying
  if human examples already existed
- Generic placeholder values triggered AI processing even when human examples were present

**Solution:**
- Enhanced collectWorkItems() to check for existing human examples before AI processing
- Added hasUserSpecifiedV2Examples() helper to detect user examples in v2Examples structures
- Skip endpoints that already have human-specified examples
- Only process endpoints with purely autogenerated examples

**Testing:**
- Added comprehensive test suite with 3 scenarios:
  1. Human examples protection (ai-examples-issue)
  2. Autogenerated examples processing (autogen-examples-test)
  3. Conflict resolution when both AI overrides and human examples exist (mixed-examples-test)
- All tests validate proper precedence: Human examples > AI overrides > Autogenerated examples

**Impact:**
- ✅ Protects human OpenAPI examples from being overridden
- ✅ Maintains AI enhancement for purely autogenerated endpoints
- ✅ Backward compatible with existing behavior
- ✅ Proper conflict resolution between AI overrides and human examples

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4 <[email protected]>
…n and human example validation

Added test fixtures and cases to identify two critical issues with example handling:

1. **AI Examples Schema Drift**: AI-generated examples in ai_examples_override.yml become
   stale when OpenAPI schemas change. Examples may contain removed properties or miss new
   required properties.

2. **No Human Example Validation**: Discovered that Fern doesn't validate human-provided
   OpenAPI examples against current schemas. Invalid properties are preserved in IR.

**New Test Cases:**
- `schema-change-test`: Demonstrates AI examples with outdated schema properties
- `invalid-human-example-test`: Tests whether human examples are validated against schemas
- Enhanced existing test with comprehensive conflict analysis

**Key Findings:**
- AI examples don't auto-update with schema changes
- Human examples with invalid properties pass through unvalidated
- System needs universal example validation mechanism

**Test Results Show:**
- Schema mismatch detection working for identifying the problem
- Both human and AI examples need validation improvements
- Foundation for implementing universal example schema validation

These tests provide the baseline for implementing comprehensive example validation
and auto-refresh capabilities in future PRs.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4 <[email protected]>
@devin-ai-integration devin-ai-integration bot changed the title chore(cli): add tests for ai overrides fix(cli): prevent AI examples from overriding human-specified OpenAPI examples Dec 9, 2025
@kennyderek kennyderek enabled auto-merge (squash) December 10, 2025 22:19
@kennyderek kennyderek merged commit 5b2f33f into main Dec 10, 2025
100 checks passed
@kennyderek kennyderek deleted the fix/ai-examples-human-override-issue branch December 10, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants