⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add test case for ArrayEncoding with extensible union
21 changes: 21 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,27 @@ Expected response body:
}
```

### Encode_Array_Property_pipeDelimitedEnumElement

- Endpoint: `post /encode/array/property/pipe-delimited-enum-element`

Test operation with request and response model contains an extensible enum array property with pipeDelimited encode.
Expected request body:

```json
{
"value": "blue|red|green"
}
```

Expected response body:

```json
{
"value": "blue|red|green"
}
```

### Encode_Array_Property_spaceDelimited

- Endpoint: `post /encode/array/property/space-delimited`
Expand Down
34 changes: 34 additions & 0 deletions packages/http-specs/specs/encode/array/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ using Spector;
@scenarioService("/encode/array")
namespace Encode.Array;

union Color {
string,
Blue: "blue",
Red: "red",
Green: "green",
}

model CommaDelimitedArrayProperty {
@encode(ArrayEncoding.commaDelimited)
value: string[];
Expand All @@ -28,6 +35,11 @@ model NewlineDelimitedArrayProperty {
value: string[];
}

model PipeDelimitedArrayEnumElementProperty {
@encode(ArrayEncoding.pipeDelimited)
value: Color[];
}

@route("/property")
namespace Property {
@route("/comma-delimited")
Expand Down Expand Up @@ -109,4 +121,26 @@ namespace Property {
""")
@post
op newlineDelimited(@body body: NewlineDelimitedArrayProperty): NewlineDelimitedArrayProperty;

@route("/pipe-delimited-enum-element")
@scenario
@scenarioDoc("""
Test operation with request and response model contains an extensible enum array property with pipeDelimited encode.
Expected request body:
```json
{
"value": "blue|red|green"
}
```
Expected response body:
```json
{
"value": "blue|red|green"
}
```
""")
@post
op pipeDelimitedEnumElement(
@body body: PipeDelimitedArrayEnumElementProperty,
): PipeDelimitedArrayEnumElementProperty;
}
5 changes: 5 additions & 0 deletions packages/http-specs/specs/encode/array/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ Scenarios.Encode_Array_Property_newlineDelimited = createPropertyServerTests(
"/encode/array/property/newline-delimited",
"\n",
);

Scenarios.Encode_Array_Property_pipeDelimitedEnumElement = createPropertyServerTests(
"/encode/array/property/pipe-delimited-enum-element",
"|",
);
Loading