Skip to content

fix: use dedicated struct for identity mapping request#359

Closed
leifj wants to merge 2 commits into
SUNET:mainfrom
sirosfoundation:fix/identity-mapping-request-validation
Closed

fix: use dedicated struct for identity mapping request#359
leifj wants to merge 2 commits into
SUNET:mainfrom
sirosfoundation:fix/identity-mapping-request-validation

Conversation

@leifj
Copy link
Copy Markdown
Contributor

@leifj leifj commented Apr 23, 2026

The POST /api/v1/identity/mapping endpoint reused model.Identity which marks authentic_source_person_id and schema as required via validation tags. However, authentic_source_person_id is the output of this endpoint — requiring it in the request is contradictory.

This creates a dedicated IdentityMappingIdentity struct for the mapping request with:

  • Required fields: schema, family_name, given_name, birth_date
  • Optional fields (for narrowing matches): birth_place, nationality, personal_administrative_number, birth_family_name, birth_given_name, sex, email_address, mobile_phone_number, issuing_authority, issuing_country

The handler converts IdentityMappingIdentitymodel.Identity internally before passing to the datastore.

The MongoDB query now uses $elemMatch to ensure all identity predicates match the same array element (preventing cross-element false positives), and uses $all for nationality matching. Optional fields are included in the filter only when provided.

Regenerated swagger docs to reflect the new request type.

Reported by SKV during integration testing — the documented example (without authentic_source_person_id) was returning a validation error.

@leifj leifj force-pushed the fix/identity-mapping-request-validation branch 2 times, most recently from 1ff26ca to 84af15e Compare April 23, 2026 12:02
@masv3971 masv3971 requested a review from Copilot April 23, 2026 13:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adjusts the POST /api/v1/identity/mapping request model so the endpoint no longer reuses model.Identity (which requires authentic_source_person_id), and extends the datastore lookup to optionally narrow matches using additional identity fields when provided.

Changes:

  • Introduces IdentityMappingIdentity as a dedicated request struct for the identity mapping endpoint and converts it to model.Identity internally.
  • Adds optional identity fields to the MongoDB query filter to narrow ID mapping matches when those fields are present.
  • Updates the handler request type for /identity/mapping to use the new struct.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
internal/apigw/apiv1/handlers_datastore.go Adds a dedicated request identity type for /identity/mapping and maps it into model.Identity for datastore lookup.
internal/apigw/db/methods_vc_datastore.go Extends the ID mapping MongoDB filter with optional identity fields for more specific matching.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/apigw/apiv1/handlers_datastore.go
Comment thread internal/apigw/db/methods_vc_datastore.go Outdated
Comment thread internal/apigw/db/methods_vc_datastore.go Outdated
Comment thread internal/apigw/apiv1/handlers_datastore.go
The IdentityMapping endpoint reused model.Identity which requires
authentic_source_person_id - but that field is the output of this
endpoint, not an input. Create IdentityMappingIdentity with only
the fields needed for lookup: schema, family_name, given_name,
birth_date.
@leifj leifj force-pushed the fix/identity-mapping-request-validation branch from 84af15e to 3068ef4 Compare April 23, 2026 17:25
@sonarqubecloud
Copy link
Copy Markdown

@masv3971 masv3971 closed this May 20, 2026
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.

3 participants