Skip to content

Conversation

bkoelman
Copy link
Member

@bkoelman bkoelman commented Aug 23, 2025

This PR improves existing tests for ID obfuscation by:

  • asserting on obfuscated IDs in returned links
  • adding support for atomic operations
  • using long instead of int as the internal ID type

ResourceGraphBuilder now has a Remove method, which enables the removal of a resource type from the resource graph, after assembly scanning has run. This is used to exclude the ObfuscatedIdentifiable abstract base class, which is not supposed to be exposed externally.

A new annotation [HideResourceIdTypeInOpenApi] is added to the JsonApiDotNetCore.OpenApi.Swashbuckle package, which can be used to hide the underlying type of IDs. Before, the OpenAPI schema looked like:

"schema": {
  "minLength": 1,
  "type": "string",
  "format": "int64"
}

With the new annotation added to ObfuscatedIdentifiable (which implicitly applies to all derived types), it becomes:

"schema": {
  "type": "string"
}

This is useful in the case of ID obfuscation because while the internal resource ID types are long, the publicly exposed obfuscated IDs are strings. We shouldn't make the internal ID type (which is an implementation detail) externally observable.

Closes #1067, closes #1603.

QUALITY CHECKLIST

@bkoelman bkoelman changed the title Enhanced id obfuscation Improved ID obfuscation Aug 23, 2025
Copy link

codecov bot commented Aug 23, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.04%. Comparing base (23be010) to head (c8d2ec2).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1775      +/-   ##
==========================================
- Coverage   92.06%   92.04%   -0.02%     
==========================================
  Files         475      475              
  Lines       14722    14736      +14     
  Branches     2331     2332       +1     
==========================================
+ Hits        13554    13564      +10     
- Misses        766      770       +4     
  Partials      402      402              

☔ 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.

@bkoelman bkoelman marked this pull request as ready for review August 23, 2025 22:23
@bkoelman bkoelman merged commit 9277256 into master Aug 23, 2025
16 checks passed
@bkoelman bkoelman deleted the enhanced-id-obfuscation branch August 23, 2025 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Revisit ID obfuscation sample Support for ID obfuscation
1 participant