Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Align the client type shape from TCGC in our emitter #6179

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update accordingly, but operations we left empty
  • Loading branch information
ArcturusZhang committed Mar 3, 2025
commit 6b30f7ee0f66e433a286b55389b97e80055cd8e1
1 change: 1 addition & 0 deletions packages/http-client-csharp/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@ export async function $onEmit(context: EmitContext<CSharpEmitterOptions>) {
logger: logger,
__typeCache: {
crossLanguageDefinitionIds: new Map(),
clients: new Map(),
types: new Map(),
models: new Map(),
enums: new Map(),
72 changes: 72 additions & 0 deletions packages/http-client-csharp/emitter/src/lib/client-converter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import { SdkClientType as SdkClientTypeOfT, SdkHttpOperation } from "@azure-tools/typespec-client-generator-core";
import { CSharpEmitterContext } from "../sdk-context.js";
import { InputClientType } from "../type/input-type.js";

type SdkClientType = SdkClientTypeOfT<SdkHttpOperation>;

export function fromSdkClients(
sdkContext: CSharpEmitterContext,
clients: SdkClientType[],
): InputClientType[] {
const inputClients: InputClientType[] = [];
for (const client of clients) {
const inputClient = fromSdkClient(sdkContext, client);
inputClients.push(inputClient);
}

return inputClients;
}

function fromSdkClient(sdkContext: CSharpEmitterContext, client: SdkClientType): InputClientType {
let inputClient: InputClientType | undefined = sdkContext.__typeCache.clients.get(client);
if (inputClient) {
return inputClient;
}

inputClient = {
kind: "client",
name: client.name,
namespace: client.namespace,
doc: client.doc,
summary: client.summary,
operations: [],
apiVersions: client.apiVersions,
crossLanguageDefinitionId: client.crossLanguageDefinitionId,
parent: undefined,
children: undefined,
};

updateSdkClientTypeReferences(sdkContext, client, inputClient);

// fill operations - TODO
// fill parent
if (client.parent) {
const parent = fromSdkClient(sdkContext, client.parent);
inputClient.parent = parent;
}
// fill children
if (client.children) {
const children: InputClientType[] = [];
for (const child of client.children) {
children.push(fromSdkClient(sdkContext, child));
}
inputClient.children = children;
}

return inputClient;
}

function updateSdkClientTypeReferences(
sdkContext: CSharpEmitterContext,
sdkClient: SdkClientType,
inputClient: InputClientType,
) {
sdkContext.__typeCache.clients.set(sdkClient, inputClient);
sdkContext.__typeCache.crossLanguageDefinitionIds.set(
sdkClient.crossLanguageDefinitionId,
sdkClient.__raw.type,
);
}
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.