Skip to content

fix(api): resolve issue causing the example API to fail in monorepos#225

Open
wise-king-sullyman wants to merge 1 commit intomainfrom
fix-example-api-not-working-in-monorepos
Open

fix(api): resolve issue causing the example API to fail in monorepos#225
wise-king-sullyman wants to merge 1 commit intomainfrom
fix-example-api-not-working-in-monorepos

Conversation

@wise-king-sullyman
Copy link
Contributor

@wise-king-sullyman wise-king-sullyman commented Mar 11, 2026

Closes #213

Assisted by Claude Code

I've got a local test of this pulled into org deployed at https://9ca89a13.patternfly-org.pages.dev/api

You can access examples via the examples api on it proving that this fix should work once it's pulled in downstream, such as https://9ca89a13.patternfly-org.pages.dev/api/v6/components/alert/react/examples/AlertGroupAsync

Summary by CodeRabbit

  • Tests

    • Added comprehensive test suite for API example retrieval, including monorepo path resolution and error handling scenarios.
  • Bug Fixes

    • Improved path resolution for API examples in monorepo configurations.
    • Enhanced content file access with fallback mechanisms to support diverse project structures.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 11, 2026

Walkthrough

This PR adds monorepo support to the examples API endpoint by introducing base path resolution for content entries. The implementation tracks package-specific base paths from content entries and uses them as fallback locations when resolving example file paths, enabling the API to work correctly in monorepo configurations.

Changes

Cohort / File(s) Summary
Test Coverage
src/__tests__/pages/api/__tests__/[version]/[section]/[page]/[tab]/examples/[example].test.ts
New comprehensive test suite covering example file resolution, including monorepo base path fallback, missing entries, file system errors (ENOENT), missing parameters, and content entry lookups.
Examples API Endpoint
src/pages/api/[version]/[section]/[page]/[tab]/examples/[example].ts
Updated to resolve content entry paths using base fallback mechanism; attempts primary content entry path, falls back to base-relative path if inaccessible, and adjusts example file path resolution accordingly.
Content Resolution Utilities
src/utils/apiRoutes/contentMatching.ts, src/utils/apiRoutes/collections.ts
Modified return types and enrichment logic to include optional base property; findContentEntryFilePath() now returns { filePath: string; base?: string } instead of a plain string, and getEnrichedCollections() propagates base paths through enriched entries.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

released

Suggested reviewers

  • dlabaj
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(api): resolve issue causing the example API to fail in monorepos' clearly and specifically describes the main change—fixing monorepo support for the example API endpoint.
Linked Issues check ✅ Passed The pull request implements all completion criteria from issue #213: resolves example files in monorepos via package-aware path resolution, maintains backward compatibility, and follows established monorepo patterns.
Out of Scope Changes check ✅ Passed All code changes directly address monorepo path resolution for the example API, including test additions, handler updates, and utility modifications—all within scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-example-api-not-working-in-monorepos

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

Example file API fails in monorepos

1 participant