Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-azure-resource-manager"
---

Allow augment decoration of action request body
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ interface Widgets {
update is Azure.ResourceManager.Legacy.CustomPatchAsync<
Widget,
Foundations.ResourceUpdateModel<Widget, WidgetProperties>,
RequestBody = {
/** The PATCH request body */
@body body?: Foundations.ResourceUpdateModel<Widget, WidgetProperties>;
}
OptionalRequestBody = true
>;
delete is ArmResourceDeleteWithoutOkAsync<Widget>;
list is ArmResourceListByParent<Widget>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@
"pattern": "^[a-zA-Z0-9-]{3,24}$"
},
{
"name": "body",
"name": "properties",
"in": "body",
"description": "The PATCH request body",
"description": "The resource properties to be updated.",
"required": false,
"schema": {
"$ref": "#/definitions/WidgetUpdate"
Expand Down
10 changes: 2 additions & 8 deletions packages/typespec-autorest/test/arm/resources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,6 @@ it("allows action requests with optional body parameters", async () => {
movingStatus: string;
}

/** Create an optional request body parameter */
model OptionalBody<T extends {}> {
/** The request body */
@body body?: T;
}

interface Operations extends Azure.ResourceManager.Operations {}

@armResourceOperations
Expand All @@ -628,7 +622,7 @@ it("allows action requests with optional body parameters", async () => {
listBySubscription is ArmListBySubscription<Employee>;

/** A sample resource action that move employee to different location */
move is ArmResourceActionAsync<Employee, MoveRequest, MoveResponse, BodyParameter = OptionalBody<MoveRequest>>;
move is ArmResourceActionAsync<Employee, MoveRequest, MoveResponse, OptionalRequestBody = true>;

}
`);
Expand All @@ -643,7 +637,7 @@ it("allows action requests with optional body parameters", async () => {
deepStrictEqual(moveOperation.parameters[4], {
name: "body",
in: "body",
description: "The request body",
description: "The content of the action request",
required: false,
schema: {
$ref: "#/definitions/MoveRequest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ export type ArmResourcePropertiesOptionalityDecorator = (
isOptional: boolean,
) => void;

/**
* designates a parameter as an explicit bodyRoot and sets the optionality of the parameter
*/
export type ArmBodyRootDecorator = (
context: DecoratorContext,
target: ModelProperty,
isOptional: boolean,
) => void;

export type AzureResourceManagerPrivateDecorators = {
resourceParameterBaseFor: ResourceParameterBaseForDecorator;
resourceBaseParametersOf: ResourceBaseParametersOfDecorator;
Expand All @@ -166,4 +175,5 @@ export type AzureResourceManagerPrivateDecorators = {
enforceConstraint: EnforceConstraintDecorator;
armRenameListByOperation: ArmRenameListByOperationDecorator;
armResourcePropertiesOptionality: ArmResourcePropertiesOptionalityDecorator;
armBodyRoot: ArmBodyRootDecorator;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Azure.ResourceManager.Legacy;

using Http;
using Azure.ResourceManager.Foundations;
using Azure.ResourceManager.Private;
using Rest;

/**
Expand All @@ -26,7 +27,7 @@ interface LegacyOperations<
* @template LroHeaders Optional. Allows overriding the lro headers returned on resource create
* @template Parameters Optional. Additional parameters after the path parameters
* @template Response Optional. The success response(s) for the PUT operation
* @template BodyParam Optional. The request body parameter for this operation
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
@autoRoute
@doc("Create a {name}", Resource)
Expand All @@ -42,20 +43,20 @@ interface LegacyOperations<
Resource,
LroHeaders
>,
BodyParam extends {} = {@doc("Resource create parameters.") @bodyRoot body: Resource}
OptionalRequestBody extends valueof boolean = false
>(
...ParentParameters,
...ResourceTypeParameter,
...Parameters,
...BodyParam,
@doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) body: Resource,
): Response | ErrorType;

/**
* A synchronous resource CreateOrUpdate (PUT)
* @template Resource the resource being created or updated
* @template Parameters Optional. Additional parameters after the path parameters
* @template Response Optional. The success response(s) for the PUT operation
* @template BodyParam Optional. The request body parameter for this operation
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
#suppress "@azure-tools/typespec-azure-core/no-private-usage"
@autoRoute
Expand All @@ -66,12 +67,12 @@ interface LegacyOperations<
Resource extends Azure.ResourceManager.CommonTypes.Resource,
Parameters extends {} = {},
Response extends {} = ArmResourceUpdatedResponse<Resource> | ArmResourceCreatedSyncResponse<Resource>,
BodyParam extends {} = {@doc("Resource create parameters.") @bodyRoot body: Resource}
OptionalRequestBody extends valueof boolean = false
>(
...ParentParameters,
...ResourceTypeParameter,
...Parameters,
...BodyParam,
@doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) body: Resource,
): Response | ErrorType;

/**
Expand All @@ -81,7 +82,7 @@ interface LegacyOperations<
* @template LroHeaders Optional. Allows overriding the lro headers returned on resource create
* @template Parameters Optional. Additional parameters after the path parameters
* @template Response Optional. The success response(s) for the PATCH operation
* @template BodyParam Optional. The request body parameter for this operation
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
@autoRoute
@doc("Update a {name}", Resource)
Expand All @@ -101,12 +102,12 @@ interface LegacyOperations<
"Resource update request accepted.",
LroHeaders
>,
BodyParam extends {} = {@doc("Resource create parameters.") @bodyRoot body: PatchModel}
OptionalRequestBody extends valueof boolean = false
>(
...ParentParameters,
...ResourceTypeParameter,
...Parameters,
...BodyParam,
@doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) body: PatchModel,
): Response | ErrorType;

/**
Expand All @@ -115,7 +116,7 @@ interface LegacyOperations<
* @template PatchModel the PATCH request model
* @template Parameters Optional. Additional parameters after the path parameters
* @template Response Optional. The success response(s) for the PATCH operation
* @template BodyParam Optional. The request body parameter for this operation
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
@autoRoute
@doc("Update a {name}", Resource)
Expand All @@ -126,12 +127,12 @@ interface LegacyOperations<
PatchModel extends {} = Azure.ResourceManager.Foundations.TagsUpdateModel<Resource>,
Parameters extends {} = {},
Response extends {} = ArmResponse<Resource>,
BodyParam extends {} = {@doc("Resource create parameters.") @bodyRoot body: PatchModel}
OptionalRequestBody extends valueof boolean = false
>(
...ParentParameters,
...ResourceTypeParameter,
...Parameters,
...BodyParam,
@doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) body: PatchModel,
): Response | ErrorType;

/**
Expand Down Expand Up @@ -214,7 +215,7 @@ interface LegacyOperations<
* @template Request The request model for the action
* @template Response The response model for the action
* @template Parameters Optional. Additional parameters after the path parameters
* @template BodyParam Optional. The request body parameter for this operation
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
@doc("")
@autoRoute
Expand All @@ -227,16 +228,15 @@ interface LegacyOperations<
Request extends TypeSpec.Reflection.Model | void,
Response extends TypeSpec.Reflection.Model | void,
Parameters extends {} = {},
BodyParam = {
@doc("The content of the action request")
@bodyRoot
body: Request;
}
OptionalRequestBody extends valueof boolean = false
>(
...ParentParameters,
...ResourceTypeParameter,
...Parameters,
...BodyParam,

@doc("The content of the action request")
@armBodyRoot(OptionalRequestBody)
body: Request,
): Response | ErrorType;

/**
Expand All @@ -246,7 +246,7 @@ interface LegacyOperations<
* @template LroHeaders Optional. Allows overriding the headers returned in the Accepted response
* @template Response The response model for the action
* @template Parameters Optional. Additional parameters after the path parameters
* @template BodyParam Optional. The request body parameter for this operation
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
#suppress "@azure-tools/typespec-azure-core/no-response-body" "ARM"
@doc("")
Expand All @@ -270,16 +270,15 @@ interface LegacyOperations<
"Resource operation accepted.",
LroHeaders
> | Result,
BodyParam = {
@doc("The content of the action request")
@bodyRoot
body: Request;
}
OptionalRequestBody extends valueof boolean = false
>(
...ParentParameters,
...ResourceTypeParameter,
...Parameters,
...BodyParam,

@doc("The content of the action request")
@armBodyRoot(OptionalRequestBody)
body: Request,
): Response | ErrorType;
}
/**
Expand All @@ -299,7 +298,7 @@ model Provider<Resource extends {} = TenantActionScope> {
* @template Parameters Optional. Additional parameters after the path parameters
* @template Response Optional. The success response for the patch operation
* @template Error Optional. The error response, if non-standard.
* @template RequestBody Optional. ENables changing the name, documentation, or optionality of the request body parameter
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
@autoRoute
@doc("Update a {name}", Resource)
Expand All @@ -322,15 +321,13 @@ op CustomPatchAsync<
LroHeaders
>,
Error extends {} = ErrorResponse,
RequestBody extends {} = {
@doc("The resource properties to be updated.") @bodyRoot properties: PatchModel;
}
OptionalRequestBody extends valueof boolean = false
> is UpdateOperation<
ResourceInstanceParameters<Resource, BaseParameters> & Parameters,
PatchModel,
Response,
Error,
RequestBody
OptionalRequestBody
>;

/**
Expand All @@ -341,7 +338,7 @@ op CustomPatchAsync<
* @template Parameters Optional. Additional parameters after the path parameters
* @template Response Optional. The success response for the patch operation
* @template Error Optional. The error response, if non-standard.
* @template RequestBody Optional. ENables changing the name, documentation, or optionality of the request body parameter
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
@autoRoute
@doc("Update a {name}", Resource)
Expand All @@ -355,15 +352,13 @@ op CustomPatchSync<
Parameters extends {} = {},
Response extends {} = ArmResponse<Resource>,
Error extends {} = ErrorResponse,
RequestBody extends {} = {
@doc("The resource properties to be updated.") @bodyRoot properties: PatchModel;
}
OptionalRequestBody extends valueof boolean = false
> is UpdateOperation<
ResourceInstanceParameters<Resource, BaseParameters> & Parameters,
PatchModel,
Response,
Error,
RequestBody
OptionalRequestBody
>;

/**
Expand All @@ -372,14 +367,18 @@ op CustomPatchSync<
* @template BodyParameter The body parameter
* @template Response The response or union of responses for success.
* @template ErrorResponse The error response.
* @template RequestBody Optional. ENables changing the name, documentation, or optionality of the request body parameter
* @template OptionalRequestBody Optional. Indicates whether the request body is optional
*/
op UpdateOperation<
HttpParameters extends {},
BodyParameter extends {},
Response extends {},
ErrorResponse extends {},
RequestBody extends {} = {
@doc("The resource properties to be updated.") @bodyRoot properties: BodyParameter;
}
>(...HttpParameters, ...RequestBody): Response | ErrorResponse;
OptionalRequestBody extends valueof boolean = false
>(
...HttpParameters,

@doc("The resource properties to be updated.")
@armBodyRoot(OptionalRequestBody)
properties: BodyParameter,
): Response | ErrorResponse;
Loading
Loading