Skip to content

Conversation

@tjb9dc
Copy link
Collaborator

@tjb9dc tjb9dc commented Dec 9, 2025

Description

Refs https://buildwithfern.slack.com/archives/C09NRQZ4A2X/p1765250090217619

Fixes a bug where an OpenAPI spec with the same header name (e.g., Accept) across multiple endpoints but with different schemas causes validation errors during example generation.

Root cause: When detecting global headers, the importer uses the first endpoint's schema for all endpoints. If subsequent endpoints have different schemas for the same header (e.g., one with default: 'text/event-stream' and another with const: 'application/json'), the generated examples don't match the global header's type, causing validation errors like:

Expected example to be "application/json". Example is: "text/event-stream"

Fix: When incompatible schemas are detected for the same header name across endpoints, widen the header type to string instead of using a literal type.

Changes Made

  • Added markIncompatible() and isIncompatible() methods to HeaderWithCount class to track schema incompatibility
  • Added getTypeFromHttpHeaderSchema() helper to extract type from Fern header schema for comparison
  • Added widenToString() helper to convert header schema to plain string type
  • Added logic to detect when headers with the same name have different schemas across endpoints
  • When incompatible schemas are detected, the global header type is widened to string
  • Added test fixture openapi-accept-header to reproduce the issue
  • Added JSON schema snapshots for the test fixture
  • Added Swift SDK endpoint path snapshot for the test fixture

Testing

  • Manual testing: Verified the test fixture passes fern ir without validation errors
  • Lint checks pass
  • JSON schema snapshot tests added
  • Swift SDK snapshot tests added

Human Review Checklist

  • Verify the schema comparison logic in getTypeFromHttpHeaderSchema is sufficient (currently only compares the type field from the converted Fern schema)
  • Consider if there are edge cases where widening to string loses important type information
  • Confirm the test fixture adequately covers the reported bug scenario

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

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

2 participants