Skip to content

Conversation

@fredbi
Copy link
Member

@fredbi fredbi commented Mar 25, 2025

feat: add generics for conversion and pointer utilities

Also:
* refactored all the conversion and pointer/value methods
  as a separate package, thus deprecating their usage from
  the swag package.
  • test: added benchmark for the small optimization of conv.ConvertBool
NOTE:
* This is a first step towards the complete split of the vast API of
the swag package into smaller packages, which will eventually become go
modules, thus reducing the spread of dependencies (e.g. easyjson and
yaml).


Signed-off-by: Frederic BIDON <fredbi@yahoo.com>

fredbi added 2 commits March 25, 2025 12:44
Also:
* refactored all the conversion and pointer/value methods
  as a separate package, thus deprecating their usage from
  the swag package.

NOTE:
* This is a first step towards the complete split of the vast API of
the swag package into smaller packages, which will eventually become go
modules, thus reducing the spread of dependencies (e.g. easyjson and
yaml).

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@codecov
Copy link

codecov bot commented Mar 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.54%. Comparing base (b043ca7) to head (172b3c7).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #108      +/-   ##
==========================================
- Coverage   89.03%   87.54%   -1.50%     
==========================================
  Files          15       19       +4     
  Lines        1970     1678     -292     
==========================================
- Hits         1754     1469     -285     
+ Misses        183      176       -7     
  Partials       33       33              
Flag Coverage Δ
oldstable-macos-latest 86.17% <100.00%> (-1.70%) ⬇️
oldstable-ubuntu-latest 86.17% <100.00%> (-1.70%) ⬇️
oldstable-windows-latest 87.18% <100.00%> (-1.55%) ⬇️
stable-macos-latest 86.17% <100.00%> (-1.70%) ⬇️
stable-ubuntu-latest 86.17% <100.00%> (-1.70%) ⬇️
stable-windows-latest 87.18% <100.00%> (-1.55%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 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.

Code suggestion to simplify test

Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com>
@fredbi
Copy link
Member Author

fredbi commented Mar 25, 2025

@ccoVeille you may also find this read interesting, as I've tried to explain the (long-winded) migration plan that all these PRs try to contribute to: #68

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
Comment on lines +57 to +61
// NOTE: [unsafe.SizeOf] simply returns the size in bytes of the value.
// For primitive types T, the generic stencil is precompiled and this value
// is resolved at compile time, resulting in an immediate call to [strconv.ParseFloat].
var v T
f, err := strconv.ParseFloat(str, int(unsafe.Sizeof(v))*8)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is good, but you are using unsafe.Sizeof in various place here in this file

Please consider:

  • creating a sizeof.go file
  • add a sizeOfNumber func
  • add this exact comment
  • call sizeOfNumber everywhere else

This way, only sizeof.go will import the unsafe package and it would be clearer

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you see this before merging ?

@fredbi

Copy link
Member Author

Choose a reason for hiding this comment

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

ok thanks. I'v been considering that wrapper func too. Perhaps in a follow-up. Now it is time to merge and move on to the next series of packages

Copy link
Contributor

Choose a reason for hiding this comment

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

@fredbi
Copy link
Member Author

fredbi commented Mar 25, 2025

again a false negative from codecov: reducing the code automatically magnifies the few uncovered (pre-existing) parts of the code

@fredbi fredbi merged commit 8d59866 into go-openapi:master Mar 25, 2025
9 of 11 checks passed
@fredbi fredbi deleted the feat/conv-package branch March 25, 2025 20:11
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