Skip to content

request-body-problem

Id
@azure-tools/typespec-azure-core/request-body-problem

Request body should not be of raw array type.

Request body should not be of raw array type. Using an array as the top-level request body prevents adding new properties in the future without introducing breaking changes. Instead, create a container model that wraps the array.

  • Area: API, SDK

A request body typed as a bare array is difficult to evolve, since new properties cannot be added later.

Raw array as request body:

op upload(@body body: string[]): string;

Wrap the array in a model:

model StringList {
value: string[];
}
op upload(@body body: StringList): string;
op list(@body body: string): string[];

Suppress for actions where an array body is appropriate; otherwise wrap the array in a keyed model property so new properties can be added in the future.