Skip to content

SHOULD throw if extension attributes are NOT following naming convention? #380

Closed

Description

@c-pius

Describe the Bug
Extension attributes NOT following the naming convention (lowercase) are added to the event (no error thrown) but their value is added as undefined.

Steps to Reproduce
Use the following snippet:

const event = HTTP.toEvent({
  headers: {
    'Content-Type': 'application/json',
    'ce-id': '0815',
    'ce-specversion': '1.0',
    'ce-type': 'my.event.type',
    'ce-source': 'my.event.source',
    'ce-FOO': 'bar',
  },
  body: {}
})

Check the resulting event:

{
  //...
  id: '0815',
  specversion: '1.0',
  type: 'my.event.type',
  source: 'my.event.source',
  foo: undefined
}

Expected Behavior
I assume according to spec an error should be thrown if attributes not following the naming convention are passed. Alternatively, if they are still accepted, their value should be passed on to the event correctly.

Additional context
If decided to still pass the extension attribute, I think the problem lies somewhere here:

eventObj[header.substring(CONSTANTS.EXTENSIONS_PREFIX.length)] = headers[header];

header has been sanitized (converted to lowercase, e.g. ce-foo) which is not present as such in the headers object (still original casing, e.g. ce-FOO) and therefore undefined is set as value.

Activity

  1. lance commented on Mar 5, 2021

    @lance
    Member

    I assume according to spec an error should be thrown if attributes not following the naming convention are passed.

    When creating a new event in code, I think I agree. But this is similar to other scenarios in that when receiving an event, the library should adhere to loose validation. That is, if we can effectively recover from the wrongly formatted event when receiving it, we should. I accept that this scenario should be caught and flagged somehow.

    Alternatively, if they are still accepted, their value should be passed on to the event correctly.

    It's not so clear to me. In that case, the resulting event would not conform to the specification. I think I would rather see the event ultimately represented according to spec.

  2. lance commented on Mar 5, 2021

    @lance
    Member

    When creating a new event in code, I think I agree.

    In fact, that is what's happening. See: #389

  3. github-actions commented on Apr 5, 2021

    @github-actions
    Contributor

    This issue is stale because it has been open 30 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions