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

tsp, migrate tcgc getHttpOperationExamples #2882

Merged

Conversation

weidongxu-microsoft
Copy link
Member

No description provided.

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All change in this file is the delete of code that no longer needed (as TCGC now provide this functionality).

Comment on lines 709 to 720
private getOperationExample(operation: Operation): any | undefined {
if (operation.projectionSource?.kind === "Operation") {
// always use the projectionSource, if available
operation = operation.projectionSource;
}
let operationExample = this.operationExamples.get(operation);
if (!operationExample && operation.sourceOperation) {
// if the operation is customized in client.tsp, the operation would be different from that of main.tsp
// try the operation.sourceOperation
operation = operation.sourceOperation;
if (operation.projectionSource?.kind === "Operation") {
operation = operation.projectionSource;
private getOperationExample(operation: HttpOperation): Record<string, any> | undefined {
const httpOperationExamples = getHttpOperationExamples(this.sdkContext, operation);
if (httpOperationExamples && httpOperationExamples.length > 0) {
const operationExamples: Record<string, any> = {};
for (const example of httpOperationExamples) {
const operationExample = example.rawExample;
operationExample["x-ms-original-file"] = pathToFileURL(example.filePath).toString();
operationExamples[operationExample.title ?? operationExample.operationId ?? operation.operation.name] = operationExample;
}
operationExample = this.operationExamples.get(operation);
return operationExamples;
} else {
return undefined;
}
return operationExample;
}
Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most logic is same before/after the change.

One change is to make it directly return a Record that can be plugged in "x-ms-examples"

Also a fix that previously we seems only take 1 example per operation.

@weidongxu-microsoft weidongxu-microsoft marked this pull request as ready for review July 30, 2024 09:30
for (const example of httpOperationExamples) {
const operationExample = example.rawExample;
operationExample["x-ms-original-file"] = pathToFileURL(example.filePath).toString();
operationExamples[operationExample.title ?? operationExample.operationId ?? operation.operation.name] =
Copy link
Contributor

@XiaofeiCao XiaofeiCao Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe the operation.operation.name can be removed, as TCGC will ensure either title or operationId:
https://github.com/Azure/typespec-azure/blob/main/packages/typespec-client-generator-core/src/example.ts#L88

Copy link
Member Author

@weidongxu-microsoft weidongxu-microsoft Jul 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rawExample is type any, so we don't have any constraint on type of this behavior. Guess having a last fallback is not bad.

Though I am actually relying on their logic on avoiding duplicate title.
https://github.com/Azure/typespec-azure/pull/1076/files#diff-d276532a6e7d2da177119679a7dfdc92a59980b7bbb70000f99ad0e4d50f3183R180

@weidongxu-microsoft weidongxu-microsoft merged commit ba277b4 into Azure:main Jul 31, 2024
3 checks passed
@weidongxu-microsoft weidongxu-microsoft deleted the tsp_migrate-tcgc-examples branch July 31, 2024 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants