Skip to content

feat(#1461): filter JMS properties by route area - #2407

Open
jneidel wants to merge 3 commits into
nelmio:4.xfrom
jneidel:master
Open

feat(#1461): filter JMS properties by route area#2407
jneidel wants to merge 3 commits into
nelmio:4.xfrom
jneidel:master

Conversation

@jneidel

@jneidel jneidel commented Dec 9, 2024

Copy link
Copy Markdown

Description

This PR uses the area configured in the route (like /api/{area}/doc/) to filter out properties on the model, which should be excluded based on JMS's versioning (also see demo below.)

Closes #1461
Refs #2129

What type of PR is this? (check all applicable)

  • Bug Fix
  • Feature
  • Refactor
  • Deprecation
  • Breaking Change
  • Documentation Update
  • CI

Checklist

  • I have made corresponding changes to the documentation (docs/)
  • I have made corresponding changes to the changelog (CHANGELOG.md)

Demo from our project

We have an entity property:

// MyEntity.php

#[Serializer\Until('v3')]
private \DateTimeInterface $createdAt;                                                                                                     

Opening the docs on the route: /api/v4.3/doc/,
which is configured as:

# config/routes/nelmio_api_doc.yaml

nelmio_api_doc_index:
  path: /api/{area}/doc/
  defaults: { _controller: nelmio_api_doc.controller.swagger_ui }
  methods: [GET]

before this PR
Screenshot 2024-12-09 at 12 53 27
after this PR
Screenshot 2024-12-09 at 12 54 45

Implementation

I opted for the word "area", since it is used in the route definition.
I proceeded as adviced in #1461.

Could you point me to where you would like to see tests created/adjusted?

@codecov

codecov Bot commented Dec 9, 2024

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.51%. Comparing base (9411e9c) to head (427d9d7).
⚠️ Report is 56 commits behind head on 4.x.

Files with missing lines Patch % Lines
src/ModelDescriber/JMSModelDescriber.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              4.x    #2407      +/-   ##
==========================================
+ Coverage   89.50%   89.51%   +0.01%     
==========================================
  Files          78       78              
  Lines        2896     2910      +14     
==========================================
+ Hits         2592     2605      +13     
- Misses        304      305       +1     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread CHANGELOG.md
@jneidel jneidel changed the title feat: filter JMS properties by route area feat(#1461): filter JMS properties by route area Dec 9, 2024

$area = $model->getArea();
if (null !== $area) {
$context->addExclusionStrategy(new VersionExclusionStrategy($area));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you write a test? 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I honestly tried, but could not figure out how to test it. I could have asked for help back then, but I didn't. Now it would be even harder to do, even with help.

@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This PR has been marked as stale because it has not had any activity for 60 days. Remove stale label or comment to prevent this from being closed in 60 days.

@github-actions github-actions Bot added the stale stale issue/PR label Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale stale issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation for versioned api

2 participants