Skip to content

fix: allow payload property named message with null value - #1247

Open
AayushSaini101 wants to merge 1 commit into
asyncapi:masterfrom
AayushSaini101:863
Open

AayushSaini101 wants to merge 1 commit into
asyncapi:masterfrom
AayushSaini101:863

Conversation

@AayushSaini101

@AayushSaini101 AayushSaini101 commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

closes#863:
Related: #1203
parsing/validating an AsyncAPI 2.x document no longer crashes when a payload schema defines a property named message with a null example value.

The issue occurred because several v2 Spectral rule JSONPath filters used expressions like:

[?(@property === 'message' && @.schemaFormat === void 0)]

jsonpath-plus evaluates these filters while traversing the document tree. Any property named message matched the filter — including payload schema fields, not just AsyncAPI Message Objects. When that value was null, accessing @.schemaFormat threw:

Cannot read properties of null (reading 'schemaFormat')

This fix adds !@null guards before property access on @, consistent with other filters already in the ruleset.

Changes

  • Add !@null && guards to 8 JSONPath filters in packages/parser/src/ruleset/v2/ruleset.ts
    • asyncapi2-message-examples
    • asyncapi2-schema-default
    • asyncapi2-schema-examples
    • asyncapi2-message-messageId
  • Add !@null && guards to 2 JSONPath filters in messageExamples-spectral-rule-v2.ts
  • Add regression tests based on the gist from the issue
  • Add integration test in validate.spec.ts using parser.parse()

Test plan

  • Parse a document with payload.properties.message allowing null and examples[0].payload.message: null
  • Confirm no Cannot read properties of null diagnostic
  • Confirm no uncaught-error diagnostic
  • Confirm existing rule tests still pass for asyncapi2-message-examples, asyncapi2-schema-examples, asyncapi2-schema-default, and asyncapi2-message-messageId

Closes #863

Add null guards to JSONPath filters that matched payload schema fields
named message and crashed when accessing schemaFormat on null values.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Sep 12, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 34f8920

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@asyncapi/parser Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@sonarqubecloud

Copy link
Copy Markdown

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.

Payload property named message breaks with null value

1 participant