Skip to content

Commit

Permalink
rename client class name for rlc (#1349)
Browse files Browse the repository at this point in the history
* rename client class name for rlc

* fix version tolerance test

* resolve comments
  • Loading branch information
qiaozha committed Mar 23, 2022
1 parent eb11588 commit 1b89465
Show file tree
Hide file tree
Showing 59 changed files with 159 additions and 163 deletions.
4 changes: 2 additions & 2 deletions src/generators/indexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function generateIndexFile(
function generateRLCIndexForMultiClient(file: SourceFile) {
const { model } = getSession();
const clientName = model.language.default.name;
const createClientFuncName = `${clientName}`;
const createClientFuncName = `createClient`;
const moduleName = normalizeName(clientName, NameType.File);

file.addImportDeclaration({
Expand Down Expand Up @@ -90,7 +90,7 @@ function generateRLCIndexForMultiClient(file: SourceFile) {
file.addExportDeclarations([
{
moduleSpecifier: `./${moduleName}`,
namedExports: [createClientFuncName],
namedExports: [`${createClientFuncName}`],
},
{
namedExports: [...exports]
Expand Down
4 changes: 2 additions & 2 deletions src/restLevelClient/generateClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export function generateClient(model: CodeModel, project: Project) {
? []
: [{ name: "credentials", type: credentialTypes.join(" | ") }])
];
const clientInterfaceName = `${clientName}Like`;
const clientInterfaceName = clientName.endsWith("Client")? `${clientName}`: `${clientName}Client`;

const functionStatement = {
isExported: true,
name: `${clientName}`,
name: `createClient`,
parameters: [
...commonClientParams,
{ name: "options", type: "ClientOptions = {}" }
Expand Down
2 changes: 1 addition & 1 deletion src/restLevelClient/generateClientDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export function generatePathFirstClient(model: CodeModel, project: Project) {

const clientName = getLanguageMetadata(model.language).name;

const clientInterfaceName = `${clientName}Like`;
const clientInterfaceName = clientName.endsWith("Client")? `${clientName}`: `${clientName}Client`;

const { rlcShortcut } = getAutorestOptions();

Expand Down
4 changes: 0 additions & 4 deletions src/restLevelClient/generateTopLevelIndexFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ export function generateTopLevelIndexFile(model: CodeModel, project: Project) {
namespaceImport: item[1],
moduleSpecifier: `${item[0]}`
});
file.addExportDeclaration({
moduleSpecifier: `${item[0]}/${item[2]}`,
namedExports: [`${item[1]} as ${item[1]}Client`]
})
allModules.push(item[1]);
});
file.addExportDeclaration({
Expand Down
8 changes: 4 additions & 4 deletions test/integration/bodyComplextRest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assert } from "chai";
import BodyComplexRestClient, {
BodyComplexRestClientLike,
import BodyComplexRest, {
BodyComplexRestClient,
DotSalmonOutput,
Fish,
FishOutput,
Expand All @@ -12,10 +12,10 @@ import BodyComplexRestClient, {
} from "./generated/bodyComplexRest/src";

describe("BodyComplex Rest Client", () => {
let client: BodyComplexRestClientLike;
let client: BodyComplexRestClient;

beforeEach(() => {
client = BodyComplexRestClient({ allowInsecureConnection: true });
client = BodyComplexRest({ allowInsecureConnection: true });
});

describe("Swagger Complex Type BAT", function() {
Expand Down
4 changes: 2 additions & 2 deletions test/integration/bodyFileRest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { assert } from "chai";
import BodyFile, { BodyFileLike } from "./generated/bodyFileRest/src";
import BodyFile, { BodyFileClient } from "./generated/bodyFileRest/src";

describe("BodyFile Client", () => {
let client: BodyFileLike;
let client: BodyFileClient;

beforeEach("create client", () => {
client = BodyFile({ allowInsecureConnection: true });
Expand Down
4 changes: 2 additions & 2 deletions test/integration/bodyFormDataRest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import BodyFormData, {
BodyFormDataLike
BodyFormDataClient
} from "./generated/bodyFormDataRest/src";
import { assert } from "chai";

describe("Integration tests for BodyFormData", () => {
let client: BodyFormDataLike;
let client: BodyFormDataClient;

it("should correctly accept file via form", async function() {
client = BodyFormData({ allowInsecureConnection: true });
Expand Down
4 changes: 2 additions & 2 deletions test/integration/bodyStringRest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { assert } from "chai";
import BodyStringRest, {
BodyStringRestLike
BodyStringRestClient
} from "./generated/bodyStringRest/src";

describe(" BodyStringRest", () => {
let client: BodyStringRestLike;
let client: BodyStringRestClient;

beforeEach(() => {
client = BodyStringRest();
Expand Down
8 changes: 4 additions & 4 deletions test/integration/customUrlRest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import CustomUrlRestClient, {
CustomUrlRestClientLike
import CustomUrlRest, {
CustomUrlRestClient
} from "./generated/customUrlRest/src";
import { assert } from "chai";

describe("CustomRest Endpoint", () => {
let client: CustomUrlRestClientLike;
let client: CustomUrlRestClient;
let clientOptions: any;
beforeEach(() => {
clientOptions = { allowInsecureConnection: true };
client = CustomUrlRestClient("host:3000", clientOptions);
client = CustomUrlRest("host:3000", clientOptions);
});

it("should return 200", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { BodyComplexRestClientLike } from "./clientDefinitions";
import { BodyComplexRestClient } from "./clientDefinitions";

export default function BodyComplexRestClient(
export default function createClient(
options: ClientOptions = {}
): BodyComplexRestClientLike {
): BodyComplexRestClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";
options.apiVersion = options.apiVersion ?? "2016-02-29";

Expand All @@ -22,7 +22,7 @@ export default function BodyComplexRestClient(
}
};

const client = getClient(baseUrl, options) as BodyComplexRestClientLike;
const client = getClient(baseUrl, options) as BodyComplexRestClient;

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,6 @@ export interface Routes {
(path: "/complex/flatten/valid"): FlattencomplexGetValid;
}

export type BodyComplexRestClientLike = Client & {
export type BodyComplexRestClient = Client & {
path: Routes;
};
8 changes: 5 additions & 3 deletions test/integration/generated/bodyFileRest/src/bodyFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { BodyFileLike } from "./clientDefinitions";
import { BodyFileClient } from "./clientDefinitions";

export default function BodyFile(options: ClientOptions = {}): BodyFileLike {
export default function createClient(
options: ClientOptions = {}
): BodyFileClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";

const userAgentInfo = `azsdk-js-body-file-rest/1.0.0-preview1`;
Expand All @@ -19,7 +21,7 @@ export default function BodyFile(options: ClientOptions = {}): BodyFileLike {
}
};

const client = getClient(baseUrl, options) as BodyFileLike;
const client = getClient(baseUrl, options) as BodyFileClient;

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ export interface Routes {
(path: "/files/stream/empty"): GetEmptyFile;
}

export type BodyFileLike = Client & {
export type BodyFileClient = Client & {
path: Routes;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { BodyFormDataLike } from "./clientDefinitions";
import { BodyFormDataClient } from "./clientDefinitions";

export default function BodyFormData(
export default function createClient(
options: ClientOptions = {}
): BodyFormDataLike {
): BodyFormDataClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";

const userAgentInfo = `azsdk-js-body-formdata-rest/1.0.0-preview1`;
Expand All @@ -21,7 +21,7 @@ export default function BodyFormData(
}
};

const client = getClient(baseUrl, options) as BodyFormDataLike;
const client = getClient(baseUrl, options) as BodyFormDataClient;

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ export interface Routes {
(path: "/formdata/stream/uploadfiles"): UploadFiles;
}

export type BodyFormDataLike = Client & {
export type BodyFormDataClient = Client & {
path: Routes;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { BodyStringRestLike } from "./clientDefinitions";
import { BodyStringRestClient } from "./clientDefinitions";

export default function BodyStringRest(
export default function createClient(
options: ClientOptions = {}
): BodyStringRestLike {
): BodyStringRestClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";

const userAgentInfo = `azsdk-js-body-string-rest/1.0.0-preview1`;
Expand All @@ -21,7 +21,7 @@ export default function BodyStringRest(
}
};

const client = getClient(baseUrl, options) as BodyStringRestLike;
const client = getClient(baseUrl, options) as BodyStringRestClient;

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,6 @@ export interface Routes {
(path: "/string/enum/ReferencedConstant"): EnumGetReferencedConstant;
}

export type BodyStringRestLike = Client & {
export type BodyStringRestClient = Client & {
path: Routes;
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Routes {
(path: "/customuri"): GetEmpty;
}

export type CustomUrlRestClientLike = Client & {
export type CustomUrlRestClient = Client & {
path: Routes;
paths: PathsOperations;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { CustomUrlRestClientLike } from "./clientDefinitions";
import { CustomUrlRestClient } from "./clientDefinitions";

export default function CustomUrlRestClient(
export default function createClient(
host: string,
options: ClientOptions = {}
): CustomUrlRestClientLike {
): CustomUrlRestClient {
const baseUrl = options.baseUrl ?? `http://{accountName}${host}`;
const userAgentInfo = `azsdk-js-custom-url-rest/1.0.0-preview1`;
const userAgentPrefix =
Expand All @@ -21,7 +21,7 @@ export default function CustomUrlRestClient(
}
};

const client = getClient(baseUrl, options) as CustomUrlRestClientLike;
const client = getClient(baseUrl, options) as CustomUrlRestClient;

return {
...client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,6 @@ export interface Routes {
): CustomRequestId;
}

export type HeaderRestClientLike = Client & {
export type HeaderRestClient = Client & {
path: Routes;
};
8 changes: 4 additions & 4 deletions test/integration/generated/headerRest/src/headerRestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { HeaderRestClientLike } from "./clientDefinitions";
import { HeaderRestClient } from "./clientDefinitions";

export default function HeaderRestClient(
export default function createClient(
options: ClientOptions = {}
): HeaderRestClientLike {
): HeaderRestClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";

const userAgentInfo = `azsdk-js-header-rest/1.0.0-preview1`;
Expand All @@ -21,7 +21,7 @@ export default function HeaderRestClient(
}
};

const client = getClient(baseUrl, options) as HeaderRestClientLike;
const client = getClient(baseUrl, options) as HeaderRestClient;

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2032,7 +2032,7 @@ export interface Routes {
): MultipleResponsesGet200ModelA202Valid;
}

export type HttpInfrastructureRestClientLike = Client & {
export type HttpInfrastructureRestClient = Client & {
path: Routes;
httpFailure: HttpFailureOperations;
httpSuccess: HttpSuccessOperations;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { HttpInfrastructureRestClientLike } from "./clientDefinitions";
import { HttpInfrastructureRestClient } from "./clientDefinitions";

export default function HttpInfrastructureRestClient(
export default function createClient(
options: ClientOptions = {}
): HttpInfrastructureRestClientLike {
): HttpInfrastructureRestClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";

const userAgentInfo = `azsdk-js-http-infrastructure-rest/1.0.0-preview1`;
Expand All @@ -21,10 +21,7 @@ export default function HttpInfrastructureRestClient(
}
};

const client = getClient(
baseUrl,
options
) as HttpInfrastructureRestClientLike;
const client = getClient(baseUrl, options) as HttpInfrastructureRestClient;

return {
...client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,6 @@ export interface Routes {
): LROsCustomHeaderPostAsyncRetrySucceeded;
}

export type LRORestClientLike = Client & {
export type LRORestClient = Client & {
path: Routes;
};
8 changes: 4 additions & 4 deletions test/integration/generated/lroRest/src/lRORestClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { LRORestClientLike } from "./clientDefinitions";
import { LRORestClient } from "./clientDefinitions";

export default function LRORestClient(
export default function createClient(
options: ClientOptions = {}
): LRORestClientLike {
): LRORestClient {
const baseUrl = options.baseUrl ?? "http://localhost:3000";

const userAgentInfo = `azsdk-js-lro-rest/1.0.0-preview1`;
Expand All @@ -21,7 +21,7 @@ export default function LRORestClient(
}
};

const client = getClient(baseUrl, options) as LRORestClientLike;
const client = getClient(baseUrl, options) as LRORestClient;

return client;
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ export interface Routes {
(path: "/mediatypes/textAndJson"): PutTextAndJsonBody;
}

export type MediaTypesLike = Client & {
export type MediaTypesClient = Client & {
path: Routes;
};
Loading

0 comments on commit 1b89465

Please sign in to comment.