[PubSub] CloudEvent docs not correct
- Dominant language
- SCSS
- Stars
- 1k
- Forks
- 794
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 7
Description
Given this section of the docs https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-cloudevents/#publish-your-own-cloudevent
There are a few statements which don't appear to be true.
> If the CloudEvent that was authored by the app does not contain the [minimum required fields](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#required-attributes) in the CloudEvent specification, the message is rejected.
Given the following request :
```
> POST /v1.0/publish/redis-pubsub/orders HTTP/1.1
> Host: localhost:3501
> User-Agent: insomnia/2023.4.0
> dapr-app-id: myapp3
> Content-Type: application/cloudevents+json
> Accept: */*
> Content-Length: 34
{
"data": {
"some": "body"
}
}
```
Produces the following CE envelope. :
```json
{
"data": {
"some": "body"
},
"pubsubname": "redis-pubsub",
"source": "Dapr",
"specversion": "1.0",
"time": "2023-08-13T19:40:24Z",
"topic": "orders",
"traceid": "00-00000000000000000000000000000000-0000000000000000-00",
"traceparent": "00-00000000000000000000000000000000-0000000000000000-00",
"tracestate": "",
"type": "com.dapr.event.sent"
}
```
1. As you can see, I did not specify any of the CE required properties (`id`, `source`, `specversion` & `type`) however Dapr allowed the message to be published, it did not reject the message as the docs imply.
2. Interestingly the resulting CE envelope (despite Daprs augmentation) is technically invalid according to the CE spec, as the `Id` property is not present.
Given both points above, the expected behaviour here is hard to pin point. But If I was to hazard a guess...
This section should be adjusted :
> If the CloudEvent that was authored by the app does not contain the [minimum required fields](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#required-attributes) in the CloudEvent specification, ~the message is rejected~. Dapr adds the following fields to the CloudEvent if they are not provided:
> time
> traceid
> traceparent
> tracestate
> topic
> pubsubname
> source
> type
> specversion
To become :
> If the CloudEvent that was authored by the app does not contain the [minimum required fields](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md#required-attributes) in the CloudEvent specification, **these will be added automatically by Dapr**.
> Dapr will also add the following fields to the CloudEvent if they are not provided :
> time
> traceid
> traceparent
> tracestate
> topic
> pubsubname
> source
> type
> specversion
> id <- NEW
This still leaves my second point above unsatisfied, so I will raise a bug for that in `dapr/dapr` for that.
Contributor guide
Assessment
This issue has not been assessed yet.