elsa-workflows / elsa-workflows/elsa-core

Duplicate StatusCode values in WriteHttpResponse activity input dropdown

Open
#6,845 0 comments 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
7.9k
Forks
1.5k
Avg merge
15h 22m
Merged PRs (30d)
114

Description

### Description:
The `WriteHttpResponse` activity exposes a dropdown input for selecting an HTTP status code, based on `System.Net.HttpStatusCode`.

When calling `GET /descriptors/activities`, the `status` input generates its dropdown from `Enum.GetValues()`. However, this results in **duplicate entries** because the `HttpStatusCode` enum contains multiple names with the same underlying value.

For example:

- `MultipleChoices` appears twice (value = 300)
- `MovedPermanently` appears twice (value = 301)
- `Found` appears twice (value = 302)
- `SeeOther` appears twice (value = 303)
- `TemporaryRedirect` appears twice (value = 307)
- `UnprocessableEntity` appears twice (value = 422)

---

### How to Reproduce:

1. Start Elsa Server
2. Call `GET /descriptors/activities`
3. Locate the `WriteHttpResponse` activity
4. Inspect the `status` input's dropdown list (selectList.items)
5. Observe repeated values with identical `text` and `value` fields

---

### Root Cause:
Calling `Enum.GetValues()` returns all enum members **in declaration order**, including names that share the same numeric value. The resulting list contains duplicates unless explicitly de-duplicated.

---

### Suggested Fix:
Filter the dropdown list to include only **distinct numeric values**, e.g.:

```csharp
Enum.GetValues()
.Cast()
.DistinctBy(code => (int)code)
```
Or use:
```csharp
Enum.GetValues(typeof(HttpStatusCode))
.Cast()
.GroupBy(x => (int)x)
.Select(g => g.First())
```
This will ensure that only one entry per status code is displayed in the dropdown.

### Environment:
Elsa Core Version: 3.4.2
Endpoint: GET /descriptors/activities
Affected Activity: WriteHttpResponse
Affected Input: status (bound to StatusCode enum)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.