Skip to content

Conversation

@zebapy
Copy link
Member

@zebapy zebapy commented Nov 25, 2025

Summary

This PR adds support for filtering OpenAPI specifications by audience using the x-openapi-interfaces-audience extension, similar to Fern's x-fern-audiences feature.

Features

CLI Arguments

  • --audience <name>: Filter by one or more audiences (can be specified multiple times)
  • --audience-mode <include|exclude>: Control filtering mode (defaults to "include")

Supported Levels

  • Operations/Endpoints: Tag entire HTTP operations with audiences
  • Schema Properties: Tag individual fields within interface members with audiences

Filtering Behavior

  • Items without an audience tag are treated as public/default and always included
  • Include mode: Only items with matching audiences (plus public items) are included
  • Exclude mode: Items with matching audiences are excluded (public items remain)

Usage Examples

# Include only beta features (plus public features)
openapi-interfaces api.yml -o api_beta.yml --audience beta

# Exclude internal features
openapi-interfaces api.yml -o api_public.yml --audience internal --audience-mode exclude

# Include multiple audiences
openapi-interfaces api.yml -o api.yml --audience beta --audience internal

Example YAML

paths:
  /beta-endpoint:
    get:
      x-openapi-interfaces-audience: ["beta"]
      responses:
        200:
          description: Beta endpoint

components:
  interfaces:
    Widget:
      members:
        publicField:
          schema:
            type: string
        betaField:
          schema:
            type: string
            x-openapi-interfaces-audience: ["beta"]

Implementation Details

  • Extended Scope struct with audience filtering configuration
  • Added AudienceFilterMode enum for include/exclude control
  • Filter operations during OpenApi transpilation
  • Filter interface members during Interface transpilation
  • Filter schema properties during PrimitiveSchema transpilation
  • Maintain consistency of required fields when filtering properties

Testing

  • ✅ All existing tests pass
  • ✅ Added comprehensive example file (examples/audience_example.yml)
  • ✅ Tested endpoint filtering (include/exclude modes)
  • ✅ Tested property filtering (include/exclude modes)
  • ✅ Tested multiple audiences
  • ✅ Tested public (untagged) items

Documentation

  • Updated README with audience filtering section
  • Added usage examples
  • Created example file demonstrating the feature

🤖 Generated with Claude Code

zebapy and others added 7 commits November 25, 2025 10:17
…ension

This commit adds support for filtering OpenAPI specs by audience, similar to
Fern's x-fern-audiences extension. The implementation allows API definitions
to be tagged at the endpoint and field level, then filtered during build time.

Features:
- Add --audience flag to filter by one or more audiences
- Add --audience-mode flag to control include/exclude behavior
- Support x-openapi-interfaces-audience at operation level (endpoints)
- Support x-openapi-interfaces-audience at schema property level (fields)
- Items without audiences are treated as public/default and included by default
- Add comprehensive example demonstrating audience filtering

Implementation details:
- Extend Scope struct with audience filtering configuration
- Add AudienceFilterMode enum (Include/Exclude)
- Filter operations during OpenApi transpilation
- Filter interface members during Interface transpilation
- Filter schema properties during PrimitiveSchema transpilation
- Preserve required field list consistency when filtering properties

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

Co-Authored-By: Claude <noreply@anthropic.com>
- Derive Default for AudienceFilterMode instead of manual impl
- Remove needless borrows in ref_or.rs and schema.rs
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