Skip to content

PSM JSON serializers write null for optional references the OpenAPI document does not make nullable #425

Closed

Description

@samatstariongroup

Problem

The generated PSM JSON serializers write null for an optional reference property that is not set, where the OpenAPI document (Resources/ptc-25-02-30.json) declares that property as an Identified object that is not nullable. A conforming request leaves the property out instead.

Example, SysML2.NET.Serializer.Json/PSM/AutoGenSerializer/ProjectRequestSerializer.cs:88:

else
{
    writer.WriteNull("defaultBranch"u8);
}

ProjectRequest in the OpenAPI document:

"defaultBranch": { "$ref": "#/components/schemas/Identified" },
"required": ["name"]

So new ProjectRequest { Name = "p" } is sent as {"@type":"Project","defaultBranch":null,…}, which does not validate against ProjectRequest.

Affected request types

Optional, non-nullable properties for which the serializer writes null:

Request Properties
DataVersionRequest identity
ExternalRelationshipRequest elementEnd, externalDataEnd
PrimitiveConstraintRequest inverse
ProjectRequest defaultBranch
ProjectUsageRequest usedCommit, usedProject

The serializers are generated from SysML2.NET.CodeGenerator/Templates/OpenAPI/psm-json-serializer-openapi-template.hbs; the fix belongs in the template: omit an unset property unless its schema allows null.

How it was found

The Flexo integration scenario of #407 checks every request against the OpenAPI document. POST /projects (step 2) fails that check:

POST /projects: SchemaMismatch: /defaultBranch type: Value is "null" but should be "object"

The check stays red until this is fixed.

Activity

  1. added
    bug
    on Nov 7, 2026
  2. added a commit that references this issue on Nov 9, 2026
    93bffef
  3. added a commit that references this issue on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions