Skip to content

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

Merged
antoineatstariongroup merged 3 commits into
developmentfrom
389-feature-pim-resthttp-psm-data-mapping-declared-on-the-psm-types
Oct 26, 2026
Merged

antoineatstariongroup merged 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

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

Comment thread SysML2.NET/PIM/POCO/Branch.cs Outdated
/// Gets or sets the commit to which the branch is currently pointing. It represents the latest state of the
/// <see cref="Project"/> on the given branch
/// </summary>
[Property(lowerValue: 1, upperValue: 1)]

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.

please use full form, the intent is to be self documenting

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The rebase took care of that

Comment thread SysML2.NET/PIM/DTO/Commit.cs Outdated
/// <summary>
/// Gets or sets the timestamp at which the <see cref="Commit"/> was created
/// </summary>
[Property(lowerValue: 1, upperValue: 1)]

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.

please use full form, the intent is to be self documenting

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The rebase took care of that

@samatstariongroup

Copy link
Copy Markdown
Member

please document the mapping principle and difference between PIM and REST model in the wiki

@antoineatstariongroup
antoineatstariongroup force-pushed the 389-feature-pim-resthttp-psm-data-mapping-declared-on-the-psm-types branch from 50caf2d to 1ce5a04 Compare October 26, 2026 15:02
@sonarqubecloud

Copy link
Copy Markdown

@antoineatstariongroup
antoineatstariongroup merged commit 4e42a36 into development Oct 26, 2026
8 checks passed
@antoineatstariongroup
antoineatstariongroup deleted the 389-feature-pim-resthttp-psm-data-mapping-declared-on-the-psm-types branch October 26, 2026 15:16
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