Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: override code based defaults with explicit ones #2377

Conversation

heiglandreas
Copy link
Contributor

@heiglandreas heiglandreas commented Nov 6, 2024

Description

This change allows that defaults that are set in attributes can override the ones that are read from the code.

This fixes #2330

Closes #2330

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)

This change allows that defaults that are set in attributes can override
the ones that are read from the code.

This fixes nelmio#2330
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch 3 times, most recently from de11fd1 to 4451269 Compare November 6, 2024 11:02
@heiglandreas heiglandreas changed the title Override code based defaults with explicit ones Fix: Override code based defaults with explicit ones Nov 6, 2024
@heiglandreas heiglandreas changed the title Fix: Override code based defaults with explicit ones fix: Override code based defaults with explicit ones Nov 6, 2024
@heiglandreas heiglandreas marked this pull request as ready for review November 6, 2024 11:05
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch from 4451269 to 6419201 Compare November 6, 2024 14:38
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch from 6419201 to 0a81850 Compare November 6, 2024 14:54
Copy link

codecov bot commented Nov 6, 2024

Codecov Report

Attention: Patch coverage is 92.45283% with 4 lines in your changes missing coverage. Please review.

Project coverage is 89.48%. Comparing base (1023c9d) to head (6a2bffd).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...rc/ModelDescriber/Annotations/ReflectionReader.php 92.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2377      +/-   ##
==========================================
+ Coverage   89.46%   89.48%   +0.01%     
==========================================
  Files          77       78       +1     
  Lines        2848     2890      +42     
==========================================
+ Hits         2548     2586      +38     
- Misses        300      304       +4     

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

@heiglandreas heiglandreas marked this pull request as draft November 7, 2024 06:14
@heiglandreas heiglandreas changed the title fix: Override code based defaults with explicit ones fix: override code based defaults with explicit ones Nov 7, 2024
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch from 7a499cb to 006e643 Compare November 7, 2024 08:29
This allows to fetch default values via reflection should they so far
not have been set via other means.

As that happens before the SymfonyConstraint handling, the required
fields should be set as expected but should also take into account the
default values set via Attributes or Annotations.
Two tests didn't handle the provided defaults properly, so I had to fix
them to now also validate that the defaults are set appropriately
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch from 006e643 to 43eca97 Compare November 7, 2024 08:33
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch 2 times, most recently from 65cbd50 to 4e3fae1 Compare November 7, 2024 08:54
As the library is set to be usable with PHP7.4 and the
ReflectionProperty::has/getDefaultValue is only available for PHP8+ I
needed to slightly refactor the class.
@heiglandreas heiglandreas force-pushed the override-code-defauls-with-explicitly-set-ones branch from 4e3fae1 to 6a2bffd Compare November 7, 2024 08:56
@heiglandreas heiglandreas marked this pull request as ready for review November 7, 2024 08:57
@heiglandreas
Copy link
Contributor Author

All problems should be addressed, the behaviour is almost the same as before.

I had to change two tests where a default value was provided in the code that wasn't passed into the OpenAPI-spec previously but is passed in now.

This could be considered a BC-break but I'd argue that it was broken in the first place and is therefore a Bug-Fix

Copy link
Collaborator

@DjordyKoert DjordyKoert left a comment

Choose a reason for hiding this comment

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

LGTM

@DjordyKoert DjordyKoert merged commit 84c7916 into nelmio:master Nov 7, 2024
20 checks passed
@DjordyKoert
Copy link
Collaborator

Thank you @heiglandreas ❤️

DjordyKoert pushed a commit that referenced this pull request Nov 7, 2024
## Description

This change allows that defaults that are set in attributes can override
the ones that are read from the code.

This fixes #2330

Closes #2330

## What type of PR is this? (check all applicable)
- [x] 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`)

(cherry picked from commit 84c7916)
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.

[Bug]: explicit setting of default value in Property causes error "Multiple definitions for [property]"
3 participants