Skip to content

Commit 3592d60

Browse files
pshao25Pan Shao
andauthored
Change legacy operations from interface to alias (#5150)
Co-authored-by: Pan Shao <pashao@microsoft.com>
1 parent d0880a2 commit 3592d60

19 files changed

Lines changed: 1021 additions & 1090 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@autorest/openapi-to-typespec",
5+
"comment": "legacy operation from interface to alias",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@autorest/openapi-to-typespec"
10+
}

packages/extensions/openapi-to-typespec/src/generate/generate-arm-resource.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,12 @@ function generateArmResourceOperationGroup(
112112
const definitions: string[] = [];
113113

114114
if (operationGroup.isLegacy) {
115-
definitions.push("@armResourceOperations");
116115
definitions.push(
117-
`interface ${
116+
`alias ${
118117
operationGroup.legacyOperationGroup!.interfaceName
119-
} extends Azure.ResourceManager.Legacy.${operationGroup.legacyOperationGroup?.type === "Normal" ? "LegacyOperations" : "ExtensionOperations"}<{${operationGroup.legacyOperationGroup!.targetParentParameters.join(
118+
} = Azure.ResourceManager.Legacy.${operationGroup.legacyOperationGroup?.type === "Normal" ? "LegacyOperations" : "ExtensionOperations"}<{${operationGroup.legacyOperationGroup!.targetParentParameters.join(
120119
";",
121-
)}}, ${operationGroup.legacyOperationGroup?.type === "Normal" ? "" : `{${operationGroup.legacyOperationGroup!.extensionParentParameters!.join(";")}},`}{${operationGroup.legacyOperationGroup!.instanceParameters.join(";")}}> {}`,
120+
)}}, ${operationGroup.legacyOperationGroup?.type === "Normal" ? "" : `{${operationGroup.legacyOperationGroup!.extensionParentParameters!.join(";")}},`}{${operationGroup.legacyOperationGroup!.instanceParameters.join(";")}}>;`,
122121
);
123122
definitions.push("\n");
124123
}

packages/extensions/openapi-to-typespec/test/arm-apimanagement/tsp-output/DiagnosticContract.tsp

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,35 @@ model DiagnosticContract
2525
>;
2626
}
2727

28-
@armResourceOperations
29-
interface DiagnosticContractOps
30-
extends Azure.ResourceManager.Legacy.LegacyOperations<
31-
{
32-
...ApiVersionParameter,
33-
...SubscriptionIdParameter,
34-
...ResourceGroupParameter,
35-
...Azure.ResourceManager.Legacy.Provider,
28+
alias DiagnosticContractOps = Azure.ResourceManager.Legacy.LegacyOperations<
29+
{
30+
...ApiVersionParameter;
31+
...SubscriptionIdParameter;
32+
...ResourceGroupParameter;
33+
...Azure.ResourceManager.Legacy.Provider;
3634

37-
/** The name of the API Management service. */
38-
@path
39-
@segment("service")
40-
@key
41-
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
42-
serviceName: string,
35+
/** The name of the API Management service. */
36+
@path
37+
@segment("service")
38+
@key
39+
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
40+
serviceName: string;
4341

44-
/** API identifier. Must be unique in the current API Management service instance. */
45-
@path
46-
@segment("apis")
47-
@key
48-
apiId: string,
49-
},
50-
{
51-
/** Diagnostic identifier. Must be unique in the current API Management service instance. */
52-
@path
53-
@segment("diagnostics")
54-
@key
55-
@pattern("^[^*#&+:<>?]+$")
56-
diagnosticId: string,
57-
}
58-
> {}
42+
/** API identifier. Must be unique in the current API Management service instance. */
43+
@path
44+
@segment("apis")
45+
@key
46+
apiId: string;
47+
},
48+
{
49+
/** Diagnostic identifier. Must be unique in the current API Management service instance. */
50+
@path
51+
@segment("diagnostics")
52+
@key
53+
@pattern("^[^*#&+:<>?]+$")
54+
diagnosticId: string;
55+
}
56+
>;
5957

6058
@armResourceOperations
6159
interface DiagnosticContracts {
@@ -140,31 +138,29 @@ interface DiagnosticContracts {
140138
}
141139
>;
142140
}
143-
@armResourceOperations
144-
interface DiagnosticOps
145-
extends Azure.ResourceManager.Legacy.LegacyOperations<
146-
{
147-
...ApiVersionParameter,
148-
...SubscriptionIdParameter,
149-
...ResourceGroupParameter,
150-
...Azure.ResourceManager.Legacy.Provider,
141+
alias DiagnosticOps = Azure.ResourceManager.Legacy.LegacyOperations<
142+
{
143+
...ApiVersionParameter;
144+
...SubscriptionIdParameter;
145+
...ResourceGroupParameter;
146+
...Azure.ResourceManager.Legacy.Provider;
151147

152-
/** The name of the API Management service. */
153-
@path
154-
@segment("service")
155-
@key
156-
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
157-
serviceName: string,
158-
},
159-
{
160-
/** Diagnostic identifier. Must be unique in the current API Management service instance. */
161-
@path
162-
@segment("diagnostics")
163-
@key
164-
@pattern("^[^*#&+:<>?]+$")
165-
diagnosticId: string,
166-
}
167-
> {}
148+
/** The name of the API Management service. */
149+
@path
150+
@segment("service")
151+
@key
152+
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
153+
serviceName: string;
154+
},
155+
{
156+
/** Diagnostic identifier. Must be unique in the current API Management service instance. */
157+
@path
158+
@segment("diagnostics")
159+
@key
160+
@pattern("^[^*#&+:<>?]+$")
161+
diagnosticId: string;
162+
}
163+
>;
168164

169165
@armResourceOperations
170166
interface Diagnostic {

packages/extensions/openapi-to-typespec/test/arm-apimanagement/tsp-output/IssueContract.tsp

Lines changed: 52 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,35 @@ model IssueContract
2525
>;
2626
}
2727

28-
@armResourceOperations
29-
interface IssueContractOps
30-
extends Azure.ResourceManager.Legacy.LegacyOperations<
31-
{
32-
...ApiVersionParameter,
33-
...SubscriptionIdParameter,
34-
...ResourceGroupParameter,
35-
...Azure.ResourceManager.Legacy.Provider,
36-
37-
/** The name of the API Management service. */
38-
@path
39-
@segment("service")
40-
@key
41-
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
42-
serviceName: string,
43-
44-
/** API identifier. Must be unique in the current API Management service instance. */
45-
@path
46-
@segment("apis")
47-
@key
48-
apiId: string,
49-
},
50-
{
51-
/** Issue identifier. Must be unique in the current API Management service instance. */
52-
@path
53-
@segment("issues")
54-
@key
55-
@pattern("^[^*#&+:<>?]+$")
56-
issueId: string,
57-
}
58-
> {}
28+
alias IssueContractOps = Azure.ResourceManager.Legacy.LegacyOperations<
29+
{
30+
...ApiVersionParameter;
31+
...SubscriptionIdParameter;
32+
...ResourceGroupParameter;
33+
...Azure.ResourceManager.Legacy.Provider;
34+
35+
/** The name of the API Management service. */
36+
@path
37+
@segment("service")
38+
@key
39+
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
40+
serviceName: string;
41+
42+
/** API identifier. Must be unique in the current API Management service instance. */
43+
@path
44+
@segment("apis")
45+
@key
46+
apiId: string;
47+
},
48+
{
49+
/** Issue identifier. Must be unique in the current API Management service instance. */
50+
@path
51+
@segment("issues")
52+
@key
53+
@pattern("^[^*#&+:<>?]+$")
54+
issueId: string;
55+
}
56+
>;
5957

6058
@armResourceOperations
6159
interface IssueContracts {
@@ -155,31 +153,29 @@ interface IssueContracts {
155153
}
156154
>;
157155
}
158-
@armResourceOperations
159-
interface IssueOps
160-
extends Azure.ResourceManager.Legacy.LegacyOperations<
161-
{
162-
...ApiVersionParameter,
163-
...SubscriptionIdParameter,
164-
...ResourceGroupParameter,
165-
...Azure.ResourceManager.Legacy.Provider,
166-
167-
/** The name of the API Management service. */
168-
@path
169-
@segment("service")
170-
@key
171-
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
172-
serviceName: string,
173-
},
174-
{
175-
/** Issue identifier. Must be unique in the current API Management service instance. */
176-
@path
177-
@segment("issues")
178-
@key
179-
@pattern("^[^*#&+:<>?]+$")
180-
issueId: string,
181-
}
182-
> {}
156+
alias IssueOps = Azure.ResourceManager.Legacy.LegacyOperations<
157+
{
158+
...ApiVersionParameter;
159+
...SubscriptionIdParameter;
160+
...ResourceGroupParameter;
161+
...Azure.ResourceManager.Legacy.Provider;
162+
163+
/** The name of the API Management service. */
164+
@path
165+
@segment("service")
166+
@key
167+
@pattern("^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$")
168+
serviceName: string;
169+
},
170+
{
171+
/** Issue identifier. Must be unique in the current API Management service instance. */
172+
@path
173+
@segment("issues")
174+
@key
175+
@pattern("^[^*#&+:<>?]+$")
176+
issueId: string;
177+
}
178+
>;
183179

184180
@armResourceOperations
185181
interface Issue {

0 commit comments

Comments
 (0)