pm7y / AzureEventGridSimulator

A simulator that provides endpoints to mimic the functionality of Azure Event Grid topics and subscribers and is compatible with the Azure.Messaging.EventGrid client library.
MIT License
82 stars 39 forks source link

Improve documentation #181

Open tschirky opened 11 months ago

tschirky commented 11 months ago

I think my struggles with the advanced filtering implementation are worth sharing here to maybe consider improving the documentation. Still, this is not supposed to be any blame regarding the general implementation, because we really appreciate this neat little simulator!

Here's a draft:

Advanced Filtering

Every advanced filter config consists of three properties.

operatorType: any in [NumberGreaterThan, NumberGreaterThanOrEquals, NumberLessThan, NumberLessThanOrEquals, NumberIn, NumberNotIn, BoolEquals, StringContains, StringBeginsWith, StringEndsWith, StringIn, StringNotIn]

key: name of a property of the event to filter for. Important: the property name must start with a capital letter, even if the "real" property in the event (i.e. the JSON object) might not.

The third property depends on the operatorType. For the following operator types (StringIn, StringNotIn, NumberIn and NumberNotIn), use the values property with an array of at most 5 values:

"filter": {
  "advancedFilters": [
    {
      "operatorType": "StringIn",
      "key": "Data.Key1",
      "values": ["value1", "value2" ]
    }
  ]
}

For all the other operator types, use the value property with a single value:

"filter": {
  "advancedFilters": [
    {
      "operatorType": "NumberGreaterThanOrEquals",
      "key": "Data.Key1",
      "value": 5
    }
  ]
}

The example given in the current README on the other hand is - if I'm not mistaken - wrong. The operatorType StringContains does not work with an array of values but only with a value.

"filter": {
  "advancedFilters": [
    {
      "operatorType": "NumberGreaterThanOrEquals",
      "key": "Data.Key1",
      "value": 5
    },
    {
      "operatorType": "StringContains",
      "key": "Subject",
      "values": ["container1", "container2"]
    }
  ]
}