Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/add-optional-array-body-spector-2026-6-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/http-specs"
---

Add Spector coverage for omitted optional array request bodies.
7 changes: 7 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -5431,6 +5431,13 @@ Expected Array input body:
["hello", null, "world"]
```

### Type_Array_OptionalValue

- Endpoint: `put /type/array/optional`

Expected no request body.
Expected Content-Type header: must NOT be present

### Type_Array_StringValue_get

- Endpoint: `get /type/array/string`
Expand Down
12 changes: 12 additions & 0 deletions packages/http-specs/specs/type/array/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,15 @@ interface NullableModelValue
NullableModel[],
"[{'property': 'hello'}, null, {'property': 'world'}]"
> {}

@scenario
@doc("Optional array value")
@scenarioDoc("""
Expected no request body.
Expected Content-Type header: must NOT be present
""")
@route("/optional")
interface OptionalValue {
@put
omit(@body body?: string[]): void;
}
30 changes: 29 additions & 1 deletion packages/http-specs/specs/type/array/mockapi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";
import {
json,
MockRequest,
passOnSuccess,
ScenarioMockApi,
ValidationError,
} from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Expand Down Expand Up @@ -105,3 +111,25 @@ const Type_Array_Nullable_Model = createServerTests(`/type/array/nullable-model`
]);
Scenarios.Type_Array_NullableModelValue_get = Type_Array_Nullable_Model.get;
Scenarios.Type_Array_NullableModelValue_put = Type_Array_Nullable_Model.put;

Scenarios.Type_Array_OptionalValue = passOnSuccess({
uri: "/type/array/optional/omit",
method: "put",
request: {},
response: {
status: 204,
},
handler: (req: MockRequest) => {
req.expect.rawBodyEquals(undefined);
const contentTypeHeader = req.headers["content-type"];
if (contentTypeHeader !== undefined) {
throw new ValidationError(
"Content-Type header must NOT be present when body is omitted",
undefined,
contentTypeHeader,
);
}
return { status: 204 };
},
kind: "MockApiDefinition",
});
Loading