Skip to content

Commit 508f7f7

Browse files
pshao25Pan Shao
andauthored
File structure change for brownfield services (#5098)
Co-authored-by: Pan Shao <pashao@microsoft.com>
1 parent 50519f7 commit 508f7f7

48 files changed

Lines changed: 194 additions & 170 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
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": "File structure for brownfield services",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@autorest/openapi-to-typespec"
10+
}

packages/extensions/openapi-to-typespec/src/emiters/emit-client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ export async function emitClient(filePath: string, program: TypespecProgram): Pr
2121
}
2222

2323
function generateClient(program: TypespecProgram) {
24-
const { isArm } = getOptions();
24+
const { isArm, isFullCompatible } = getOptions();
2525
const { models } = program;
2626
const { modules, namespaces: namespacesSet } = getClientImports(program);
27-
const imports = [...new Set<string>([`import "./main.tsp";`, ...modules])].join("\n");
27+
const imports = (
28+
isFullCompatible ? [...new Set<string>([...modules])] : [...new Set<string>([`import "./main.tsp";`, ...modules])]
29+
).join("\n");
2830

2931
const namespaces = [...new Set<string>([...namespacesSet, `using ${getNamespace(program)};`])].join("\n");
3032
const objects = models.objects

packages/extensions/openapi-to-typespec/src/emiters/emit-main.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,29 @@ function getServiceInformation(program: TypespecProgram) {
6262
}
6363

6464
function getArmServiceInformation(program: TypespecProgram, metadata: Metadata) {
65+
const { isFullCompatible } = getOptions();
6566
const imports = [
6667
`import "@typespec/rest";`,
6768
`import "@typespec/versioning";`,
6869
`import "@azure-tools/typespec-azure-core";`,
6970
`import "@azure-tools/typespec-azure-resource-manager";`,
7071
`import "./models.tsp";`,
71-
...getArmResourceImports(program, metadata),
72-
``,
73-
`using TypeSpec.Rest;`,
74-
`using TypeSpec.Http;`,
75-
`using Azure.ResourceManager.Foundations;`,
76-
`using Azure.Core;`,
77-
`using Azure.ResourceManager;`,
78-
`using TypeSpec.Versioning;`,
7972
];
73+
if (isFullCompatible) {
74+
imports.push(`import "./back-compatible.tsp";`);
75+
}
76+
imports.push(
77+
...[
78+
...getArmResourceImports(program, metadata),
79+
``,
80+
`using TypeSpec.Rest;`,
81+
`using TypeSpec.Http;`,
82+
`using Azure.ResourceManager.Foundations;`,
83+
`using Azure.Core;`,
84+
`using Azure.ResourceManager;`,
85+
`using TypeSpec.Versioning;`,
86+
],
87+
);
8088
const content = generateServiceInformation(program);
8189

8290
return [...imports, content].join("\n");

packages/extensions/openapi-to-typespec/src/emiters/emit-typespec-config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export async function emitTypespecConfig(filePath: string, programDetails: Types
3838
- '@azure-tools/typespec-autorest'
3939
options:
4040
'@azure-tools/typespec-autorest':
41-
use-read-only-status-schema: true
4241
omit-unreachable-types: true
4342
emitter-output-dir: "{project-root}/.."
4443
azure-resource-provider-folder: "resource-manager"

packages/extensions/openapi-to-typespec/src/generate/generate-client.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ export function generateArmResourceClientDecorator(resource: TspArmResource): st
4343
const definitions: string[] = [];
4444

4545
const formalOperationGroupName = pluralize(resource.name);
46-
let targetName = formalOperationGroupName;
47-
48-
if (resource.name === formalOperationGroupName) {
49-
targetName = `${formalOperationGroupName}OperationGroup}`;
50-
definitions.push(`@@clientName(${formalOperationGroupName}OperationGroup, "${formalOperationGroupName}")`);
51-
}
46+
const targetName = formalOperationGroupName;
5247

5348
if (resource.clientDecorators && resource.clientDecorators.length > 0)
5449
definitions.push(generateAugmentedDecorators(resource.name, resource.clientDecorators));

packages/extensions/openapi-to-typespec/src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function processConverter(host: AutorestExtensionHost) {
3232
setSession(session);
3333
const codeModel = session.model;
3434
pretransformNames(codeModel);
35-
const { isArm } = getOptions();
35+
const { isArm, isFullCompatible } = getOptions();
3636
let metadata: Metadata | undefined = undefined;
3737
if (isArm) {
3838
// await host.writeFile({ filename: "codeModel.yaml", content: serialize(codeModel, codeModelSchema) });
@@ -55,7 +55,7 @@ export async function processConverter(host: AutorestExtensionHost) {
5555
await emitMain(programDetails, metadata, getOutuptDirectory(session));
5656
await emitPackage(getFilePath(session, "package.json"), programDetails);
5757
await emitTypespecConfig(getFilePath(session, "tspconfig.yaml"), programDetails);
58-
await emitClient(getFilePath(session, "client.tsp"), programDetails);
58+
await emitClient(getFilePath(session, isFullCompatible ? "back-compatible.tsp" : "client.tsp"), programDetails);
5959
if (metadata && Object.keys(metadata.Resources).find((key) => metadata!.Resources[key].length > 1)) {
6060
await emitLegacy(getFilePath(session, "legacy.tsp"));
6161
}

packages/extensions/openapi-to-typespec/test/arm-agrifood/swagger-output/swagger.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@
630630
"pattern": "^[A-Za-z0-9]+(-[A-Za-z0-9]+)*$"
631631
},
632632
{
633-
"name": "resource",
633+
"name": "request",
634634
"in": "body",
635635
"description": "Data Manager For Agriculture resource create or update request object.",
636636
"required": true,
@@ -692,7 +692,7 @@
692692
"pattern": "^[A-Za-z0-9]+(-[A-Za-z0-9]+)*$"
693693
},
694694
{
695-
"name": "properties",
695+
"name": "request",
696696
"in": "body",
697697
"description": "Request object.",
698698
"required": true,
@@ -953,7 +953,7 @@
953953
"maxLength": 63
954954
},
955955
{
956-
"name": "resource",
956+
"name": "body",
957957
"in": "body",
958958
"description": "Body must be valid DataConnector request.",
959959
"required": true,
@@ -1226,7 +1226,7 @@
12261226
"type": "string"
12271227
},
12281228
{
1229-
"name": "resource",
1229+
"name": "requestBody",
12301230
"in": "body",
12311231
"description": "Extension resource request body.",
12321232
"required": true,
@@ -1448,7 +1448,7 @@
14481448
"type": "string"
14491449
},
14501450
{
1451-
"name": "resource",
1451+
"name": "request",
14521452
"in": "body",
14531453
"description": "Request object.",
14541454
"required": true,
@@ -1903,7 +1903,7 @@
19031903
"pattern": "^[a-zA-Z]{3,50}[.][a-zA-Z]{3,100}$"
19041904
},
19051905
{
1906-
"name": "resource",
1906+
"name": "requestBody",
19071907
"in": "body",
19081908
"description": "Solution resource request body.",
19091909
"required": true,
@@ -2259,7 +2259,8 @@
22592259
},
22602260
"$skipToken": {
22612261
"type": "string",
2262-
"description": "Token used in retrieving the next page. If null, there are no additional pages."
2262+
"description": "Token used in retrieving the next page. If null, there are no additional pages.",
2263+
"x-ms-client-name": "skipToken"
22632264
}
22642265
},
22652266
"required": [
@@ -2358,7 +2359,8 @@
23582359
},
23592360
"$skipToken": {
23602361
"type": "string",
2361-
"description": "Token used in retrieving the next page. If null, there are no additional pages."
2362+
"description": "Token used in retrieving the next page. If null, there are no additional pages.",
2363+
"x-ms-client-name": "skipToken"
23622364
}
23632365
},
23642366
"required": [
@@ -2432,7 +2434,8 @@
24322434
},
24332435
"$skipToken": {
24342436
"type": "string",
2435-
"description": "Token used in retrieving the next page. If null, there are no additional pages."
2437+
"description": "Token used in retrieving the next page. If null, there are no additional pages.",
2438+
"x-ms-client-name": "skipToken"
24362439
}
24372440
},
24382441
"required": [
@@ -2634,7 +2637,8 @@
26342637
},
26352638
"$skipToken": {
26362639
"type": "string",
2637-
"description": "Token used in retrieving the next page. If null, there are no additional pages."
2640+
"description": "Token used in retrieving the next page. If null, there are no additional pages.",
2641+
"x-ms-client-name": "skipToken"
26382642
}
26392643
},
26402644
"required": [
@@ -2872,8 +2876,7 @@
28722876
"value": "Failed"
28732877
}
28742878
]
2875-
},
2876-
"readOnly": true
2879+
}
28772880
},
28782881
"PrivateEndpointServiceConnectionStatus": {
28792882
"type": "string",
@@ -3015,8 +3018,7 @@
30153018
"value": "Running"
30163019
}
30173020
]
3018-
},
3019-
"readOnly": true
3021+
}
30203022
},
30213023
"PublicNetworkAccess": {
30223024
"type": "string",
@@ -3098,7 +3100,8 @@
30983100
},
30993101
"$skipToken": {
31003102
"type": "string",
3101-
"description": "Token used in retrieving the next page. If null, there are no additional pages."
3103+
"description": "Token used in retrieving the next page. If null, there are no additional pages.",
3104+
"x-ms-client-name": "skipToken"
31023105
}
31033106
},
31043107
"required": [

packages/extensions/openapi-to-typespec/test/arm-agrifood/tsp-output/client.tsp renamed to packages/extensions/openapi-to-typespec/test/arm-agrifood/tsp-output/back-compatible.tsp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import "./main.tsp";
21
import "@azure-tools/typespec-client-generator-core";
32

43
using Azure.ClientGenerator.Core;

packages/extensions/openapi-to-typespec/test/arm-agrifood/tsp-output/main.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import "@typespec/versioning";
1212
import "@azure-tools/typespec-azure-core";
1313
import "@azure-tools/typespec-azure-resource-manager";
1414
import "./models.tsp";
15+
import "./back-compatible.tsp";
1516
import "./DataConnector.tsp";
1617
import "./DataManagerForAgricultureExtension.tsp";
1718
import "./DataManagerForAgriculture.tsp";

packages/extensions/openapi-to-typespec/test/arm-agrifood/tsp-output/tspconfig.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ emit:
22
- "@azure-tools/typespec-autorest"
33
options:
44
"@azure-tools/typespec-autorest":
5-
use-read-only-status-schema: true
65
omit-unreachable-types: true
76
emitter-output-dir: "{project-root}/.."
87
azure-resource-provider-folder: "resource-manager"

0 commit comments

Comments
 (0)