-
Notifications
You must be signed in to change notification settings - Fork 82
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
tsp, migrate tcgc getHttpOperationExamples #2882
Conversation
There was a problem hiding this comment.
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).
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; | ||
} |
There was a problem hiding this comment.
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.
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] = |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
No description provided.