🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

fix(#3265781): add resource type route default for single-bundle views - #14

Open
Decipher wants to merge 2 commits into
8.x-1.xfrom
feature/3265781-openapi-resource-type
Open

fix(#3265781): add resource type route default for single-bundle views#14
Decipher wants to merge 2 commits into
8.x-1.xfrom
feature/3265781-openapi-resource-type

Conversation

@Decipher

@Decipher Decipher commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Fixes #3265781.

jsonapi_views-generated routes never carried the resource_type route default that route/resource introspection code (for example the OpenAPI module's JSON:API discovery) reads to resolve a route to a single ResourceType.

This does not use the community patch's/MR !18's approach. Both the original 2022 patch and the 2026 MR add new ResourceType('view', 'view', ViewsResource::class) - a fake type unrelated to the view's real entity type/bundle(s). I installed drupal/openapi_jsonapi and called its generator directly against a real site: that fake type produces zero-schema, generically-tagged ("View") OpenAPI entries for every exposed view, regardless of its real bundle(s). It avoids a crash but replaces it with silently wrong documentation. I also found the originally reported crash no longer reproduces against current openapi/openapi_jsonapi releases at all - their own null-guard (added 2020, in getPaths()) already excludes routes with no resource_type default rather than erroring.

Instead: a view can span multiple bundles (_jsonapi_resource_types, plural, already reflects this), so a single resource_type default only has one unambiguous answer when the view's entity type has exactly one bundle. For that case, this sets the real ResourceType already returned by resourceTypeRepository->get() - no fabrication needed. For a view spanning several bundles, the default is left unset rather than reporting a made-up type.

Verified manually against the real openapi/openapi_jsonapi modules (not just the Kernel test assertions): a single-bundle diagnostic view resolves a real schema ($ref: #/definitions/user--user); a multi-bundle diagnostic view is correctly excluded.

Adds Kernel test coverage for both the single-bundle and multi-bundle cases.

Verified on Drupal 10 and 11 locally via make test-kernel and make lint.

Summary by CodeRabbit

  • Bug Fixes

    • Improved generated Views JSON:API routes to provide accurate resource type information.
    • Single-bundle Views now use a specific resource type, while multi-bundle Views retain supported resource types without an ambiguous default.
    • Improved resource representation handling for JSON:API responses.
  • Tests

    • Added coverage for single-bundle and multi-bundle Views route behavior.
  • Documentation

    • Documented JSON:API resource type default behavior.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Decipher, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5204101b-c78e-42c0-adcd-cc30cf48f7fd

📥 Commits

Reviewing files that changed from the base of the PR and between 3e50d79 and 9e0f9d0.

📒 Files selected for processing (4)
  • AGENTS.md
  • src/Routing/Routes.php
  • tests/src/Kernel/JsonapiViewsResourceKernelTest.php
  • tests/src/Kernel/NullingResourceTypeRepository.php
📝 Walkthrough

Walkthrough

Generated JSON:API view routes now resolve bundle resource types. Single-bundle views receive a singular resource_type default. Multi-bundle views retain plural resource types and omit the singular default. Kernel tests cover both cases.

Changes

View route resource type

Layer / File(s) Summary
Conditional route resource type defaults
src/Routing/Routes.php, AGENTS.md
Resolves bundle resource types before extracting names. Skips views without resolved types. Assigns the singular resource_type default only when exactly one bundle exists.
Route resource type validation
tests/src/Kernel/JsonapiViewsResourceKernelTest.php
Verifies that multi-bundle node routes omit resource_type and single-bundle user routes provide the expected ResourceType.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a resource type route default for single-bundle Views routes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/3265781-openapi-resource-type

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.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.28%. Comparing base (3e50d79) to head (9e0f9d0).

Additional details and impacted files
@@             Coverage Diff             @@
##           8.x-1.x      #14      +/-   ##
===========================================
+ Coverage    94.11%   94.28%   +0.16%     
===========================================
  Files            3        3              
  Lines          136      140       +4     
===========================================
+ Hits           128      132       +4     
  Misses           8        8              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Decipher
Decipher force-pushed the feature/3265781-openapi-resource-type branch from 18d585a to 7eb9fda Compare August 6, 2026 06:51
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@Decipher Decipher changed the title fix(#3265781): add resource type route default for OpenAPI export fix(#3265781): add resource type route default for single-bundle views Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/Routing/Routes.php`:
- Around line 80-85: Update the route-building logic around the
bundle_resource_types mapping to remove unresolved NULL ResourceType results
before constructing resource_types and route defaults. Skip the route when no
bundle resource types resolve, and ensure single-bundle resource_type handling
never assigns NULL; add a Kernel test covering a view whose bundle resource type
is missing.

In `@tests/src/Kernel/JsonapiViewsResourceKernelTest.php`:
- Line 315: Update the assertion for JsonApiRoutes::RESOURCE_TYPE_KEY in the
multi-bundle route test to use hasDefault() and assert the default is absent,
rather than relying on getDefault() returning NULL. Preserve the existing route
setup and other assertions.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 55d5c820-ad18-4c4c-8d89-fd0cce38ca93

📥 Commits

Reviewing files that changed from the base of the PR and between 3e50d79 and 7eb9fda.

📒 Files selected for processing (3)
  • AGENTS.md
  • src/Routing/Routes.php
  • tests/src/Kernel/JsonapiViewsResourceKernelTest.php

Comment thread src/Routing/Routes.php Outdated
Comment on lines +80 to +85
$bundle_resource_types = array_map(fn(int|string $bundle) => $this->resourceTypeRepository->get($entity_type, $bundle), $bundles);

if (empty($resource_types)) {
if (empty($bundle_resource_types)) {
continue;
}
$resource_types = array_map(fn(?ResourceType $resource_type) => $resource_type?->getTypeName(), $bundle_resource_types);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env sh
set -eu

# Run the Kernel suite after adding an unresolved-ResourceType regression case.
make test-kernel

Repository: Decipher/jsonapi_views

Length of output: 202


🏁 Script executed:

#!/usr/bin/env sh
set -eu

printf 'Repository files matching Routes.php / Resource type files:\n'
git ls-files | rg '(^|/)(Routes\.php|.*ResourceType.*\.php)$' || true

printf '\nRoutes.php outline:\n'
ast-grep outline src/Routing/Routes.php || true

printf '\nRelevant Routes.php lines:\n'
cat -n src/Routing/Routes.php | sed -n '1,140p'

printf '\nSearch for resource type repository interfaces/classes and tests mentioning _jsonapi_resource_types:\n'
rg -n "ResourceTypeRepository|resourceTypeRepository|ResourceTypeRepositoryInterface|resource_type|resource_types|_jsonapi_resource_types|routes\(\)" src tests phpunit.xml makefile Makefile -S . || true

Repository: Decipher/jsonapi_views

Length of output: 9336


🌐 Web query:

Drupal jsonapi ResourceTypeRepositoryInterface get() return type NULL get($entity_type_id, $bundle)

💡 Result:

The get method of the Drupal JSON:API ResourceTypeRepositoryInterface returns either an instance of \Drupal\jsonapi\ResourceType\ResourceType or NULL [1][2]. Specifically, the method is defined to return the requested JSON:API resource type if it exists, and NULL if it does not [2][3]. The method signature accepts two parameters: $entity_type_id (the entity type ID) and $bundle (the ID for the bundle, or the entity type ID if the entity does not have a bundle) [2][4]. Note that this interface is marked as @internal, meaning it is not part of the stable PHP API and may change at any time [3]. Developers are advised that the JSON:API module's primary API is the HTTP API [3].

Citations:


🏁 Script executed:

#!/usr/bin/env sh
set -eu

printf 'Kernel test relevant section:\n'
cat -n tests/src/Kernel/JsonapiViewsResourceKernelTest.php | sed -n '260,380p'

printf '\nRepository files for tests and config:\n'
git ls-files tests src vendor composer.json composer.lock phpunit.xml.* Makefile makefile AGENTS.md | sed -n '1,200p'

printf '\nDRUSH/MODULE commands availability:\n'
command -v drush || true
command -v php || true
php -v || true

Repository: Decipher/jsonapi_views

Length of output: 5814


Skip routes with unresolved bundle resource types.

ResourceTypeRepositoryInterface::get() can return NULL; with at least one bundle present, empty($bundle_resource_types) is FALSE, and the route gets NULL values in _jsonapi_resource_types. A single-bundle route can set resource_type to NULL as well. Filter resolved resource types before building route defaults, and add a Kernel test for a view whose bundle resource type does not exist.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Routing/Routes.php` around lines 80 - 85, Update the route-building logic
around the bundle_resource_types mapping to remove unresolved NULL ResourceType
results before constructing resource_types and route defaults. Skip the route
when no bundle resource types resolve, and ensure single-bundle resource_type
handling never assigns NULL; add a Kernel test covering a view whose bundle
resource type is missing.

Source: Coding guidelines

Comment thread tests/src/Kernel/JsonapiViewsResourceKernelTest.php Outdated
@Decipher
Decipher force-pushed the feature/3265781-openapi-resource-type branch from 7eb9fda to 9e0f9d0 Compare August 6, 2026 07:05
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.

1 participant