Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh committed Oct 31, 2024
1 parent 9fb60d6 commit bfab50e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
20 changes: 16 additions & 4 deletions packages/typespec-client-generator-core/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,13 +629,25 @@ function findMapping(
return undefined;
}

function filterOutUselessPathParameters(context: TCGCContext, httpOperation: HttpOperation, methodParameters: SdkMethodParameter[]) {
// for autoroute with constant or singleton arm resource operation,
// some path parameters will be added to route directly with the constant value,
function filterOutUselessPathParameters(
context: TCGCContext,
httpOperation: HttpOperation,
methodParameters: SdkMethodParameter[],
) {
// there are some cases that method path parameter is not in operation:
// 1. autoroute with constant parameter
// 2. singleton arm resource name
// 3. visibility mis-match
// so we will remove the method parameter for consistent
for (let i = 0; i < methodParameters.length; i++) {
const param = methodParameters[i];
if (param.__raw && isPathParam(context.program, param.__raw) && httpOperation.parameters.parameters.filter(p => p.type === "path" && p.name === getWireName(context, param.__raw!)).length === 0) {
if (
param.__raw &&
isPathParam(context.program, param.__raw) &&
httpOperation.parameters.parameters.filter(
(p) => p.type === "path" && p.name === getWireName(context, param.__raw!),
).length === 0
) {
methodParameters.splice(i, 1);
i--;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ describe("typespec-client-generator-core: package", () => {
const method = getServiceMethodOfClient(sdkPackage);
strictEqual(method.name, "create");
strictEqual(method.kind, "basic");
strictEqual(method.parameters.length, 5);
strictEqual(method.parameters.length, 4);
deepStrictEqual(
method.parameters.map((x) => x.name),
["id", "weight", "color", "contentType", "accept"],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { AzureCoreTestLibrary } from "@azure-tools/typespec-azure-core/testing";
import { AzureResourceManagerTestLibrary } from "@azure-tools/typespec-azure-resource-manager/testing";
import { OpenAPITestLibrary } from "@typespec/openapi/testing";
import { deepStrictEqual, ok, strictEqual } from "assert";
import { beforeEach, describe, it } from "vitest";
import {
Expand All @@ -10,8 +12,6 @@ import {
} from "../../src/interfaces.js";
import { SdkTestRunner, createSdkTestRunner } from "../test-host.js";
import { getServiceMethodOfClient, getServiceWithDefaultApiVersion } from "./utils.js";
import { AzureResourceManagerTestLibrary } from "@azure-tools/typespec-azure-resource-manager/testing";
import { OpenAPITestLibrary } from "@typespec/openapi/testing";

describe("typespec-client-generator-core: parameters", () => {
let runner: SdkTestRunner;
Expand Down Expand Up @@ -1127,8 +1127,14 @@ describe("typespec-client-generator-core: parameters", () => {

const sdkPackage = runnerWithArm.context.sdkPackage;
const method = getServiceMethodOfClient(sdkPackage);
deepStrictEqual(method.parameters.map(p => p.name), ["resourceGroupName", "resource", "contentType", "accept"]);
deepStrictEqual(method.operation.parameters.map(p => p.name), ["apiVersion", "subscriptionId", "resourceGroupName", "contentType", "accept"]);
deepStrictEqual(
method.parameters.map((p) => p.name),
["resourceGroupName", "resource", "contentType", "accept"],
);
deepStrictEqual(
method.operation.parameters.map((p) => p.name),
["apiVersion", "subscriptionId", "resourceGroupName", "contentType", "accept"],
);
});
});
});

0 comments on commit bfab50e

Please sign in to comment.