Resolving Swagger Breaking Change Violations
The Swagger Converter will not be able to accurately represent every part of every API in TypeSpec. This document
outlines some common changes you might need to make to a converted TypeSpec to make it conform to your existing service API and
pass check-in validations.
Migrate ARM Specs
Section titled āMigrate ARM SpecsāChanging the Names of Request Payload Parameters
Section titled āChanging the Names of Request Payload ParametersāFor operations with non-empty request bodies (PUT, POST, PATCH), the TypeSpec operation templates provide a default name for the request parameter corresponding to the request payload. You can use augment decorators to make changes to this parameter, and other parts of the operation signature.
The following sections show how to do this for each operation template.
CreateOrUpdate (PUT) APIs
Section titled āCreateOrUpdate (PUT) APIsāGiven a PUT operation, for example:
interface Widgets { createOrUpdate is ArmResourceCreateOrReplaceAsync<Widget>;}
The name of the request body parameter is resource
so you can change the name in clients using an augment decorator
@@clientName(Widgets.createOrUpdate::parameters.resource, "<desired-request-body-parameter-name>");
Note that this works for any PUT operation template.
Update (PATCH) APIs
Section titled āUpdate (PATCH) APIsāGiven a PATCH operation, for example:
interface Widgets { update is ArmResourcePatchAsync<Widget, WidgetProperties>;}
The name of the request body parameter is properties
so you can change the name in clients using an augment decorator
@@clientName(Widgets.update::parameters.properties, "<desired-request-body-parameter-name>");
Note that this works for any PATCH operation template.
Action (POST) APIs
Section titled āAction (POST) APIsāGiven a POST operation, for example:
interface Widgets { mungeWidget is ArmResourceActionAsync<Widget, MungeRequest, MungeResponse>;}
The name of the request body parameter is body
so you can change the name in clients using an augment decorator
@@clientName(Widgets.mungeWidget::parameters.body, "<desired-request-body-parameter-name>");
Note that this works for any POST operation template.
Adding Request Query or Header Parameters
Section titled āAdding Request Query or Header ParametersāThe Parameters
template parameter allows you to specify additional parameters after the operation path (for example, query and header parameters) in the form of a model, with each model property corresponding to a parameter. You may use intersection to combine multiple separate parameters.
// all list query paramsop listBySubscription is ArmListBySubscription< Widget, Parameters = Azure.Core.StandardListQueryParameters>;
// intersecting individual parametersop listBySubscription is ArmListBySubscription< Widget, Parameters = Azure.Core.TopQueryParameter & Azure.Core.SkipQueryParameter>;
Changing Response Types
Section titled āChanging Response TypesāThe Response
parameter allows you to specify non-error responses to the operation.
// all list query paramsop listBySubscription is ArmListBySubscription<Widget, Response = MyCustomCollectionType>;
Changing Error Types
Section titled āChanging Error TypesāThe Error
parameter allows you to change the default error type used in an operation.
// all list query paramsop listBySubscription is ArmListBySubscription<Widget, Error = MyCustomError>;
Converting Synchronous Operations to LROs
Section titled āConverting Synchronous Operations to LROsāYou can generally choose an asynchronous operation template that matches your operation.
Templates for Async PUT Operations
Section titled āTemplates for Async PUT Operationsā-
ArmCreateOrReplaceAsync
is a PUT operation that uses the āresourceā definition in the request body, and return a200
response and a201
response, both of which contain the created/updated resource in the response payload. The 201 response contains āLocation` LRO header.op createOrUpdate is ArmCreateOrReplaceAsync<Resource>; -
ArmCreateOrUpdateAsync
is a PUT operation that uses the āresourceā definition in the request body, and return a200
response and a201
response, both of which contain the created/updated resource in the response payload. The 201 response contains āAzure-AsyncOperation` LRO header.op createOrUpdate is ArmCreateOrUpdateAsync<Resource>;
Templates for Async PATCH Operations
Section titled āTemplates for Async PATCH Operationsā-
ArmTagsPatchAsync
is a PATCH operation that only allows changing the resource tags (the minimum for Azure Resource Manager).op update is ArmTagsPatchAsync<Resource>; -
ArmResourcePatchAsync
is a PATCH operation that uses the visibility settings to select properties for the PATCH request body(any property with no visibility setting, or including visibility āupdateā). It follows the required 202 pattern to resolve the LRO via location, although this can be customized using theLroHeaders
parameter.op update is ArmResourcePatchAsync<Resource, ResourceProperties>; -
ArmCustomPatchAsync
is a PATCH operation that allows you to customize the PATCH request body.op update is ArmCustomPatchAsync<Resource, PatchRequestBody>;
Templates for Async POST (Action) Operations
Section titled āTemplates for Async POST (Action) Operationsā-
ArmResourceActionAsync
is a POST operation that allows you to specify the request and response body for a resource action operation. It follows the required 202 pattern to resolve the LRO via location, although this can be customized using theLroHeaders
parameter.op doStuff is ArmResourceActionAsync<Resource, ActionRequest, ActionResponse>;// with no request bodyop doStuffNoRequest is ArmResourceActionAsync<Resource, void, ActionResponse>;// with no response bodyop doStuffCommand is ArmResourceActionAsync<Resource, ActionRequest, void>;
Templates for Async DELETE Operations
Section titled āTemplates for Async DELETE Operationsā-
ArmResourceDeleteWithoutOKAsync
is a DELETE operation that uses no request body, will return a202
response in the case of an Asynchronous delete operation, and a204
response in case the resource does not exist.op delete is ArmResourceDeleteWithoutOKAsync<Resource>; -
ArmResourceDeleteAsync
iis a DELETE operation that uses no request body, and return a200
response in the case of a successful synchronous delete, a202
response in the case of an Asynchronous delete operation, and a204
response in case the resource does not exist.op createOrUpdate is ArmResourceDeleteAsync<Resource>;