Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

Refine diagnostic for LRO and paging metadata generation.
9 changes: 5 additions & 4 deletions packages/typespec-client-generator-core/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function getSdkPagingServiceMethod<TServiceOperation extends SdkServiceOperation
} else {
const markAsPageableInfo = getMarkAsPageable(context, operation);
if (markAsPageableInfo) {
const itemsProperty = ignoreDiagnostics(
const itemsProperty = diagnostics.pipe(
getSdkModelPropertyType(context, markAsPageableInfo.itemsProperty, operation),
);
// tcgc will let all paging method return a list of items
Expand Down Expand Up @@ -454,9 +454,9 @@ function getServiceMethodLroMetadata<TServiceOperation extends SdkServiceOperati
return {
kind: "pollingSuccessProperty",
responseModel: getSdkModel(context, step.responseModel),
target: ignoreDiagnostics(getSdkModelPropertyType(context, step.target)),
target: diagnostics.pipe(getSdkModelPropertyType(context, step.target)),
sourceProperty: step.sourceProperty
? ignoreDiagnostics(getSdkModelPropertyType(context, step.sourceProperty))
? diagnostics.pipe(getSdkModelPropertyType(context, step.sourceProperty))
: undefined,
};
}
Expand Down Expand Up @@ -515,7 +515,8 @@ function getServiceMethodLroMetadata<TServiceOperation extends SdkServiceOperati
}
return {
kind: "reference",
operation: diagnostics.pipe(getSdkBasicServiceMethod(context, reference.operation, client))
// since these operations may not be included in the client customization, we ignore diagnostics here
operation: ignoreDiagnostics(getSdkBasicServiceMethod(context, reference.operation, client))
.operation,
parameterMap: reference.parameterMap,
parameters,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1235,3 +1235,71 @@ describe("getLroMetadata", () => {
);
});
});

it("versioned LRO with customization", async () => {
const runnerWithCore = await createSdkTestRunner({
librariesToAdd: [AzureCoreTestLibrary],
autoUsings: ["Azure.Core", "Azure.Core.Traits"],
emitterName: "@azure-tools/typespec-java",
});
await runnerWithCore.compileWithCustomization(
`
@service
@versioned(Versions)
namespace TestService;

enum Versions {
v1,
v2,
}

alias TestOperations = ResourceOperations<NoConditionalRequests & NoClientRequestId & NoRepeatableRequests>;

@resource("id")
model TestResult {
@key
id: string;

@lroStatus
status: JobStatus;
}

@lroStatus
union JobStatus {
string,
NotStarted: "notStarted",
Running: "running",

@lroSucceeded
Succeeded: "succeeded",

@lroFailed
Failed: "failed",

Canceled: "canceled",
}

@get
op get is TestOperations.ResourceRead<TestResult>;

@pollingOperation(get)
op create is TestOperations.LongRunningResourceCreateOrReplace<TestResult>;
`,
`
@client({
service: TestService,
})
namespace TestClient;

op test is TestService.create;
`,
);
strictEqual(runnerWithCore.context.diagnostics.length, 0);
const client = runnerWithCore.context.sdkPackage.clients[0];
strictEqual(client.methods.length, 1);
const method = client.methods[0];
strictEqual(method.name, "test");
strictEqual(method.kind, "lro");
const lroMetadata = method.lroMetadata;
ok(lroMetadata);
});
Loading