Skip to content

Fix #389: PIM <-> PSM data mapping - #391

Open
antoineatstariongroup wants to merge 3 commits into
developmentfrom
389-feature-pim-resthttp-psm-data-mapping-declared-on-the-psm-types
Open

antoineatstariongroup wants to merge 3 commits into
developmentfrom
389-feature-pim-resthttp-psm-data-mapping-declared-on-the-psm-types

Conversation

@antoineatstariongroup

@antoineatstariongroup antoineatstariongroup commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the SysML2.NET code style guidelines
  • I have provided test coverage for my change (where applicable)

Description

Fix #389

Provides datamapping between the PIM and REST PSM. PR #390 needs to be merged-in first

@antoineatstariongroup antoineatstariongroup linked an issue Oct 12, 2026 that may be closed by this pull request
1 of 2 tasks
@sonarqubecloud

Copy link
Copy Markdown

@samatstariongroup samatstariongroup left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Review of the mapping added on top of #390, checked against Resources/ptc-25-02-30.json. The solution builds and all tests pass locally on 50caf2d4; the problems below are cases the tests do not cover.

Functional problems

1. A live branch or tag maps to one deleted on 0001-01-01

Branch.FromPim and Tag.FromPim (SysML2.NET/PSM/DTO/Mapping/Branch.Mapping.cs, SysML2.NET/PSM/DTO/Mapping/Tag.Mapping.cs) copy the PIM Deleted straight into the nullable PSM Deleted. The PIM type is a non-nullable DateTime, so a branch that was never deleted arrives as default and leaves as a non-null timestamp. ToPim does the reverse (null → default), so PSM → PIM → PSM is not an identity.

The round-trip tests only cover a record with Deleted set. The root cause is the non-nullable Deleted on the PIM DTO, already raised on #390.

2. Guid.Empty leaks into requests as a real reference

The request ToPim methods use ?? Guid.Empty for absent references, and FromPim copies the PIM value back without the reverse check. A PIM Project with no default branch therefore produces a ProjectRequest with a non-null all-zero DefaultBranch, where the OpenAPI document makes that member optional.

The same pattern affects:

  • BranchRequest.Head and Branch.Head
  • ExternalDataRequest.Id
  • ExternalRelationshipRequest (Id, ElementEnd, ExternalDataEnd)
  • ProjectUsageRequest (Id, UsedCommit, UsedProject)

FromPim should map Guid.Empty back to null for the nullable PSM members, with a test for the absent case of each.

Limitations to document or resolve

3. Id-only shells where the OpenAPI document requires full objects

DataDifference.FromPim builds a DataVersion with only Id set, and MergeResultMapper.ToPsm does the same for Commit and DataIdentity. The OpenAPI document requires full objects there (identity, payload, created, owningProject), so serializing these shells yields invalid responses. The PIM DTO carries only ids, so the mapper cannot do better without a lookup; the XML docs should state this, or the mapper should accept a resolver.

4. Constraint value types are lost

ConstraintMapper.ToPimValue renders numbers, booleans and ids as strings, and ToPsmValue wraps every value as a string, so 4 comes back as "4". The remarks in SysML2.NET/PSM/DTO/ConstraintMapper.cs document this, but it means a query condition does not survive a pass through the PIM.

5. No mapping for CommitRequest or DataVersionRequest

#390 added Commit.Change as the input of createCommit, but nothing maps it. Issue #389 calls the contract opt-in, so please either add the mapping or say in the PR description that it is out of scope.

Tests

6. Fixture layout

SysML2.NET.Tests/PSM/DTO/PimMappingTestFixture.cs covers some 23 production types in one fixture, with Verify…RoundTrip test names. TESTING.md asks for one fixture per production type and Verify{MethodUnderTest} names.

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.

[Feature]: PIM ↔ REST/HTTP PSM data mapping declared on the PSM types

2 participants