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
7 changes: 7 additions & 0 deletions packages/azure-http-specs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @azure-tools/azure-http-specs

## 0.1.0-alpha.36

### Bug Fixes

- [#3770](https://github.com/Azure/typespec-azure/pull/3770) Fix missing api-version in nextLink of lropaging test scenario.


## 0.1.0-alpha.35

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/azure-http-specs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/azure-http-specs",
"version": "0.1.0-alpha.35",
"version": "0.1.0-alpha.36",
"description": "Azure Spec scenarios and mock apis",
"main": "dist/index.js",
"type": "module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ Scenarios.Azure_ResourceManager_OperationTemplates_LroPaging_postPagingLro = pas
if (postPagingLroPollCount > 0) {
const response = {
...validProductListResult,
nextLink: `${req.baseUrl}/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/providers/Azure.ResourceManager.OperationTemplates/locations/eastus/operations/lro_paging_post_location/nextPage`,
nextLink: `${req.baseUrl}/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/providers/Azure.ResourceManager.OperationTemplates/locations/eastus/operations/lro_paging_post_location/nextPage?api-version=2023-12-01-preview`,
};
return {
status: 200,
Expand Down
8 changes: 8 additions & 0 deletions packages/typespec-client-generator-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Change Log - @azure-tools/typespec-client-generator-core

## 0.64.1

### Bug Fixes

- [#3767](https://github.com/Azure/typespec-azure/pull/3767) Fix enum type exclusion in protocol methods when `@convenientAPI(false)`.
- [#3768](https://github.com/Azure/typespec-azure/pull/3768) Refine diagnostic for LRO and paging metadata generation.


## 0.64.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-client-generator-core",
"version": "0.64.0",
"version": "0.64.1",
"author": "Microsoft Corporation",
"description": "TypeSpec Data Plane Generation library",
"homepage": "https://azure.github.io/typespec-azure",
Expand Down
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
6 changes: 3 additions & 3 deletions packages/typespec-client-generator-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,9 @@ function updateTypesFromOperation(
for (const param of httpOperation.parameters.parameters) {
if (isNeverOrVoidType(param.param.type)) continue;
const sdkType = diagnostics.pipe(getClientTypeWithDiagnostics(context, param.param, operation));
if (generateConvenient) {
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.Input, sdkType));
}
// Always update input usage for HTTP operation parameters (header, query, path)
// even when generateConvenient is false, so that types like enums are included
diagnostics.pipe(updateUsageOrAccess(context, UsageFlags.Input, sdkType));
const access = getAccessOverride(context, operation) ?? "public";
diagnostics.pipe(updateUsageOrAccess(context, access, sdkType));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Operation } from "@typespec/compiler";
import { strictEqual } from "assert";
import { ok, strictEqual } from "assert";
import { beforeEach, describe, it } from "vitest";
import { shouldGenerateConvenient, shouldGenerateProtocol } from "../../src/decorators.js";
import { UsageFlags } from "../../src/interfaces.js";
import { SdkTestRunner, createSdkContextTestHelper, createSdkTestRunner } from "../test-host.js";

let runner: SdkTestRunner;
Expand Down Expand Up @@ -345,3 +346,102 @@ describe("@protocolAPI and @convenientAPI with scope", () => {
}
});
});

describe("@convenientAPI(false) with enum parameters", () => {
it("enum in query parameter should have Input usage even with convenientAPI(false)", async () => {
await runner.compile(`
@service
namespace TestService {
enum IncludeEnum {
file_search_call_results: "file_search_call.results",
web_search_call_results: "web_search_call.results",
}

model ItemResult {
id: string;
content: string;
}

@route("/conversations/{conversation_id}/items/{item_id}")
@convenientAPI(false)
op getConversationItem(
@path conversation_id: string,
@path item_id: string,
@query(#{explode: true}) include?: IncludeEnum[],
): ItemResult;
}
`);

const sdkPackage = runner.context.sdkPackage;
ok(sdkPackage.enums);
const includeEnum = sdkPackage.enums.find((e) => e.name === "IncludeEnum");
ok(includeEnum, "IncludeEnum should be in the enums list");
ok(
includeEnum.usage & UsageFlags.Input,
"IncludeEnum should have Input usage even with convenientAPI(false)",
);
});

it("enum in header parameter should have Input usage even with convenientAPI(false)", async () => {
await runner.compile(`
@service
namespace TestService {
enum StatusEnum {
active: "active",
inactive: "inactive",
}

model Response {
data: string;
}

@route("/data")
@convenientAPI(false)
op getData(
@header status: StatusEnum,
): Response;
}
`);

const sdkPackage = runner.context.sdkPackage;
ok(sdkPackage.enums);
const statusEnum = sdkPackage.enums.find((e) => e.name === "StatusEnum");
ok(statusEnum, "StatusEnum should be in the enums list");
ok(
statusEnum.usage & UsageFlags.Input,
"StatusEnum should have Input usage even with convenientAPI(false)",
);
});

it("enum in path parameter should have Input usage even with convenientAPI(false)", async () => {
await runner.compile(`
@service
namespace TestService {
enum ResourceType {
users: "users",
groups: "groups",
}

model Resource {
id: string;
}

@route("/resources/{type}/{id}")
@convenientAPI(false)
op getResource(
@path type: ResourceType,
@path id: string,
): Resource;
}
`);

const sdkPackage = runner.context.sdkPackage;
ok(sdkPackage.enums);
const resourceType = sdkPackage.enums.find((e) => e.name === "ResourceType");
ok(resourceType, "ResourceType should be in the enums list");
ok(
resourceType.usage & UsageFlags.Input,
"ResourceType should have Input usage even with convenientAPI(false)",
);
});
});
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