diff --git a/.vscode/launch.json b/.vscode/launch.json index fd6d27d42c..54c56e89d9 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -27,6 +27,24 @@ "${workspaceFolder}/packages/*/dist-dev/**/*.js" ] }, + { + "name": "[Autorest] Run Debug Integration Test", + "request": "launch", + "cwd": "${workspaceFolder}/packages/autorest.typescript", + "runtimeArgs": [ + "ts-node", + "./test/commands/test-swagger-gen.ts", + "--", + "rlc" + ], + "runtimeExecutable": "npx", + "skipFiles": ["/**"], + "type": "pwa-node", + "outFiles": [ + "${workspaceFolder}/packages/*/dist/**/*.js", + "${workspaceFolder}/packages/*/dist-dev/**/*.js" + ] + }, { "type": "node", "request": "launch", @@ -94,7 +112,7 @@ { "name": "[TypeSpec] Smoke Test Debug", "request": "launch", - "cwd": "${workspaceFolder}/packages/typespec-test/test/openai_modular", + "cwd": "${workspaceFolder}/packages/typespec-test/test/customWrapper", "runtimeArgs": ["tsp", "compile", "./spec"], "runtimeExecutable": "npx", "skipFiles": ["/**"], @@ -108,7 +126,7 @@ "runtimeArgs": [ "ts-node", "./test/commands/gen-cadl-ranch.ts", - "--tag=modular", + "--tag=rlc", "--debug" ], "runtimeExecutable": "npx", diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index b46199fa4e..c3980707c5 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -158,6 +158,7 @@ importers: chai: ^4.3.7 cross-env: 7.0.3 eslint: ^8.9.0 + eslint-plugin-require-extensions: 0.1.3 fs-extra: ^10.0.0 handlebars: ^4.7.7 lodash: ^4.17.21 @@ -182,6 +183,7 @@ importers: chai: 4.3.8 cross-env: 7.0.3 eslint: 8.50.0 + eslint-plugin-require-extensions: 0.1.3_eslint@8.50.0 fs-extra: 10.1.0 mocha: 10.2.0 prettier: 2.7.1 @@ -256,6 +258,7 @@ importers: chalk: ^4.0.0 cross-env: ^7.0.3 eslint: ^8.9.0 + eslint-plugin-require-extensions: 0.1.3 fs-extra: ^11.1.0 mkdirp: ^2.1.2 mocha: ^9.2.2 @@ -299,6 +302,7 @@ importers: chalk: 4.1.2 cross-env: 7.0.3 eslint: 8.50.0 + eslint-plugin-require-extensions: 0.1.3_eslint@8.50.0 mkdirp: 2.1.6 mocha: 9.2.2 rimraf: 5.0.4 @@ -2630,6 +2634,15 @@ packages: engines: {node: '>=10'} dev: true + /eslint-plugin-require-extensions/0.1.3_eslint@8.50.0: + resolution: {integrity: sha512-T3c1PZ9PIdI3hjV8LdunfYI8gj017UQjzAnCrxuo3wAjneDbTPHdE3oNWInOjMA+z/aBkUtlW5vC0YepYMZIug==} + engines: {node: '>=16'} + peerDependencies: + eslint: '*' + dependencies: + eslint: 8.50.0 + dev: true + /eslint-scope/5.1.1: resolution: {integrity: sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==} engines: {node: '>=8.0.0'} diff --git a/packages/autorest.typescript/src/generators/samples/rlcSampleGenerator.ts b/packages/autorest.typescript/src/generators/samples/rlcSampleGenerator.ts index cac3365449..ad45c0c779 100644 --- a/packages/autorest.typescript/src/generators/samples/rlcSampleGenerator.ts +++ b/packages/autorest.typescript/src/generators/samples/rlcSampleGenerator.ts @@ -2,42 +2,57 @@ import { ExampleParameter, TestCodeModel } from "@autorest/testmodeler/dist/src/core/model"; -import { Project } from "ts-morph"; import { getAutorestOptions, getSession } from "../../autorestSession"; -import * as fs from "fs"; -import * as path from "path"; -import * as hbs from "handlebars"; import { NameType, normalizeName } from "../../utils/nameUtils"; import { getLanguageMetadata } from "../../utils/languageHelpers"; import { transformBaseUrl } from "../../transforms/urlTransforms"; -import { - RLCSampleDetail, - RLCSampleGroup, - SampleParameter, - SampleParameters, - TestSampleParameters, - OperationMethod -} from "../../restLevelClient/interfaces"; import { camelCase } from "@azure-tools/codegen"; import { Operation, ParameterLocation } from "@autorest/codemodel"; import { isLongRunningOperation } from "../../restLevelClient/helpers/hasPollingOperations"; import { isPagingOperation } from "../../utils/extractPaginationDetails"; import { getSecurityInfoFromModel } from "../../utils/schemaHelpers"; import { getParameterAssignment } from "../../utils/valueHelpers"; -import { Paths, PathMetadata } from "@azure-tools/rlc-common"; +import { + Paths, + PathMetadata, + RLCSampleGroup, + RLCSampleDetail, + SampleParameter, + SampleParameters, + OperationMethod, + SampleParameterPosition, + transformSampleGroups as transformSampleGroupsFromMockValue, + RLCModel +} from "@azure-tools/rlc-common"; import { transformPaths } from "../../restLevelClient/transforms/transformPaths"; const tokenCredentialPackage = "@azure/identity"; const apiKeyCredentialPackage = "@azure/core-auth"; -export let hasRLCSamplesGenerated = false; +export function transformRLCSampleData( + model: TestCodeModel, + rlcModel: RLCModel +): RLCSampleGroup[] | undefined { + // We prefer to generate sample from swagger examples first + const sampleGroups = transformSampleGroupsFromSwaggerExamples(model); + if (sampleGroups && sampleGroups.length > 0) { + return sampleGroups; + } + const { generateSample, generateMetadata } = getAutorestOptions(); + // If no swagger examples, we will generate mock sample + // Allow to generate mock sample when generateSample and generateMetadata are both true + const allowMockValue = generateSample === true && generateMetadata === true; + return transformSampleGroupsFromMockValue(rlcModel, allowMockValue); +} -export function generateRLCSamples(model: TestCodeModel, project: Project) { +function transformSampleGroupsFromSwaggerExamples( + model: TestCodeModel +): RLCSampleGroup[] | undefined { const { generateSample, multiClient } = getAutorestOptions(); - const session = getSession(); if (!generateSample || !model?.testModel?.mockTest?.exampleGroups) { return; } + const session = getSession(); // Currently only support single client if (multiClient) { session.info( @@ -45,43 +60,11 @@ export function generateRLCSamples(model: TestCodeModel, project: Project) { ); return; } - const sampleGroups: RLCSampleGroup[] = transformRLCSampleData(model); - if (sampleGroups.length > 0) { - hasRLCSamplesGenerated = true; - } - for (const sampleGroup of sampleGroups) { - try { - const file = fs.readFileSync(path.join(__dirname, "rlcSamples.ts.hbs"), { - encoding: "utf-8" - }); - const sampleGroupFileContents = hbs.compile(file, { noEscape: true }); - project.createSourceFile( - `samples-dev/${sampleGroup.filename}.ts`, - sampleGroupFileContents(sampleGroup), - { - overwrite: true - } - ); - } catch (error) { - session.error( - "An error was encountered while handling sample generation", - [sampleGroup.filename] - ); - session.error( - "Stop generating samples and please inform the developers of codegen the detailed errors", - [] - ); - } - } -} - -export function transformRLCSampleData(model: TestCodeModel): RLCSampleGroup[] { const rlcSampleGroups: RLCSampleGroup[] = []; if (!model?.testModel?.mockTest?.exampleGroups) { return rlcSampleGroups; } // Get all paths - const session = getSession(); const paths: Paths = transformPaths(model); const clientName = getLanguageMetadata(model.language).name; const clientInterfaceName = clientName.endsWith("Client") @@ -134,7 +117,10 @@ export function transformRLCSampleData(model: TestCodeModel): RLCSampleGroup[] { useLegacyLro: false }; // convert the parameters to the intermidate model - SampleParameters - const rawParamters: TestSampleParameters = { + const rawParamters: Record< + SampleParameterPosition, + ExampleParameter[] + > = { client: rawSample.clientParameters, path: (rawSample.methodParameters || []).filter(isPathLevelParam), method: (rawSample.methodParameters || []).filter(isMethodLevelParam) @@ -149,8 +135,7 @@ export function transformRLCSampleData(model: TestCodeModel): RLCSampleGroup[] { path: convertPathLevelParameters(rawParamters.path, pathDetail, path), method: convertMethodLevelParameters( rawParamters.method, - pathDetail.methods[method], - importedDict + pathDetail.methods[method] ) }; // enrich parameter details @@ -310,8 +295,7 @@ function convertPathLevelParameters( function convertMethodLevelParameters( rawMethodParams: ExampleParameter[], - methods: OperationMethod[], - importedDict: Record> + methods: OperationMethod[] ): SampleParameter[] { if (!methods || methods.length == 0) { return []; @@ -369,9 +353,9 @@ function convertMethodLevelParameters( } const optionParam: SampleParameter = { name: "options", - assignment: `const options: ${method.optionsName} =` + value + `;` + assignment: `const options =` + value + `;`, + value }; - addValueInImportedDict(getPackageName(), method.optionsName, importedDict); return [optionParam]; } @@ -383,8 +367,8 @@ function enrichParameterInSample( sample.clientParamNames = getContactParameterNames(parameters.client); sample.pathParamAssignments = getAssignmentStrArray(parameters.path); sample.pathParamNames = getContactParameterNames(parameters.path); - sample.methodParamAssignments = getAssignmentStrArray(parameters.method); - sample.methodParamNames = parameters.method.length > 0 ? "options" : ""; + sample.methodParamNames = + parameters.method.length > 0 ? parameters.method[0].value ?? "" : ""; } function getAssignmentStrArray(parameters: SampleParameter[]) { diff --git a/packages/autorest.typescript/src/restLevelClient/generateRestLevel.ts b/packages/autorest.typescript/src/restLevelClient/generateRestLevel.ts index 708d1bf339..a8e18a9872 100644 --- a/packages/autorest.typescript/src/restLevelClient/generateRestLevel.ts +++ b/packages/autorest.typescript/src/restLevelClient/generateRestLevel.ts @@ -9,10 +9,6 @@ import { prettierJSONOptions, prettierTypeScriptOptions } from "./config"; import * as path from "path"; import * as fsextra from "fs-extra"; import { generateSampleEnv } from "../generators/samples/sampleEnvGenerator"; -import { - generateRLCSamples, - hasRLCSamplesGenerated -} from "../generators/samples/rlcSampleGenerator"; import { transform } from "./transforms/transform"; import { buildApiExtractorConfig, @@ -36,7 +32,8 @@ import { buildLicenseFile, buildReadmeFile, buildSerializeHelper, - buildLogger + buildLogger, + buildSamples } from "@azure-tools/rlc-common"; import { generateFileByBuilder, @@ -53,7 +50,6 @@ export async function generateRestLevelClient() { const { outputPath, srcPath, - generateSample, generateTest, generateMetadata } = getAutorestOptions(); @@ -70,6 +66,7 @@ export async function generateRestLevelClient() { // then transform CodeModel to RLCModel const rlcModels = transform(model); + const hasSampleGenerated = (rlcModels.sampleGroups ?? []).length > 0; if (generateMetadata) { // buildReadmeFile @@ -118,31 +115,18 @@ export async function generateRestLevelClient() { generateFileByBuilder(project, buildSerializeHelper, rlcModels); generateFileByBuilder(project, buildLogger, rlcModels); generateTopLevelIndexFile(rlcModels, project); - if (generateSample && generateMetadata) { - generateRLCSamples(model, project); + if (hasSampleGenerated && generateMetadata) { + generateFileByBuilder(project, buildSamples, rlcModels); } - if ( - ((generateSample && hasRLCSamplesGenerated) || generateTest) && - generateMetadata - ) { + if ((hasSampleGenerated || generateTest) && generateMetadata) { generateSampleEnv(project); } if (generateMetadata) { // buildPackageFile - generateFileByBuilder( - project, - buildPackageFile, - rlcModels, - hasRLCSamplesGenerated - ); + generateFileByBuilder(project, buildPackageFile, rlcModels); // buildTsConfig - generateFileByBuilder( - project, - buildTsConfig, - rlcModels, - hasRLCSamplesGenerated - ); + generateFileByBuilder(project, buildTsConfig, rlcModels); } // Save the source files to the virtual filesystem diff --git a/packages/autorest.typescript/src/restLevelClient/helpers/generatorHelpers.ts b/packages/autorest.typescript/src/restLevelClient/helpers/generatorHelpers.ts index 913332ec81..bdc2752aad 100644 --- a/packages/autorest.typescript/src/restLevelClient/helpers/generatorHelpers.ts +++ b/packages/autorest.typescript/src/restLevelClient/helpers/generatorHelpers.ts @@ -9,18 +9,13 @@ import { buildSchemaTypes } from "@azure-tools/rlc-common"; export function generateFileByBuilder( project: Project, buildFnOrList: ContentBuilder | ContentBuilder[], - rlcModels: RLCModel, - hasSampleGenerated?: boolean + rlcModels: RLCModel ) { if (!Array.isArray(buildFnOrList)) { buildFnOrList = [buildFnOrList]; } for (const buildFn of buildFnOrList) { - const preparedFile: RLCFile | undefined = buildFn( - rlcModels, - hasSampleGenerated - ); - generateFile(preparedFile, project); + generateFile(buildFn(rlcModels), project); } } @@ -30,8 +25,17 @@ export function generateSchemaTypes(project: Project, rlcModels: RLCModel) { generateFile(outputModelFile, project); } -function generateFile(file: RLCFile | undefined, project: Project) { - if (file) { +function generateFile( + files: RLCFile[] | RLCFile | undefined, + project: Project +) { + if (!files) { + return; + } + if (!Array.isArray(files)) { + files = [files]; + } + for (const file of files) { project.createSourceFile(file.path, file.content, { overwrite: true }); diff --git a/packages/autorest.typescript/src/restLevelClient/interfaces.ts b/packages/autorest.typescript/src/restLevelClient/interfaces.ts deleted file mode 100644 index 00ea9fb460..0000000000 --- a/packages/autorest.typescript/src/restLevelClient/interfaces.ts +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -import { Schema } from "@autorest/codemodel"; -import { ExampleParameter } from "@autorest/testmodeler/dist/src/core/model"; -// import { ExampleParameter } from "@autorest/testmodeler"; - -export type PathParameter = { - name: string; - schema: Schema; - description?: string; -}; - -export interface ResponseTypes { - success: string[]; - error: string[]; -} - -export interface OperationMethod { - optionsName: string; - description: string; - hasOptionalOptions: boolean; - returnType: string; - successStatus: string[]; - responseTypes: ResponseTypes; -} - -export type Methods = { - [key: string]: [OperationMethod]; -}; - -export interface PathMetadata { - name: string; - pathParameters: PathParameter[]; - methods: Methods; - annotations?: OperationAnnotations; -} - -export type Paths = Record; - -export interface OperationAnnotations { - isLongRunning?: boolean; - isPageable?: boolean; -} - -/** - * A group of samples in operation_id level and they are used to generate in a sample file - */ -export interface RLCSampleGroup { - filename: string; - clientPackageName: string; - defaultFactoryName: string; - samples: RLCSampleDetail[]; - importedTypes?: string[]; -} - -/** - * An independent sample detail and it will be wrapped as a func - */ -export interface RLCSampleDetail { - /** - * metadata for comments - */ - description: string; - originalFileLocation?: string; - name: string; - path: string; - defaultFactoryName: string; - clientParamAssignments: string[]; - pathParamAssignments: string[]; - methodParamAssignments: string[]; - clientParamNames: string; - pathParamNames: string; - methodParamNames: "options" | ""; - method: string; - isLRO: boolean; - isPaging: boolean; - useLegacyLro: boolean; -} - -export type SampleParameterPosition = "client" | "path" | "method"; - -export type SampleParameters = Record< - SampleParameterPosition, - SampleParameter[] ->; - -export type TestSampleParameters = Record< - SampleParameterPosition, - ExampleParameter[] ->; - -export interface SampleParameter { - name: string; - assignment?: string; -} diff --git a/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts b/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts index c781d2ea02..df872ce8f5 100644 --- a/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts +++ b/packages/autorest.typescript/src/restLevelClient/transforms/transform.ts @@ -34,6 +34,7 @@ import { import { transformPaths } from "./transformPaths"; import { transformResponseTypes } from "./transformResponseTypes"; import { transformSchemas } from "./transformSchemas"; +import { transformRLCSampleData } from "../../generators/samples/rlcSampleGenerator"; export function transform(model: CodeModel): RLCModel { const { srcPath } = getAutorestOptions(); @@ -55,6 +56,7 @@ export function transform(model: CodeModel): RLCModel { urlInfo: transformUrlInfo(model), apiVersionInfo: transformApiVersion(model, urlInfo) }; + rlcModel.sampleGroups = transformRLCSampleData(model, rlcModel); return rlcModel; } @@ -125,6 +127,7 @@ export function transformHelperDetails( let hasPipeCollection = false; let hasSsvCollection = false; let hasTsvCollection = false; + let hasCsvCollection = false; for (let operationGroup of model.operationGroups) { for (let operation of operationGroup.operations) { const paginationDetails = extractPaginationDetails(operation); @@ -147,6 +150,9 @@ export function transformHelperDetails( hasTsvCollection = hasTsvCollection ? hasTsvCollection : serializeInfo.hasTsvCollection; + hasCsvCollection = hasCsvCollection + ? hasCsvCollection + : serializeInfo.hasCsvCollection; }); } } diff --git a/packages/autorest.typescript/src/restLevelClient/transforms/transformParameterTypes.ts b/packages/autorest.typescript/src/restLevelClient/transforms/transformParameterTypes.ts index 39fc13b8ef..1f72947c4a 100644 --- a/packages/autorest.typescript/src/restLevelClient/transforms/transformParameterTypes.ts +++ b/packages/autorest.typescript/src/restLevelClient/transforms/transformParameterTypes.ts @@ -171,7 +171,12 @@ function transformBodyParameters( ); } else { rlcBodyParam.body = [ - getParameterSchema(bodyParameters[0], importedModels, false, contentTypeParam) + getParameterSchema( + bodyParameters[0], + importedModels, + false, + contentTypeParam + ) ]; } @@ -244,9 +249,23 @@ function getParameterSchema( } if (type === "Array" || type === "Array") { const serializeInfo = getSpecialSerializeInfo(parameter); - if (serializeInfo.hasMultiCollection || serializeInfo.hasPipeCollection || serializeInfo.hasSsvCollection || serializeInfo.hasTsvCollection) { + if ( + serializeInfo.hasMultiCollection || + serializeInfo.hasPipeCollection || + serializeInfo.hasSsvCollection || + serializeInfo.hasTsvCollection || + serializeInfo.hasCsvCollection + ) { type = "string"; - description += ` This parameter needs to be formatted as ${serializeInfo.collectionInfo.join(", ")} collection, we provide ${serializeInfo.descriptions.join(", ")} from serializeHelper.ts to help${serializeInfo.hasMultiCollection? ", you will probably need to set skipUrlEncoding as true when sending the request": ""}`; + description += ` This parameter needs to be formatted as ${serializeInfo.collectionInfo.join( + ", " + )} collection, we provide ${serializeInfo.descriptions.join( + ", " + )} from serializeHelper.ts to help${ + serializeInfo.hasMultiCollection + ? ", you will probably need to set skipUrlEncoding as true when sending the request" + : "" + }`; } } return { @@ -262,9 +281,13 @@ export function getSpecialSerializeInfo(parameter: Parameter) { let hasPipeCollection = false; let hasSsvCollection = false; let hasTsvCollection = false; + let hasCsvCollection = false; const descriptions = []; const collectionInfo = []; - if (parameter.protocol.http?.explode === true && parameter.protocol.http?.style === 'form') { + if ( + parameter.protocol.http?.explode === true && + parameter.protocol.http?.style === "form" + ) { hasMultiCollection = true; descriptions.push("buildMultiCollection"); collectionInfo.push("multi"); @@ -284,14 +307,20 @@ export function getSpecialSerializeInfo(parameter: Parameter) { descriptions.push("buildTsvCollection"); collectionInfo.push("tsv"); } + if (parameter.protocol.http?.style === "simple") { + hasCsvCollection = true; + descriptions.push("buildCsvCollection"); + collectionInfo.push("csv"); + } return { hasMultiCollection, hasPipeCollection, hasSsvCollection, hasTsvCollection, + hasCsvCollection, descriptions, collectionInfo - } + }; } /** @@ -304,4 +333,4 @@ function getAllOperations(model: CodeModel): Operation[] { } return operations; -} \ No newline at end of file +} diff --git a/packages/autorest.typescript/test/commands/test-swagger-gen.ts b/packages/autorest.typescript/test/commands/test-swagger-gen.ts index 501c2bacf3..09b8e5ac37 100644 --- a/packages/autorest.typescript/test/commands/test-swagger-gen.ts +++ b/packages/autorest.typescript/test/commands/test-swagger-gen.ts @@ -907,7 +907,7 @@ const rlcTestSwaggers: { [name: string]: SwaggerConfig } = { isTestPackage: true, restLevelClient: true, azureSdkForJs: false, - generateSample: true + generateSample: false }, dpgCustomization: { swaggerOrConfig: "dpg-customization.json", @@ -954,7 +954,7 @@ const rlcTestSwaggers: { [name: string]: SwaggerConfig } = { isTestPackage: true, restLevelClient: true, azureSdkForJs: false, - generateSample: true + generateSample: false }, multipleInheritanceRest: { swaggerOrConfig: "multiple-inheritance.json", @@ -991,7 +991,7 @@ const rlcTestSwaggers: { [name: string]: SwaggerConfig } = { isTestPackage: true, restLevelClient: true, azureSdkForJs: false, - generateSample: true + generateSample: false }, headerRest: { swaggerOrConfig: "header.json", @@ -1016,7 +1016,7 @@ const rlcTestSwaggers: { [name: string]: SwaggerConfig } = { addCredentials: false, isTestPackage: true, azureSdkForJs: false, - generateSample: true + generateSample: false }, bodyFormDataRest: { swaggerOrConfig: "body-formdata.json", @@ -1029,7 +1029,7 @@ const rlcTestSwaggers: { [name: string]: SwaggerConfig } = { isTestPackage: true, restLevelClient: true, azureSdkForJs: false, - generateSample: true + generateSample: false }, customUrlRest: { swaggerOrConfig: "custom-baseUrl.json", @@ -1054,7 +1054,7 @@ const rlcTestSwaggers: { [name: string]: SwaggerConfig } = { allowInsecureConnection: true, addCredentials: false, isTestPackage: true, - generateSample: true + generateSample: false }, securityAADRest: { swaggerOrConfig: "security-aad.json", diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetNotExpandableSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetNotExpandableSample.ts index bf486c7a4d..1c6e63300e 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetNotExpandableSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetNotExpandableSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedConstantSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedConstantSample.ts index 4fb3513be3..038eb39e96 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedConstantSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedConstantSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedSample.ts index b2ca371f76..9d0f512a89 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumGetReferencedSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutNotExpandableSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutNotExpandableSample.ts index e2309251bb..528b4f1a5e 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutNotExpandableSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutNotExpandableSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - EnumPutNotExpandableParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,8 +14,9 @@ dotenv.config(); */ async function enumPutNotExpandable() { const client = createBodyStringRestClient(); - const options: EnumPutNotExpandableParameters = { body: "red color" }; - const result = await client.path("/string/enum/notExpandable").put(options); + const result = await client + .path("/string/enum/notExpandable") + .put({ body: "red color" }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedConstantSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedConstantSample.ts index 406d07821a..e089f2b346 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedConstantSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedConstantSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - EnumPutReferencedConstantParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,12 +14,9 @@ dotenv.config(); */ async function enumPutReferencedConstant() { const client = createBodyStringRestClient(); - const options: EnumPutReferencedConstantParameters = { - body: { ColorConstant: "green-color" } - }; const result = await client .path("/string/enum/ReferencedConstant") - .put(options); + .put({ body: { ColorConstant: "green-color" } }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedSample.ts index 03cbf9f3bc..b5ec59026e 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/enumPutReferencedSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - EnumPutReferencedParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,8 +14,9 @@ dotenv.config(); */ async function enumPutReferenced() { const client = createBodyStringRestClient(); - const options: EnumPutReferencedParameters = { body: "red color" }; - const result = await client.path("/string/enum/Referenced").put(options); + const result = await client + .path("/string/enum/Referenced") + .put({ body: "red color" }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64EncodedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64EncodedSample.ts index 04ac0ee0f6..8544fff6ac 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64EncodedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64EncodedSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64UrlEncodedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64UrlEncodedSample.ts index 55f473dbc0..8ddb83f011 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64UrlEncodedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetBase64UrlEncodedSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetEmptySample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetEmptySample.ts index 030985a7c4..f3167326b8 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetEmptySample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetEmptySample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetMbcsSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetMbcsSample.ts index 1787579ead..6125a44167 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetMbcsSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetMbcsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNotProvidedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNotProvidedSample.ts index ae18340ccf..48df087380 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNotProvidedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNotProvidedSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullBase64UrlEncodedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullBase64UrlEncodedSample.ts index b6b73b11c2..8323fe030a 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullBase64UrlEncodedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullBase64UrlEncodedSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullSample.ts index 9ed5dae3ca..feda01b0a1 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetNullSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetWhitespaceSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetWhitespaceSample.ts index 192a72896d..82055c339c 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetWhitespaceSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringGetWhitespaceSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutBase64UrlEncodedSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutBase64UrlEncodedSample.ts index ea3c40c877..405bf07f71 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutBase64UrlEncodedSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutBase64UrlEncodedSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - StringPutBase64UrlEncodedParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,10 +14,9 @@ dotenv.config(); */ async function stringPutBase64UrlEncoded() { const client = createBodyStringRestClient(); - const options: StringPutBase64UrlEncodedParameters = { - body: "YSBzdHJpbmcgdGhhdCBnZXRzIGVuY29kZWQgd2l0aCBiYXNlNjR1cmw" - }; - const result = await client.path("/string/base64UrlEncoding").put(options); + const result = await client + .path("/string/base64UrlEncoding") + .put({ body: "YSBzdHJpbmcgdGhhdCBnZXRzIGVuY29kZWQgd2l0aCBiYXNlNjR1cmw" }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutEmptySample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutEmptySample.ts index 5d3d62fe64..1b98e50bac 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutEmptySample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutEmptySample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - StringPutEmptyParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,8 +14,7 @@ dotenv.config(); */ async function stringPutEmpty() { const client = createBodyStringRestClient(); - const options: StringPutEmptyParameters = { body: "" }; - const result = await client.path("/string/empty").put(options); + const result = await client.path("/string/empty").put({ body: "" }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutMbcsSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutMbcsSample.ts index d047440ca8..785cd6bd82 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutMbcsSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutMbcsSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - StringPutMbcsParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,11 +14,12 @@ dotenv.config(); */ async function stringPutMbcs() { const client = createBodyStringRestClient(); - const options: StringPutMbcsParameters = { - body: - "啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€" - }; - const result = await client.path("/string/mbcs").put(options); + const result = await client + .path("/string/mbcs") + .put({ + body: + "啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€" + }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutNullSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutNullSample.ts index 19187e7bd3..6c14b36e11 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutNullSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutNullSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutWhitespaceSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutWhitespaceSample.ts index aa646b99a4..d0e328792f 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutWhitespaceSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/bodyStringRest/samples-dev/stringPutWhitespaceSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createBodyStringRestClient, { - StringPutWhitespaceParameters -} from "@msinternal/body-string-rest"; +import createBodyStringRestClient from "@msinternal/body-string-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,11 +14,12 @@ dotenv.config(); */ async function stringPutWhitespace() { const client = createBodyStringRestClient(); - const options: StringPutWhitespaceParameters = { - body: - " Now is the time for all good men to come to the aid of their country " - }; - const result = await client.path("/string/whitespace").put(options); + const result = await client + .path("/string/whitespace") + .put({ + body: + " Now is the time for all good men to come to the aid of their country " + }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getModelSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getModelSample.ts index d90fcd4beb..ad70a4b20a 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getModelSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getModelSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createDpgCustomizationClient from "@msinternal/dpg-customization-rest"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getPagesSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getPagesSample.ts index 2e3c3a6c35..f6516ba3d9 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getPagesSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/getPagesSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createDpgCustomizationClient, { paginate } from "@msinternal/dpg-customization-rest"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/lroSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/lroSample.ts index 763a2f072e..738bbc67b1 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/lroSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/lroSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createDpgCustomizationClient, { getLongRunningPoller } from "@msinternal/dpg-customization-rest"; diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/postModelSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/postModelSample.ts index 32cb67fb79..5825fd741f 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/postModelSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/dpgCustomization/samples-dev/postModelSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createDpgCustomizationClient, { - PostModelParameters -} from "@msinternal/dpg-customization-rest"; +import createDpgCustomizationClient from "@msinternal/dpg-customization-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -19,10 +15,9 @@ dotenv.config(); async function dpgPostModel() { const client = createDpgCustomizationClient(); const mode = "uat"; - const options: PostModelParameters = { body: { hello: "test" } }; const result = await client .path("/customization/model/{mode}", mode) - .post(options); + .post({ body: { hello: "test" } }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamExistingKeySample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamExistingKeySample.ts index 0d8f471367..73262e79c6 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamExistingKeySample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamExistingKeySample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createHeaderRestClient, { - HeaderParamExistingKeyParameters -} from "@msinternal/header-rest"; +import createHeaderRestClient from "@msinternal/header-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,10 +14,9 @@ dotenv.config(); */ async function headerParamExistingKey() { const client = createHeaderRestClient(); - const options: HeaderParamExistingKeyParameters = { - headers: { "User-Agent": "overwrite" } - }; - const result = await client.path("/header/param/existingkey").post(options); + const result = await client + .path("/header/param/existingkey") + .post({ headers: { "User-Agent": "overwrite" } }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamIntegerSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamIntegerSample.ts index 7b0b4ee487..0912a03fcc 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamIntegerSample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamIntegerSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createHeaderRestClient, { - HeaderParamIntegerParameters -} from "@msinternal/header-rest"; +import createHeaderRestClient from "@msinternal/header-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,10 +14,9 @@ dotenv.config(); */ async function headerParamInteger() { const client = createHeaderRestClient(); - const options: HeaderParamIntegerParameters = { - headers: { scenario: "positive", value: 1 } - }; - const result = await client.path("/header/param/prim/integer").post(options); + const result = await client + .path("/header/param/prim/integer") + .post({ headers: { scenario: "positive", value: 1 } }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamProtectedKeySample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamProtectedKeySample.ts index 0be156627e..4b3cb10878 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamProtectedKeySample.ts +++ b/packages/autorest.typescript/test/rlcIntegration/generated/headerRest/samples-dev/headerParamProtectedKeySample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createHeaderRestClient, { - HeaderParamProtectedKeyParameters -} from "@msinternal/header-rest"; +import createHeaderRestClient from "@msinternal/header-rest"; import * as dotenv from "dotenv"; dotenv.config(); @@ -18,10 +14,9 @@ dotenv.config(); */ async function headerParamProtectedKey() { const client = createHeaderRestClient(); - const options: HeaderParamProtectedKeyParameters = { - headers: { "Content-Type": "text/html" } - }; - const result = await client.path("/header/param/protectedkey").post(options); + const result = await client + .path("/header/param/protectedkey") + .post({ headers: { "Content-Type": "text/html" } }); console.log(result); } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/package.json b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/package.json index 260f8738a4..33ed51de95 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/package.json +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "echo skipped.", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "generate:client": "autorest --typescript swagger/README.md && npm run format", "integration-test:browser": "echo skipped", "integration-test:node": "echo skipped", @@ -75,5 +75,11 @@ "rollup": "^2.66.1", "rollup-plugin-sourcemaps": "^0.6.3", "uglify-js": "^3.4.9" + }, + "//sampleConfiguration": { + "productName": "MediaTypes", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/media-types-service-rest" } } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/sample.env b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/sample.env new file mode 100644 index 0000000000..672847a3fe --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/sample.env @@ -0,0 +1,4 @@ +# App registration secret for AAD authentication +AZURE_CLIENT_SECRET= +AZURE_CLIENT_ID= +AZURE_TENANT_ID= \ No newline at end of file diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodyNoAcceptHeaderSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodyNoAcceptHeaderSample.ts new file mode 100644 index 0000000000..73e198cd60 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodyNoAcceptHeaderSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation AnalyzeBodyNoAcceptHeader + * + * @summary call operation AnalyzeBodyNoAcceptHeader + */ +async function analyzeBodyNoAcceptHeaderSample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/analyzeNoAccept") + .post({ body: "{Your body}", contentType: "application/pdf" }); + console.log(result); +} + +async function main() { + analyzeBodyNoAcceptHeaderSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodySample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodySample.ts new file mode 100644 index 0000000000..e976548386 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/analyzeBodySample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation AnalyzeBody + * + * @summary call operation AnalyzeBody + */ +async function analyzeBodySample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/analyze") + .post({ body: "{Your body}", contentType: "application/pdf" }); + console.log(result); +} + +async function main() { + analyzeBodySample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/binaryBodyWithThreeContentTypesSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/binaryBodyWithThreeContentTypesSample.ts new file mode 100644 index 0000000000..00d0f03f81 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/binaryBodyWithThreeContentTypesSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation BinaryBodyWithThreeContentTypes + * + * @summary call operation BinaryBodyWithThreeContentTypes + */ +async function binaryBodyWithThreeContentTypesSample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/binaryBodyThreeContentTypes") + .post({ body: "{Your body}", contentType: "application/json" }); + console.log(result); +} + +async function main() { + binaryBodyWithThreeContentTypesSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/binaryBodyWithTwoContentTypesSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/binaryBodyWithTwoContentTypesSample.ts new file mode 100644 index 0000000000..36b03689ac --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/binaryBodyWithTwoContentTypesSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation BinaryBodyWithTwoContentTypes + * + * @summary call operation BinaryBodyWithTwoContentTypes + */ +async function binaryBodyWithTwoContentTypesSample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/binaryBodyTwoContentTypes") + .post({ body: "{Your body}", contentType: "application/json" }); + console.log(result); +} + +async function main() { + binaryBodyWithTwoContentTypesSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/bodyThreeTypesSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/bodyThreeTypesSample.ts new file mode 100644 index 0000000000..8d981fc64f --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/bodyThreeTypesSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation BodyThreeTypes + * + * @summary call operation BodyThreeTypes + */ +async function bodyThreeTypesSample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/bodyThreeTypes") + .post({ body: "{Your body}", contentType: "application/octet-stream" }); + console.log(result); +} + +async function main() { + bodyThreeTypesSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/contentTypeWithEncodingSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/contentTypeWithEncodingSample.ts new file mode 100644 index 0000000000..16e8034011 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/contentTypeWithEncodingSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ContentTypeWithEncoding + * + * @summary call operation ContentTypeWithEncoding + */ +async function contentTypeWithEncodingSample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/contentTypeWithEncoding") + .post({ body: "{Your body}", contentType: "text/plain; charset=UTF-8" }); + console.log(result); +} + +async function main() { + contentTypeWithEncodingSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/putTextAndJsonBodySample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/putTextAndJsonBodySample.ts new file mode 100644 index 0000000000..8e234ec057 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/samples-dev/putTextAndJsonBodySample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMediaTypesClient from "@msinternal/media-types-service-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation PutTextAndJsonBody + * + * @summary call operation PutTextAndJsonBody + */ +async function putTextAndJsonBodySample() { + const client = createMediaTypesClient(); + const result = await client + .path("/mediatypes/textAndJson") + .post({ body: "{Your body}", contentType: "text/plain" }); + console.log(result); +} + +async function main() { + putTextAndJsonBodySample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/tsconfig.json b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/tsconfig.json index b0bce971f9..e6ce7e8bcd 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/tsconfig.json +++ b/packages/autorest.typescript/test/rlcIntegration/generated/mediaTypesRest/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/media-types-service-rest": ["./src/index"] } }, - "include": ["./src/**/*.ts"] + "include": ["./src/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/package.json b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/package.json index d4682d740c..4109e2e26f 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/package.json +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "echo skipped.", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "generate:client": "autorest --typescript swagger/README.md && npm run format", "integration-test:browser": "echo skipped", "integration-test:node": "echo skipped", @@ -75,5 +75,11 @@ "rollup": "^2.66.1", "rollup-plugin-sourcemaps": "^0.6.3", "uglify-js": "^3.4.9" + }, + "//sampleConfiguration": { + "productName": "MultipleInheritanceRestClient", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/multiple-inheritance-rest" } } diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/sample.env b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/sample.env new file mode 100644 index 0000000000..672847a3fe --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/sample.env @@ -0,0 +1,4 @@ +# App registration secret for AAD authentication +AZURE_CLIENT_SECRET= +AZURE_CLIENT_ID= +AZURE_TENANT_ID= \ No newline at end of file diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getCatSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getCatSample.ts new file mode 100644 index 0000000000..086f741e41 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getCatSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetCat + * + * @summary call operation GetCat + */ +async function getCatSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client.path("/multipleInheritance/cat").get(); + console.log(result); +} + +async function main() { + getCatSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getFelineSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getFelineSample.ts new file mode 100644 index 0000000000..43847b1cca --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getFelineSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetFeline + * + * @summary call operation GetFeline + */ +async function getFelineSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client.path("/multipleInheritance/feline").get(); + console.log(result); +} + +async function main() { + getFelineSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getHorseSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getHorseSample.ts new file mode 100644 index 0000000000..7d3882dc40 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getHorseSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetHorse + * + * @summary call operation GetHorse + */ +async function getHorseSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client.path("/multipleInheritance/horse").get(); + console.log(result); +} + +async function main() { + getHorseSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getKittenSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getKittenSample.ts new file mode 100644 index 0000000000..c214402347 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getKittenSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetKitten + * + * @summary call operation GetKitten + */ +async function getKittenSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client.path("/multipleInheritance/kitten").get(); + console.log(result); +} + +async function main() { + getKittenSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getPetSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getPetSample.ts new file mode 100644 index 0000000000..0f37600f7f --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/getPetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetPet + * + * @summary call operation GetPet + */ +async function getPetSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client.path("/multipleInheritance/pet").get(); + console.log(result); +} + +async function main() { + getPetSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putCatSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putCatSample.ts new file mode 100644 index 0000000000..b8112cd7c6 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putCatSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation PutCat + * + * @summary call operation PutCat + */ +async function putCatSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client + .path("/multipleInheritance/cat") + .put({ + body: { name: "{Your name}", meows: true, hisses: true, likesMilk: true }, + contentType: "application/json" + }); + console.log(result); +} + +async function main() { + putCatSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putFelineSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putFelineSample.ts new file mode 100644 index 0000000000..d26d521d00 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putFelineSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation PutFeline + * + * @summary call operation PutFeline + */ +async function putFelineSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client + .path("/multipleInheritance/feline") + .put({ + body: { meows: true, hisses: true }, + contentType: "application/json" + }); + console.log(result); +} + +async function main() { + putFelineSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putHorseSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putHorseSample.ts new file mode 100644 index 0000000000..43d0b874d5 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putHorseSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation PutHorse + * + * @summary call operation PutHorse + */ +async function putHorseSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client + .path("/multipleInheritance/horse") + .put({ + body: { name: "{Your name}", isAShowHorse: true }, + contentType: "application/json" + }); + console.log(result); +} + +async function main() { + putHorseSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putKittenSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putKittenSample.ts new file mode 100644 index 0000000000..2c51e4e0f8 --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putKittenSample.ts @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation PutKitten + * + * @summary call operation PutKitten + */ +async function putKittenSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client + .path("/multipleInheritance/kitten") + .put({ + body: { + name: "{Your name}", + meows: true, + hisses: true, + likesMilk: true, + eatsMiceYet: true + }, + contentType: "application/json" + }); + console.log(result); +} + +async function main() { + putKittenSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putPetSample.ts b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putPetSample.ts new file mode 100644 index 0000000000..8a678da92c --- /dev/null +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/samples-dev/putPetSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createMultipleInheritanceRestClient from "@msinternal/multiple-inheritance-rest"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation PutPet + * + * @summary call operation PutPet + */ +async function putPetSample() { + const client = createMultipleInheritanceRestClient(); + const result = await client + .path("/multipleInheritance/pet") + .put({ body: { name: "{Your name}" }, contentType: "application/json" }); + console.log(result); +} + +async function main() { + putPetSample(); +} + +main().catch(console.error); diff --git a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/tsconfig.json b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/tsconfig.json index b0bce971f9..186c70b3aa 100644 --- a/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/tsconfig.json +++ b/packages/autorest.typescript/test/rlcIntegration/generated/multipleInheritanceRest/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/multiple-inheritance-rest": ["./src/index"] } }, - "include": ["./src/**/*.ts"] + "include": ["./src/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataDeleteSample.ts index ddc7cdc282..f4085337f8 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataGetSample.ts index dc3fa68b61..3bf86a1cf2 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListByFarmerIdSample.ts index d27ac788a6..45b704b8b9 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListSample.ts index 6c9f7c3a5d..7c835f01b5 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/applicationDataListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDeleteSample.ts index 3ad96d5cc8..ceb6a87b51 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDownloadSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDownloadSample.ts index 5ebd8d9345..0d7305d8ff 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDownloadSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsDownloadSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsGetSample.ts index 88228ab0e4..67588af519 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsListByFarmerIdSample.ts index 5676037e84..f2a090af9f 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/attachmentsListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesCreateCascadeDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesCreateCascadeDeleteJobSample.ts index 5c65ec78cf..9c098be9ad 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesCreateCascadeDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesCreateCascadeDeleteJobSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - BoundariesCreateCascadeDeleteJobParameters, getLongRunningPoller } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -26,12 +23,11 @@ async function boundariesCreateCascadeDeleteJob() { credential ); const jobId = "JOB123"; - const options: BoundariesCreateCascadeDeleteJobParameters = { - queryParameters: { farmerId: "FARMER123", boundaryId: "BOUNDARY123" } - }; const initialResponse = await client .path("/boundaries/cascade-delete/{jobId}", jobId) - .put(options); + .put({ + queryParameters: { farmerId: "FARMER123", boundaryId: "BOUNDARY123" } + }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesDeleteSample.ts index 681efc51e7..7540e255cb 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetCascadeDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetCascadeDeleteJobDetailsSample.ts index ebe7fa3332..bf0c2c11ab 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetCascadeDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetCascadeDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetOverlapSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetOverlapSample.ts index 08b476d3a4..6c697d54dc 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetOverlapSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetOverlapSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAzureAgriFoodPlatformDataPlaneServiceClient, { - BoundariesGetOverlapParameters -} from "@msinternal/agrifood-data-plane"; +import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -26,19 +22,18 @@ async function boundariesGetOverlap() { ); const farmerId = "FARMER123"; const boundaryId = "BOUNDARY123"; - const options: BoundariesGetOverlapParameters = { - queryParameters: { - otherFarmerId: "FARMER456", - otherBoundaryId: "BOUNDARY56" - } - }; const result = await client .path( "/farmers/{farmerId}/boundaries/{boundaryId}/overlap", farmerId, boundaryId ) - .get(options); + .get({ + queryParameters: { + otherFarmerId: "FARMER456", + otherBoundaryId: "BOUNDARY56" + } + }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetSample.ts index 478f1dd424..0c659fd9b2 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListByFarmerIdSample.ts index 07171c392b..4d46ca83e3 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListSample.ts index 505c2d8e39..89ee0cb0cf 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchByFarmerIdSample.ts index 7be8721ceb..84e270b68b 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchSample.ts index bdb8de56e1..7f22b23dfe 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/boundariesSearchSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesDeleteSample.ts index 09569d242c..4f50eee384 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesGetSample.ts index d53894d134..439c26763a 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListByCropIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListByCropIdSample.ts index 5935716e61..1ba86496c5 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListByCropIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListByCropIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListSample.ts index dd5381bdde..654a4a8caf 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropVarietiesListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsDeleteSample.ts index de2161628f..1696ea4d15 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsGetSample.ts index 9ebd07f677..f80d642c06 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsListSample.ts index 14854680ce..6c2cf31641 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/cropsListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsCreateDataIngestionJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsCreateDataIngestionJobSample.ts index dc197c1a0e..fae7192470 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsCreateDataIngestionJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsCreateDataIngestionJobSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { getLongRunningPoller } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsGetDataIngestionJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsGetDataIngestionJobDetailsSample.ts index 8aaf3d801e..ed9c493ec1 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsGetDataIngestionJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmOperationsGetDataIngestionJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersCreateCascadeDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersCreateCascadeDeleteJobSample.ts index 6230321731..799289ee4b 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersCreateCascadeDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersCreateCascadeDeleteJobSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - FarmersCreateCascadeDeleteJobParameters, getLongRunningPoller } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -26,12 +23,9 @@ async function farmersCreateCascadeDeleteJob() { credential ); const jobId = "JOB123"; - const options: FarmersCreateCascadeDeleteJobParameters = { - queryParameters: { farmerId: "FARMER123" } - }; const initialResponse = await client .path("/farmers/cascade-delete/{jobId}", jobId) - .put(options); + .put({ queryParameters: { farmerId: "FARMER123" } }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersDeleteSample.ts index 826b6752bf..59542f6c45 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetCascadeDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetCascadeDeleteJobDetailsSample.ts index c8d4425324..02babe2925 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetCascadeDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetCascadeDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetSample.ts index e048920038..7a61c297ca 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersListSample.ts index cff6fd2fd8..5ce6a7d02f 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmersListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsCreateCascadeDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsCreateCascadeDeleteJobSample.ts index f57ba5aace..8f53282318 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsCreateCascadeDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsCreateCascadeDeleteJobSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - FarmsCreateCascadeDeleteJobParameters, getLongRunningPoller } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -26,12 +23,9 @@ async function farmsCreateCascadeDeleteJob() { credential ); const jobId = "JOB123"; - const options: FarmsCreateCascadeDeleteJobParameters = { - queryParameters: { farmerId: "FARMER123", farmId: "FARM123" } - }; const initialResponse = await client .path("/farms/cascade-delete/{jobId}", jobId) - .put(options); + .put({ queryParameters: { farmerId: "FARMER123", farmId: "FARM123" } }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsDeleteSample.ts index e417d82bea..7db90ad6bc 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetCascadeDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetCascadeDeleteJobDetailsSample.ts index 94d70eaf50..b4cff3c3b4 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetCascadeDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetCascadeDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetSample.ts index 7519469848..60f4cba721 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListByFarmerIdSample.ts index d517fcaa23..c2debb39c9 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListSample.ts index 9127c196f3..ca892a7b18 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/farmsListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsCreateCascadeDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsCreateCascadeDeleteJobSample.ts index f8f2f95996..5d6beb09f2 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsCreateCascadeDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsCreateCascadeDeleteJobSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - FieldsCreateCascadeDeleteJobParameters, getLongRunningPoller } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -26,12 +23,9 @@ async function fieldsCreateCascadeDeleteJob() { credential ); const jobId = "JOB123"; - const options: FieldsCreateCascadeDeleteJobParameters = { - queryParameters: { farmerId: "FARMER123", fieldId: "FIELD123" } - }; const initialResponse = await client .path("/fields/cascade-delete/{jobId}", jobId) - .put(options); + .put({ queryParameters: { farmerId: "FARMER123", fieldId: "FIELD123" } }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsDeleteSample.ts index 49c62a07cc..162d6ba3f5 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetCascadeDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetCascadeDeleteJobDetailsSample.ts index 9c09ceaea4..8c55c9761e 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetCascadeDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetCascadeDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetSample.ts index 876c71c56c..f0551bdedc 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListByFarmerIdSample.ts index c815f078e1..f42d789e4e 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListSample.ts index d4fce34c93..08eed2a4f9 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/fieldsListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataDeleteSample.ts index ff9a08e212..cbb18a0df8 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataGetSample.ts index dc35060462..59a0933060 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListByFarmerIdSample.ts index 26788fb980..ea4dd23259 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListSample.ts index 5b0e5638ce..0ee25b1ef6 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/harvestDataListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingCreateRasterizeJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingCreateRasterizeJobSample.ts index dc15d6ad7e..e9f4eb8905 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingCreateRasterizeJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingCreateRasterizeJobSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { getLongRunningPoller } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingGetRasterizeJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingGetRasterizeJobSample.ts index 91fc0f0fc3..325df1fa91 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingGetRasterizeJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/imageProcessingGetRasterizeJobSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersDeleteSample.ts index d09d80423b..fd5e339e66 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersGetSample.ts index 5bfa4a6c27..21ea327ce3 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersListSample.ts index 32daa9afdd..1ef0de0c69 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthProvidersListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensCreateCascadeDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensCreateCascadeDeleteJobSample.ts index 994e57df29..0a3f4fa5e9 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensCreateCascadeDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensCreateCascadeDeleteJobSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - OAuthTokensCreateCascadeDeleteJobParameters, getLongRunningPoller } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -26,12 +23,11 @@ async function oAuthTokensCreateCascadeDeleteJob() { credential ); const jobId = "JOBID123"; - const options: OAuthTokensCreateCascadeDeleteJobParameters = { - queryParameters: { farmerId: "FARMER123", oauthProviderId: "JOHNDEERE" } - }; const initialResponse = await client .path("/oauth/tokens/remove/{jobId}", jobId) - .put(options); + .put({ + queryParameters: { farmerId: "FARMER123", oauthProviderId: "JOHNDEERE" } + }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetCascadeDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetCascadeDeleteJobDetailsSample.ts index 89e8ad6414..467db58280 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetCascadeDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetCascadeDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetOauthConnectionLinkSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetOauthConnectionLinkSample.ts index 6bb83a2f0f..58c0d6aef4 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetOauthConnectionLinkSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensGetOauthConnectionLinkSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensListSample.ts index a20b87ffd8..c7cd0c003f 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/oAuthTokensListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataDeleteSample.ts index 19dd4e878d..1d059b9473 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataGetSample.ts index ed767775f5..5f3b24522e 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListByFarmerIdSample.ts index 58d4ced7e8..b425391a21 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListSample.ts index d29dccace2..537d77916d 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/plantingDataListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesCreateSatelliteDataIngestionJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesCreateSatelliteDataIngestionJobSample.ts index 04b22e5dda..19ad3ad21f 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesCreateSatelliteDataIngestionJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesCreateSatelliteDataIngestionJobSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { getLongRunningPoller } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesDownloadSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesDownloadSample.ts index 764d071fdc..47cb607f3d 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesDownloadSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesDownloadSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAzureAgriFoodPlatformDataPlaneServiceClient, { - ScenesDownloadParameters -} from "@msinternal/agrifood-data-plane"; +import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -24,10 +20,9 @@ async function scenesDownload() { endpoint, credential ); - const options: ScenesDownloadParameters = { - queryParameters: { filePath: "https://filePath" } - }; - const result = await client.path("/scenes/downloadFiles").get(options); + const result = await client + .path("/scenes/downloadFiles") + .get({ queryParameters: { filePath: "https://filePath" } }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesGetSatelliteDataIngestionJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesGetSatelliteDataIngestionJobDetailsSample.ts index c4bd91906c..7bdcadf16a 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesGetSatelliteDataIngestionJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesGetSatelliteDataIngestionJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesListSample.ts index 6bc79334c8..d91e3d20e8 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/scenesListSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - ScenesListParameters, paginate } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -25,14 +22,15 @@ async function scenesList() { endpoint, credential ); - const options: ScenesListParameters = { - queryParameters: { - provider: "Microsoft", - farmerId: "FARMER123", - boundaryId: "BOUNDARY123" - } - }; - const initialResponse = await client.path("/scenes").get(options); + const initialResponse = await client + .path("/scenes") + .get({ + queryParameters: { + provider: "Microsoft", + farmerId: "FARMER123", + boundaryId: "BOUNDARY123" + } + }); const pageData = paginate(client, initialResponse); const result = []; for await (const item of pageData) { diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsCreateCascadeDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsCreateCascadeDeleteJobSample.ts index db7e0d3b3f..f858bc34e5 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsCreateCascadeDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsCreateCascadeDeleteJobSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - SeasonalFieldsCreateCascadeDeleteJobParameters, getLongRunningPoller } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -26,15 +23,14 @@ async function seasonalFieldsCreateCascadeDeleteJob() { credential ); const jobId = "JOB123"; - const options: SeasonalFieldsCreateCascadeDeleteJobParameters = { - queryParameters: { - farmerId: "FARMER123", - seasonalFieldId: "SEASONALFIELD123" - } - }; const initialResponse = await client .path("/seasonal-fields/cascade-delete/{jobId}", jobId) - .put(options); + .put({ + queryParameters: { + farmerId: "FARMER123", + seasonalFieldId: "SEASONALFIELD123" + } + }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsDeleteSample.ts index 614ddeb08a..670b319f29 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetCascadeDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetCascadeDeleteJobDetailsSample.ts index 4d487f84b7..06a827b96c 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetCascadeDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetCascadeDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetSample.ts index 726a9bdc79..089fccf0f5 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListByFarmerIdSample.ts index 4a6d6b2ff6..3ef960e310 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListSample.ts index 37a8769649..58cbedd27a 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonalFieldsListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsDeleteSample.ts index b0e9622465..50f49d7ed9 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsGetSample.ts index f4b2f88392..f603eae192 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsListSample.ts index cb8542f23a..ec2c86020c 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/seasonsListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataDeleteSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataDeleteSample.ts index d9a1b9b99b..b1f1667c4c 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataDeleteSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataDeleteSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataGetSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataGetSample.ts index c743b3215b..1068fa6bb8 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataGetSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataGetSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListByFarmerIdSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListByFarmerIdSample.ts index 0ce04706ca..4e98368ab4 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListByFarmerIdSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListByFarmerIdSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListSample.ts index 83894827cf..d3f1ddc198 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/tillageDataListSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { paginate } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataDeleteJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataDeleteJobSample.ts index 66932eb90a..886c53eab8 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataDeleteJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataDeleteJobSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { getLongRunningPoller } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataIngestionJobSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataIngestionJobSample.ts index 4460870b99..35cf7eca6e 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataIngestionJobSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherCreateDataIngestionJobSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { getLongRunningPoller } from "@msinternal/agrifood-data-plane"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataDeleteJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataDeleteJobDetailsSample.ts index e49a40232b..45bef22ade 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataDeleteJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataDeleteJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataIngestionJobDetailsSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataIngestionJobDetailsSample.ts index 3becb67cf5..e28263abd7 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataIngestionJobDetailsSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherGetDataIngestionJobDetailsSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherListSample.ts b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherListSample.ts index 88ecea07f9..4315a6fdcb 100644 --- a/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherListSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/agrifood-data-plane/samples-dev/weatherListSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAzureAgriFoodPlatformDataPlaneServiceClient, { - WeatherListParameters, paginate } from "@msinternal/agrifood-data-plane"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -25,16 +22,17 @@ async function weatherList() { endpoint, credential ); - const options: WeatherListParameters = { - queryParameters: { - farmerId: "FARMER123", - boundaryId: "BOUNDARY123", - extensionId: "DTN.ClearAg", - weatherDataType: "Historical", - granularity: "Daily" - } - }; - const initialResponse = await client.path("/weather").get(options); + const initialResponse = await client + .path("/weather") + .get({ + queryParameters: { + farmerId: "FARMER123", + boundaryId: "BOUNDARY123", + extensionId: "DTN.ClearAg", + weatherDataType: "Historical", + granularity: "Daily" + } + }); const pageData = paginate(client, initialResponse); const result = []; for await (const item of pageData) { diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/batchDetectAnomalySample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/batchDetectAnomalySample.ts index 5133b7c98f..6719c5df26 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/batchDetectAnomalySample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/batchDetectAnomalySample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAnomalyDetectorRestClient, { - BatchDetectAnomalyParameters, getLongRunningPoller } from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -28,19 +25,18 @@ async function detectAnomalyWithMultivariateModel() { credential ); const modelId = "45aad126-aafd-11ea-b8fb-d89ef3400c5f"; - const options: BatchDetectAnomalyParameters = { - body: { - dataSource: - "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv", - endTime: new Date("2019-04-01T00:40:00Z"), - startTime: new Date("2019-04-01T00:15:00Z"), - topContributorCount: 10 - }, - headers: { "Content-Type": "application/json" } - }; const initialResponse = await client .path("/multivariate/models/{modelId}:detect-batch", modelId) - .post(options); + .post({ + body: { + dataSource: + "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv", + endTime: new Date("2019-04-01T00:40:00Z"), + startTime: new Date("2019-04-01T00:15:00Z"), + topContributorCount: 10 + }, + headers: { "Content-Type": "application/json" } + }); const poller = await getLongRunningPoller(client, initialResponse); const result = await poller.pollUntilDone(); console.log(result); diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/createMultivariateModelSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/createMultivariateModelSample.ts index 5a82ee089c..66dcd725b7 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/createMultivariateModelSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/createMultivariateModelSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAnomalyDetectorRestClient, { - CreateMultivariateModelParameters -} from "@msinternal/anomaly-detector-rest"; +import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -26,24 +22,25 @@ async function trainMultivariateModel() { apiVersion, credential ); - const options: CreateMultivariateModelParameters = { - body: { - alignPolicy: { - alignMode: "Outer", - fillNAMethod: "Linear", - paddingValue: 0 + const result = await client + .path("/multivariate/models") + .post({ + body: { + alignPolicy: { + alignMode: "Outer", + fillNAMethod: "Linear", + paddingValue: 0 + }, + dataSchema: "OneTable", + dataSource: + "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv", + displayName: "Devops-MultiAD", + endTime: new Date("2019-04-02T00:00:00Z"), + slidingWindow: 20, + startTime: new Date("2019-04-01T00:00:00Z") }, - dataSchema: "OneTable", - dataSource: - "https://multiadsample.blob.core.windows.net/data/sample_data_2_1000.csv", - displayName: "Devops-MultiAD", - endTime: new Date("2019-04-02T00:00:00Z"), - slidingWindow: 20, - startTime: new Date("2019-04-01T00:00:00Z") - }, - headers: { "Content-Type": "application/json" } - }; - const result = await client.path("/multivariate/models").post(options); + headers: { "Content-Type": "application/json" } + }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/deleteMultivariateModelSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/deleteMultivariateModelSample.ts index 121383ae36..76cec6db10 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/deleteMultivariateModelSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/deleteMultivariateModelSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectChangePointSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectChangePointSample.ts index c84d26caf5..d807543e97 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectChangePointSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectChangePointSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAnomalyDetectorRestClient, { - DetectChangePointParameters -} from "@msinternal/anomaly-detector-rest"; +import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -26,7 +22,7 @@ async function detectChangePointExample() { apiVersion, credential ); - const options: DetectChangePointParameters = { + const result = await client.path("/timeseries/changepoint/detect").post({ body: { customInterval: 5, granularity: "minutely", @@ -294,10 +290,7 @@ async function detectChangePointExample() { threshold: 0.99 }, headers: { "Content-Type": "application/json" } - }; - const result = await client - .path("/timeseries/changepoint/detect") - .post(options); + }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectEntireSeriesSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectEntireSeriesSample.ts index 14f65f0ad0..755d65427a 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectEntireSeriesSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectEntireSeriesSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAnomalyDetectorRestClient, { - DetectEntireSeriesParameters -} from "@msinternal/anomaly-detector-rest"; +import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -26,7 +22,7 @@ async function findAnomaliesForTheEntireSeriesInBatchExample() { apiVersion, credential ); - const options: DetectEntireSeriesParameters = { + const result = await client.path("/timeseries/entire/detect").post({ body: { granularity: "monthly", imputeMode: "auto", @@ -84,8 +80,7 @@ async function findAnomaliesForTheEntireSeriesInBatchExample() { ] }, headers: { "Content-Type": "application/json" } - }; - const result = await client.path("/timeseries/entire/detect").post(options); + }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectLastPointSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectLastPointSample.ts index 3a61787dae..d904c977f9 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectLastPointSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/detectLastPointSample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAnomalyDetectorRestClient, { - DetectLastPointParameters -} from "@msinternal/anomaly-detector-rest"; +import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -26,7 +22,7 @@ async function detectAnomalyStatusOfTheLatestPointInTimeSeriesExample() { apiVersion, credential ); - const options: DetectLastPointParameters = { + const result = await client.path("/timeseries/last/detect").post({ body: { granularity: "monthly", imputeFixedValue: 800, @@ -85,8 +81,7 @@ async function detectAnomalyStatusOfTheLatestPointInTimeSeriesExample() { ] }, headers: { "Content-Type": "application/json" } - }; - const result = await client.path("/timeseries/last/detect").post(options); + }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getBatchDetectionResultSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getBatchDetectionResultSample.ts index 42a5b86e64..5cb5e2d138 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getBatchDetectionResultSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getBatchDetectionResultSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getMultivariateModelSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getMultivariateModelSample.ts index a136ce3d6f..8641b02e08 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getMultivariateModelSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/getMultivariateModelSample.ts @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/lastDetectAnomalySample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/lastDetectAnomalySample.ts index c644b9de59..38e4cae119 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/lastDetectAnomalySample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/lastDetectAnomalySample.ts @@ -1,11 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. -import createAnomalyDetectorRestClient, { - LastDetectAnomalyParameters -} from "@msinternal/anomaly-detector-rest"; +import createAnomalyDetectorRestClient from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; import * as dotenv from "dotenv"; @@ -27,218 +23,217 @@ async function detectAnomalyWithMultivariateModel() { credential ); const modelId = "45aad126-aafd-11ea-b8fb-d89ef3400c5f"; - const options: LastDetectAnomalyParameters = { - body: { - topContributorCount: 10, - variables: [ - { - timestamps: [ - "2021-01-01T00:00:00Z", - "2021-01-01T00:01:00Z", - "2021-01-01T00:02:00Z", - "2021-01-01T00:03:00Z", - "2021-01-01T00:04:00Z", - "2021-01-01T00:05:00Z", - "2021-01-01T00:06:00Z", - "2021-01-01T00:07:00Z", - "2021-01-01T00:08:00Z", - "2021-01-01T00:09:00Z", - "2021-01-01T00:10:00Z", - "2021-01-01T00:11:00Z", - "2021-01-01T00:12:00Z", - "2021-01-01T00:13:00Z", - "2021-01-01T00:14:00Z", - "2021-01-01T00:15:00Z", - "2021-01-01T00:16:00Z", - "2021-01-01T00:17:00Z", - "2021-01-01T00:18:00Z", - "2021-01-01T00:19:00Z", - "2021-01-01T00:20:00Z", - "2021-01-01T00:21:00Z", - "2021-01-01T00:22:00Z", - "2021-01-01T00:23:00Z", - "2021-01-01T00:24:00Z", - "2021-01-01T00:25:00Z", - "2021-01-01T00:26:00Z", - "2021-01-01T00:27:00Z", - "2021-01-01T00:28:00Z", - "2021-01-01T00:29:00Z" - ], - values: [ - 0.4551378545933972, - 0.7388603950488748, - 0.201088255984052, - 0.7462812245891899, - 0.07308128850401663, - 0.33090474587393537, - 0.7544925268153315, - 0.987506336316328, - 0.6665932993421468, - 0.6308351543168672, - 0.08083310161466228, - 0.8414415588668442, - 0.514583545640453, - 0.0954489875193526, - 0.7786793231920507, - 0.41646133667960994, - 0.030176187583339287, - 0.3474214937189324, - 0.508530173413991, - 0.42451199127255046, - 0.2115944222725208, - 0.24733519545833516, - 0.8791022110982156, - 0.9479621899884665, - 0.26702703121252136, - 0.6954503497669413, - 0.1235728391488995, - 0.8214915473050647, - 0.11813002444192677, - 0.8579045951076123 - ], - variable: "Variable_1" - }, - { - timestamps: [ - "2021-01-01T00:00:00Z", - "2021-01-01T00:01:00Z", - "2021-01-01T00:02:00Z", - "2021-01-01T00:03:00Z", - "2021-01-01T00:04:00Z", - "2021-01-01T00:05:00Z", - "2021-01-01T00:06:00Z", - "2021-01-01T00:07:00Z", - "2021-01-01T00:08:00Z", - "2021-01-01T00:09:00Z", - "2021-01-01T00:10:00Z", - "2021-01-01T00:11:00Z", - "2021-01-01T00:12:00Z", - "2021-01-01T00:13:00Z", - "2021-01-01T00:14:00Z", - "2021-01-01T00:15:00Z", - "2021-01-01T00:16:00Z", - "2021-01-01T00:17:00Z", - "2021-01-01T00:18:00Z", - "2021-01-01T00:19:00Z", - "2021-01-01T00:20:00Z", - "2021-01-01T00:21:00Z", - "2021-01-01T00:22:00Z", - "2021-01-01T00:23:00Z", - "2021-01-01T00:24:00Z", - "2021-01-01T00:25:00Z", - "2021-01-01T00:26:00Z", - "2021-01-01T00:27:00Z", - "2021-01-01T00:28:00Z", - "2021-01-01T00:29:00Z" - ], - values: [ - 0.9617871613964145, - 0.24903311574778408, - 0.4920561254118613, - 0.9895601049618598, - 0.9171759283128094, - 0.5754204711105273, - 0.1811033296265634, - 0.8852311981742577, - 0.9543231904644779, - 0.7088012446094262, - 0.7843572237149014, - 0.7664787010700046, - 0.3699552325387093, - 0.504519908266789, - 0.5848930929950164, - 0.7628913396089576, - 0.8148405868900065, - 0.08540458873739332, - 0.03481976727525682, - 0.21275099339467762, - 0.9836175579199806, - 0.9321441483364282, - 0.038466608085469534, - 0.1723138437622782, - 0.8626383410218382, - 0.35053229974224254, - 0.631141662835182, - 0.0730352607990088, - 0.08886179043386, - 0.7488606040971179 - ], - variable: "Variable_2" - }, - { - timestamps: [ - "2021-01-01T00:00:00Z", - "2021-01-01T00:01:00Z", - "2021-01-01T00:02:00Z", - "2021-01-01T00:03:00Z", - "2021-01-01T00:04:00Z", - "2021-01-01T00:05:00Z", - "2021-01-01T00:06:00Z", - "2021-01-01T00:07:00Z", - "2021-01-01T00:08:00Z", - "2021-01-01T00:09:00Z", - "2021-01-01T00:10:00Z", - "2021-01-01T00:11:00Z", - "2021-01-01T00:12:00Z", - "2021-01-01T00:13:00Z", - "2021-01-01T00:14:00Z", - "2021-01-01T00:15:00Z", - "2021-01-01T00:16:00Z", - "2021-01-01T00:17:00Z", - "2021-01-01T00:18:00Z", - "2021-01-01T00:19:00Z", - "2021-01-01T00:20:00Z", - "2021-01-01T00:21:00Z", - "2021-01-01T00:22:00Z", - "2021-01-01T00:23:00Z", - "2021-01-01T00:24:00Z", - "2021-01-01T00:25:00Z", - "2021-01-01T00:26:00Z", - "2021-01-01T00:27:00Z", - "2021-01-01T00:28:00Z", - "2021-01-01T00:29:00Z" - ], - values: [ - 0.4030756879437628, - 0.15526889968448554, - 0.36352226408981103, - 0.6051200637229004, - 0.8516795018476276, - 0.2645605735279929, - 0.6810875830037345, - 0.9165894221681316, - 0.700783245230424, - 0.5624155469940331, - 0.6277289685127893, - 0.15992056539730204, - 0.6020964482827594, - 0.35937967753105915, - 0.8731686034848609, - 0.20301549117588935, - 0.029261872151168933, - 0.6261499548828445, - 0.45850782028563386, - 0.8275006940083313, - 0.032760268834037376, - 0.4485202784055029, - 0.8915691008748384, - 0.891669051517807, - 0.9469979353323046, - 0.115293087370132, - 0.08818772518459506, - 0.7426286620589166, - 0.32372247468990756, - 0.936268139507417 - ], - variable: "Variable_3" - } - ] - }, - headers: { "Content-Type": "application/json" } - }; const result = await client .path("/multivariate/models/{modelId}:detect-last", modelId) - .post(options); + .post({ + body: { + topContributorCount: 10, + variables: [ + { + timestamps: [ + "2021-01-01T00:00:00Z", + "2021-01-01T00:01:00Z", + "2021-01-01T00:02:00Z", + "2021-01-01T00:03:00Z", + "2021-01-01T00:04:00Z", + "2021-01-01T00:05:00Z", + "2021-01-01T00:06:00Z", + "2021-01-01T00:07:00Z", + "2021-01-01T00:08:00Z", + "2021-01-01T00:09:00Z", + "2021-01-01T00:10:00Z", + "2021-01-01T00:11:00Z", + "2021-01-01T00:12:00Z", + "2021-01-01T00:13:00Z", + "2021-01-01T00:14:00Z", + "2021-01-01T00:15:00Z", + "2021-01-01T00:16:00Z", + "2021-01-01T00:17:00Z", + "2021-01-01T00:18:00Z", + "2021-01-01T00:19:00Z", + "2021-01-01T00:20:00Z", + "2021-01-01T00:21:00Z", + "2021-01-01T00:22:00Z", + "2021-01-01T00:23:00Z", + "2021-01-01T00:24:00Z", + "2021-01-01T00:25:00Z", + "2021-01-01T00:26:00Z", + "2021-01-01T00:27:00Z", + "2021-01-01T00:28:00Z", + "2021-01-01T00:29:00Z" + ], + values: [ + 0.4551378545933972, + 0.7388603950488748, + 0.201088255984052, + 0.7462812245891899, + 0.07308128850401663, + 0.33090474587393537, + 0.7544925268153315, + 0.987506336316328, + 0.6665932993421468, + 0.6308351543168672, + 0.08083310161466228, + 0.8414415588668442, + 0.514583545640453, + 0.0954489875193526, + 0.7786793231920507, + 0.41646133667960994, + 0.030176187583339287, + 0.3474214937189324, + 0.508530173413991, + 0.42451199127255046, + 0.2115944222725208, + 0.24733519545833516, + 0.8791022110982156, + 0.9479621899884665, + 0.26702703121252136, + 0.6954503497669413, + 0.1235728391488995, + 0.8214915473050647, + 0.11813002444192677, + 0.8579045951076123 + ], + variable: "Variable_1" + }, + { + timestamps: [ + "2021-01-01T00:00:00Z", + "2021-01-01T00:01:00Z", + "2021-01-01T00:02:00Z", + "2021-01-01T00:03:00Z", + "2021-01-01T00:04:00Z", + "2021-01-01T00:05:00Z", + "2021-01-01T00:06:00Z", + "2021-01-01T00:07:00Z", + "2021-01-01T00:08:00Z", + "2021-01-01T00:09:00Z", + "2021-01-01T00:10:00Z", + "2021-01-01T00:11:00Z", + "2021-01-01T00:12:00Z", + "2021-01-01T00:13:00Z", + "2021-01-01T00:14:00Z", + "2021-01-01T00:15:00Z", + "2021-01-01T00:16:00Z", + "2021-01-01T00:17:00Z", + "2021-01-01T00:18:00Z", + "2021-01-01T00:19:00Z", + "2021-01-01T00:20:00Z", + "2021-01-01T00:21:00Z", + "2021-01-01T00:22:00Z", + "2021-01-01T00:23:00Z", + "2021-01-01T00:24:00Z", + "2021-01-01T00:25:00Z", + "2021-01-01T00:26:00Z", + "2021-01-01T00:27:00Z", + "2021-01-01T00:28:00Z", + "2021-01-01T00:29:00Z" + ], + values: [ + 0.9617871613964145, + 0.24903311574778408, + 0.4920561254118613, + 0.9895601049618598, + 0.9171759283128094, + 0.5754204711105273, + 0.1811033296265634, + 0.8852311981742577, + 0.9543231904644779, + 0.7088012446094262, + 0.7843572237149014, + 0.7664787010700046, + 0.3699552325387093, + 0.504519908266789, + 0.5848930929950164, + 0.7628913396089576, + 0.8148405868900065, + 0.08540458873739332, + 0.03481976727525682, + 0.21275099339467762, + 0.9836175579199806, + 0.9321441483364282, + 0.038466608085469534, + 0.1723138437622782, + 0.8626383410218382, + 0.35053229974224254, + 0.631141662835182, + 0.0730352607990088, + 0.08886179043386, + 0.7488606040971179 + ], + variable: "Variable_2" + }, + { + timestamps: [ + "2021-01-01T00:00:00Z", + "2021-01-01T00:01:00Z", + "2021-01-01T00:02:00Z", + "2021-01-01T00:03:00Z", + "2021-01-01T00:04:00Z", + "2021-01-01T00:05:00Z", + "2021-01-01T00:06:00Z", + "2021-01-01T00:07:00Z", + "2021-01-01T00:08:00Z", + "2021-01-01T00:09:00Z", + "2021-01-01T00:10:00Z", + "2021-01-01T00:11:00Z", + "2021-01-01T00:12:00Z", + "2021-01-01T00:13:00Z", + "2021-01-01T00:14:00Z", + "2021-01-01T00:15:00Z", + "2021-01-01T00:16:00Z", + "2021-01-01T00:17:00Z", + "2021-01-01T00:18:00Z", + "2021-01-01T00:19:00Z", + "2021-01-01T00:20:00Z", + "2021-01-01T00:21:00Z", + "2021-01-01T00:22:00Z", + "2021-01-01T00:23:00Z", + "2021-01-01T00:24:00Z", + "2021-01-01T00:25:00Z", + "2021-01-01T00:26:00Z", + "2021-01-01T00:27:00Z", + "2021-01-01T00:28:00Z", + "2021-01-01T00:29:00Z" + ], + values: [ + 0.4030756879437628, + 0.15526889968448554, + 0.36352226408981103, + 0.6051200637229004, + 0.8516795018476276, + 0.2645605735279929, + 0.6810875830037345, + 0.9165894221681316, + 0.700783245230424, + 0.5624155469940331, + 0.6277289685127893, + 0.15992056539730204, + 0.6020964482827594, + 0.35937967753105915, + 0.8731686034848609, + 0.20301549117588935, + 0.029261872151168933, + 0.6261499548828445, + 0.45850782028563386, + 0.8275006940083313, + 0.032760268834037376, + 0.4485202784055029, + 0.8915691008748384, + 0.891669051517807, + 0.9469979353323046, + 0.115293087370132, + 0.08818772518459506, + 0.7426286620589166, + 0.32372247468990756, + 0.936268139507417 + ], + variable: "Variable_3" + } + ] + }, + headers: { "Content-Type": "application/json" } + }); console.log(result); } diff --git a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/listMultivariateModelSample.ts b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/listMultivariateModelSample.ts index aab0271dc5..f353666f5b 100644 --- a/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/listMultivariateModelSample.ts +++ b/packages/autorest.typescript/test/smoke/generated/anomaly-detector-rest/samples-dev/listMultivariateModelSample.ts @@ -1,10 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. import createAnomalyDetectorRestClient, { - ListMultivariateModelParameters, paginate } from "@msinternal/anomaly-detector-rest"; import { AzureKeyCredential } from "@azure/core-auth"; @@ -27,12 +24,9 @@ async function listMultivariateModel() { apiVersion, credential ); - const options: ListMultivariateModelParameters = { - queryParameters: { skip: 0, top: 10 } - }; const initialResponse = await client .path("/multivariate/models") - .get(options); + .get({ queryParameters: { skip: 0, top: 10 } }); const pageData = paginate(client, initialResponse); const result = []; for await (const item of pageData) { diff --git a/packages/autorest.typescript/tsconfig.browser-test.json b/packages/autorest.typescript/tsconfig.browser-test.json index 3aaa2c6f45..bac1760158 100644 --- a/packages/autorest.typescript/tsconfig.browser-test.json +++ b/packages/autorest.typescript/tsconfig.browser-test.json @@ -38,6 +38,21 @@ ], "@msinternal/header-rest": [ "./test/rlcIntegration/generated/headerRest/src/index" + ], + "@msinternal/body-file": [ + "./test/rlcIntegration/generated/bodyFileRest/src/index" + ], + "@msinternal/http-infrastructure-rest": [ + "./test/rlcIntegration/generated/httpInfrastructureRest/src/index" + ], + "@msinternal/media-types-service-rest": [ + "./test/rlcIntegration/generated/mediaTypesRest/src/index" + ], + "@msinternal/multiple-inheritance-rest": [ + "./test/rlcIntegration/generated/multipleInheritanceRest/src/index" + ], + "@msinternal/paging-service": [ + "./test/rlcIntegration/generated/pagingRest/src/index" ] } }, diff --git a/packages/rlc-common/.eslintrc.json b/packages/rlc-common/.eslintrc.json index 9fa7b6e2fb..2d81532fb2 100644 --- a/packages/rlc-common/.eslintrc.json +++ b/packages/rlc-common/.eslintrc.json @@ -1,8 +1,16 @@ { "parser": "@typescript-eslint/parser", "parserOptions": { "project": "./tsconfig.json" }, - "plugins": ["@typescript-eslint"], - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + "plugins": [ + "@typescript-eslint", + "eslint-plugin-require-extensions", + "require-extensions" + ], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:require-extensions/recommended" + ], "rules": { "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/packages/rlc-common/package.json b/packages/rlc-common/package.json index 30ab9146f9..f6e2e6109a 100644 --- a/packages/rlc-common/package.json +++ b/packages/rlc-common/package.json @@ -49,6 +49,7 @@ "@types/mocha": "^10.0.1", "@typescript-eslint/eslint-plugin": "^5.58.0", "@typescript-eslint/parser": "^5.58.0", + "eslint-plugin-require-extensions": "0.1.3", "cross-env": "7.0.3" }, "bugs": { diff --git a/packages/rlc-common/src/buildObjectTypes.ts b/packages/rlc-common/src/buildObjectTypes.ts index 9e505abb15..070eaf17c2 100644 --- a/packages/rlc-common/src/buildObjectTypes.ts +++ b/packages/rlc-common/src/buildObjectTypes.ts @@ -353,7 +353,7 @@ function getChildDiscriminatorValues(children: ObjectSchema[]): string[] { /** * Gets a list of types a given object may extend from */ -function getImmediateParentsNames( +export function getImmediateParentsNames( objectSchema: ObjectSchema, schemaUsage: SchemaContext[] ): string[] { diff --git a/packages/rlc-common/src/buildSamples.ts b/packages/rlc-common/src/buildSamples.ts new file mode 100644 index 0000000000..65f2c54ec8 --- /dev/null +++ b/packages/rlc-common/src/buildSamples.ts @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { RLCModel, RLCSampleGroup, File as RLCFile } from "./interfaces.js"; +import { sampleTemplate } from "./static/sampleTemplate.js"; +// eslint-disable-next-line @typescript-eslint/ban-ts-comment +// @ts-ignore: to fix the handlebars issue +import hbs from "handlebars"; +import * as path from "path"; + +// Build sample files for the model based on the sample groups +export function buildSamples(model: RLCModel) { + if (!model.options || !model.options.packageDetails) { + return; + } + const sampleGroups: RLCSampleGroup[] | undefined = model.sampleGroups; + if (!sampleGroups || sampleGroups.length === 0) { + return; + } + const sampleFiles: RLCFile[] = []; + for (const sampleGroup of sampleGroups) { + const sampleGroupFileContents = hbs.compile(sampleTemplate, { + noEscape: true + }); + const filePath = path.join("samples-dev", `${sampleGroup.filename}.ts`); + sampleFiles.push({ + path: filePath, + content: sampleGroupFileContents(sampleGroup) + }); + } + return sampleFiles; +} diff --git a/packages/rlc-common/src/buildSchemaType.ts b/packages/rlc-common/src/buildSchemaType.ts index 91a4c4d9bb..596eda8acf 100644 --- a/packages/rlc-common/src/buildSchemaType.ts +++ b/packages/rlc-common/src/buildSchemaType.ts @@ -36,7 +36,6 @@ export function generateModelFiles( ) { // Track models that need to be imported const importedModels = new Set(); - const objectsDefinitions = buildObjectInterfaces( model, importedModels, diff --git a/packages/rlc-common/src/helpers/apiVersionUtil.ts b/packages/rlc-common/src/helpers/apiVersionUtil.ts index 9682b91071..c67c3d67fc 100644 --- a/packages/rlc-common/src/helpers/apiVersionUtil.ts +++ b/packages/rlc-common/src/helpers/apiVersionUtil.ts @@ -1,4 +1,4 @@ -import { ApiVersionInfo, ApiVersionPosition, UrlInfo } from "../interfaces"; +import { ApiVersionInfo, ApiVersionPosition, UrlInfo } from "../interfaces.js"; /** * Extract the path api-version detail from UrlInfo, return undefined if no valid api-version parameter diff --git a/packages/rlc-common/src/helpers/nameUtils.ts b/packages/rlc-common/src/helpers/nameUtils.ts index 4764abdf9f..3ab3b0ecc9 100644 --- a/packages/rlc-common/src/helpers/nameUtils.ts +++ b/packages/rlc-common/src/helpers/nameUtils.ts @@ -13,7 +13,8 @@ export enum NameType { Property, Parameter, Operation, - OperationGroup + OperationGroup, + Method } const Newable = [NameType.Class, NameType.Interface, NameType.OperationGroup]; @@ -118,6 +119,7 @@ function getSuffix(nameType?: NameType) { return "Param"; case NameType.Class: case NameType.Interface: + case NameType.Method: default: return "Model"; } @@ -182,6 +184,7 @@ function getCasingConvention(nameType: NameType) { case NameType.Property: case NameType.Operation: case NameType.Parameter: + case NameType.Method: return CasingConvention.Camel; } } @@ -200,12 +203,12 @@ function toCasing(str: string, casing: CasingConvention): string { const firstChar = casing === CasingConvention.Pascal ? value.charAt(0).toUpperCase() - : value.charAt(0).toLocaleLowerCase(); + : value.charAt(0).toLowerCase(); return `${firstChar}${value.substring(1)}`; } function getNameParts(name: string) { - const parts = name.split(/[-._ ]+/); + const parts = name.split(/[-._ ]+/).filter((part) => part.trim().length > 0); return parts.length > 0 ? parts : [name]; } @@ -226,5 +229,5 @@ export function camelCase( return str; } - return str.charAt(0).toLocaleLowerCase() + str.slice(1); + return str.charAt(0).toLowerCase() + str.slice(1); } diff --git a/packages/rlc-common/src/helpers/schemaHelpers.ts b/packages/rlc-common/src/helpers/schemaHelpers.ts index 2f68ef47c6..503871d78a 100644 --- a/packages/rlc-common/src/helpers/schemaHelpers.ts +++ b/packages/rlc-common/src/helpers/schemaHelpers.ts @@ -1,7 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -import { Schema } from "../interfaces.js"; +import { + ObjectSchema, + RLCModel, + Schema, + SchemaContext +} from "../interfaces.js"; export interface IsDictionaryOptions { filterEmpty?: boolean; @@ -32,3 +37,18 @@ export function isConstantSchema(schema: Schema) { } return false; } + +export function buildSchemaObjectMap(model: RLCModel) { + // include interfaces + const map = new Map(); + const allSchemas = (model.schemas ?? []).filter( + (o) => + isObjectSchema(o) && + (o as ObjectSchema).usage?.some((u) => [SchemaContext.Input].includes(u)) + ); + allSchemas.forEach((o) => { + map.set(o.name, o); + }); + + return map; +} diff --git a/packages/rlc-common/src/helpers/typeUtil.ts b/packages/rlc-common/src/helpers/typeUtil.ts new file mode 100644 index 0000000000..588caf9ef7 --- /dev/null +++ b/packages/rlc-common/src/helpers/typeUtil.ts @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { Schema } from "../interfaces.js"; + +export function isRecord(type: string) { + return /^Record<([a-zA-Z]+),(\s*)(?.+)>$/.test(type); +} + +export function getRecordType(type: string) { + return /^Record<([a-zA-Z]+),(\s*)(?.+)>$/.exec(type)?.groups?.type; +} + +export function isArray(type: string) { + return isArrayObject(type) || isNativeArray(type); +} + +export function isArrayObject(type: string) { + return /(^Array<(.+)>$)/g.test(type); +} + +export function getArrayObjectType(type: string) { + return /^Array<(?.+)>$/g.exec(type)?.groups?.type; +} + +export function isNativeArray(type: string) { + return /(^.+)\[\]$/g.test(type); +} + +export function getNativeArrayType(type: string) { + return /(?.+)\[\]/g.exec(type)?.groups?.type; +} + +export function isUnion(type: string) { + const members = type.split("|").map((m) => m.trim()); + return members.length > 1 && !isStringLiteral(type) && !isRecord(type); +} + +export function getUnionType(type: string) { + return leaveBracket(type.split("|").map((m) => m.trim())[0]); +} + +export function leaveBracket(type: string) { + if (!type || type.length < 2) { + return type; + } else if (type.startsWith("(") && type.endsWith(")")) { + return type.slice(1, type.length - 1); + } + return type; +} + +export function leaveStringQuotes(str: string) { + if (isStringLiteral(str)) { + return str.slice(1, str.length - 1); + } + return str; +} + +export enum TypeScriptType { + string, + date, + number, + boolean, + constant, + record, + array, + object, + union, + unknown, + enum +} + +export function toTypeScriptTypeFromSchema( + schema: Schema +): TypeScriptType | undefined { + schema.type = schema.type.trim(); + if ( + schema.type === "string" && + schema.typeName === "Date | string" && + schema.outputTypeName === "string" + ) { + return TypeScriptType.date; + } else if (schema.enum && schema.enum.length > 0) { + if (schema.type === "union" || schema.type === "object") { + // Include both union and named union + return TypeScriptType.union; + } else { + // Include both extensible and fixed enum + return TypeScriptType.enum; + } + } else if ( + schema.isConstant === true || + isConstant(schema.typeName ?? schema.type) + ) { + return TypeScriptType.constant; + } else if (schema.type === "number") { + return TypeScriptType.number; + } else if (schema.type === "boolean") { + return TypeScriptType.boolean; + } else if (schema.type === "string") { + return TypeScriptType.string; + } else if (schema.type === "unknown") { + return TypeScriptType.unknown; + } else if (schema.type === "dictionary") { + return TypeScriptType.record; + } else if (schema.type === "array") { + return TypeScriptType.array; + } else if (schema.type === "object") { + return TypeScriptType.object; + } +} + +export function toTypeScriptTypeFromName( + typeName: string +): TypeScriptType | undefined { + typeName = typeName.trim(); + if (typeName === "Date") { + return TypeScriptType.date; + } else if (typeName === "string") { + return TypeScriptType.string; + } else if (typeName === "number") { + return TypeScriptType.number; + } else if (typeName === "boolean") { + return TypeScriptType.boolean; + } else if (typeName === "unknown") { + return TypeScriptType.unknown; + } else if (isConstant(typeName)) { + return TypeScriptType.constant; + } else if (isRecord(typeName)) { + return TypeScriptType.record; + } else if (isArray(typeName)) { + return TypeScriptType.array; + } else if (isUnion(typeName)) { + return TypeScriptType.union; + } +} + +export function isConstant(typeName: string) { + return ( + ["never", "null"].includes(typeName) || + isBoolLiteral(typeName) || + isNumericLiteral(typeName) || + isStringLiteral(typeName) + ); +} + +export function isNumericLiteral(str: string) { + if (typeof str !== "string") return false; + return !isNaN(Number(str)) && !isNaN(parseFloat(str)); +} + +export function isBoolLiteral(str: string) { + return str === "true" || str === "false"; +} + +export function isStringLiteral(type: string) { + if (type.length < 2) { + return false; + } + const first = type[0]; + const lastPos = type.length - 1; + return ( + first === type[lastPos] && + (first === '"' || first === "'") && + type.indexOf(first, 1) === lastPos + ); +} diff --git a/packages/rlc-common/src/helpers/valueGenerationUtil.ts b/packages/rlc-common/src/helpers/valueGenerationUtil.ts new file mode 100644 index 0000000000..9ff28e179f --- /dev/null +++ b/packages/rlc-common/src/helpers/valueGenerationUtil.ts @@ -0,0 +1,251 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +import { getImmediateParentsNames } from "../buildObjectTypes.js"; +import { + ArraySchema, + DictionarySchema, + ObjectSchema, + Schema, + SchemaContext +} from "../interfaces.js"; +import { + TypeScriptType, + getArrayObjectType, + getNativeArrayType, + getRecordType, + getUnionType, + isArrayObject, + isNativeArray, + leaveBracket, + leaveStringQuotes, + toTypeScriptTypeFromName, + toTypeScriptTypeFromSchema +} from "./typeUtil.js"; + +/** + * Generate parameter type value for the given type and parameter name + * @param type the typescript type + * @param parameterName the parameter name + * @param schemaMap the schema info to help generate the value + * @param path optional path to help detect self reference + * @param _allowMockValue the flag to indicate whether to allow mock value, currently we always generate mock value + * @returns + */ +export function generateParameterTypeValue( + type: string, + parameterName: string, + schemaMap: Map, + path: Set = new Set(), + _allowMockValue = true +): string | undefined { + type = leaveBracket(type?.trim()); + let tsType: TypeScriptType | undefined; + // Give priority to suggest the ts-type from schema + if (schemaMap.has(type)) { + tsType = toTypeScriptTypeFromSchema(schemaMap.get(type)!); + } + // Fallback to suggest ts-type from the type iteself + if (!tsType) { + tsType = toTypeScriptTypeFromName(type); + } + switch (tsType) { + case TypeScriptType.string: + return `"{Your ${leaveStringQuotes(parameterName)}}"`; + case TypeScriptType.number: + return "123"; + case TypeScriptType.boolean: + return "true"; + case TypeScriptType.date: + return "new Date()"; + case TypeScriptType.unknown: + return `"Unknown Type"`; + case TypeScriptType.object: { + return generateObjectValues(type, parameterName, schemaMap, path); + } + case TypeScriptType.array: { + return generateArrayValues(type, parameterName, schemaMap, path); + } + case TypeScriptType.record: { + return generateRecordValues(type, parameterName, schemaMap, path); + } + case TypeScriptType.enum: { + return mockEnumValues(type, parameterName, schemaMap, path); + } + case TypeScriptType.union: { + return mockUnionValues(type, parameterName, schemaMap, path); + } + case TypeScriptType.constant: + return type; + } + return `undefined /**FIXME */`; +} + +function mockEnumValues( + type: string, + parameterName: string, + schemaMap: Map, + path: Set = new Set() +) { + const schema = schemaMap.get(type); + if (schema && schema.enum && schema.enum.length > 0) { + const first = schema.enum[0]; + return typeof first === "string" ? `"${first}"` : `${first}`; + } + return generateParameterTypeValue( + getUnionType(type), + parameterName, + schemaMap, + path + ); +} + +function mockUnionValues( + type: string, + parameterName: string, + schemaMap: Map, + path: Set = new Set() +) { + const schema = schemaMap.get(type); + if (schema && schema.enum && schema.enum.length > 0) { + return generateParameterTypeValue( + getAccurateTypeName(schema.enum[0]) ?? schema.enum[0], + parameterName, + schemaMap, + path + ); + } + return generateParameterTypeValue( + getUnionType(type), + parameterName, + schemaMap, + path + ); +} + +function generateRecordValues( + type: string, + parameterName: string, + schemaMap: Map, + path: Set = new Set() +) { + let recordType = getRecordType(type); + const schema = schemaMap.get(type) as DictionarySchema; + if (schema && schema.additionalProperties) { + recordType = getAccurateTypeName(schema.additionalProperties); + addToSchemaMap(schemaMap, schema.additionalProperties); + } + + return recordType + ? `{"key": ${generateParameterTypeValue( + recordType, + parameterName, + schemaMap, + path + )}}` + : `{}`; +} + +function generateArrayValues( + type: string, + parameterName: string, + schemaMap: Map, + path: Set = new Set() +) { + let arrayType; + const schema = schemaMap.get(type) as ArraySchema; + if (schema && schema.items) { + arrayType = getAccurateTypeName(schema.items); + addToSchemaMap(schemaMap, schema.items); + } else if (isArrayObject(type)) { + arrayType = getArrayObjectType(type); + } else if (isNativeArray(type)) { + arrayType = getNativeArrayType(type); + } + const itemValue = arrayType + ? generateParameterTypeValue(arrayType, parameterName, schemaMap, path) + : undefined; + return itemValue ? `[${itemValue}]` : `[]`; +} + +function generateObjectValues( + type: string, + _parameterName: string, + schemaMap: Map, + path: Set = new Set() +) { + if (path.has(type)) { + // skip generating if self referenced + return `{} as any /**FIXME */`; + } + path.add(type); + // Extract all properties from the schema + const allProperties = getAllProperties(schemaMap.get(type), schemaMap); + const values = extractObjectProperties(allProperties, schemaMap, path); + + path.delete(type); + return `{${values.join(", ")}}`; +} + +function getAllProperties( + schema?: ObjectSchema, + schemaMap: Map = new Map() +): Map { + const propertiesMap: Map = new Map(); + if (!schema) { + return new Map(); + } + getImmediateParentsNames(schema, [SchemaContext.Input])?.forEach((p) => { + const parentProperties = getAllProperties(schemaMap.get(p), schemaMap); + for (const prop of parentProperties.keys()) { + propertiesMap.set(prop, parentProperties.get(prop)!); + } + }); + for (const prop in schema.properties) { + propertiesMap.set(prop, schema.properties[prop]); + } + return propertiesMap; +} + +function extractObjectProperties( + properties: Map, + schemaMap: Map = new Map(), + path: Set = new Set() +) { + const values: string[] = []; + for (const name of properties.keys()) { + const property = properties.get(name); + if (!property || property.readOnly || property.type === "never") { + continue; + } + addToSchemaMap(schemaMap, property); + values.push( + `${name}: ` + + generateParameterTypeValue( + getAccurateTypeName(property), + name, + schemaMap, + path + ) + ); + } + return values; +} + +function getAccurateTypeName(schema: Schema) { + // For extensible enum, fallback to use the type + if (schema.typeName === "string" && schema.enum && schema.enum.length > 0) { + return schema.type; + } + return schema.typeName ?? schema.type; +} + +function addToSchemaMap(schemaMap: Map, schema: Schema) { + const type = getAccurateTypeName(schema); + if ( + !schemaMap.has(type) && + !["string", "number", "boolean"].includes(schema.type) + ) { + schemaMap.set(type, schema); + } +} diff --git a/packages/rlc-common/src/index.ts b/packages/rlc-common/src/index.ts index 3d16dd6148..423228345b 100644 --- a/packages/rlc-common/src/index.ts +++ b/packages/rlc-common/src/index.ts @@ -10,6 +10,8 @@ export * from "./buildResponseTypes.js"; export * from "./helpers/shortcutMethods.js"; export * from "./helpers/nameUtils.js"; export * from "./helpers/operationHelpers.js"; +export * from "./helpers/valueGenerationUtil.js"; +export * from "./helpers/schemaHelpers.js"; export * from "./buildParameterTypes.js"; export * from "./buildIsUnexpectedHelper.js"; export * from "./buildTopLevelIndexFile.js"; @@ -30,3 +32,5 @@ export * from "./metadata/buildLicenseFile.js"; export * from "./buildSerializeHelper.js"; export * from "./helpers/apiVersionUtil.js"; export * from "./buildLogger.js"; +export * from "./buildSamples.js"; +export * from "./transformSampleGroups.js"; diff --git a/packages/rlc-common/src/interfaces.ts b/packages/rlc-common/src/interfaces.ts index 215c8cca61..c37633a740 100644 --- a/packages/rlc-common/src/interfaces.ts +++ b/packages/rlc-common/src/interfaces.ts @@ -13,6 +13,42 @@ export interface RLCModel { helperDetails?: HelperFunctionDetails; urlInfo?: UrlInfo; telemetryOptions?: TelemetryInfo; + sampleGroups?: RLCSampleGroup[]; +} + +/** + * A group of samples in operation_id level and they are used to generate in a sample file + */ +export interface RLCSampleGroup { + filename: string; + clientPackageName: string; + defaultFactoryName: string; + samples: RLCSampleDetail[]; + importedTypes?: string[]; +} + +/** + * An independent sample detail and it will be wrapped as a func + */ +export interface RLCSampleDetail { + /** + * metadata for comments + */ + description: string; + originalFileLocation?: string; + name: string; + path: string; + defaultFactoryName: string; + clientParamAssignments: string[]; + pathParamAssignments: string[]; + methodParamAssignments: string[]; + clientParamNames: string; + pathParamNames: string; + methodParamNames: "options" | "" | string; + method: string; + isLRO: boolean; + isPaging: boolean; + useLegacyLro: boolean; } export interface TelemetryInfo { @@ -187,6 +223,8 @@ export interface Schema { alias?: string; outputAlias?: string; fromCore?: boolean; + enum?: any[]; + isConstant?: boolean; } export interface ObjectSchema extends Schema { @@ -207,6 +245,11 @@ export interface ObjectSchema extends Schema { export interface DictionarySchema extends Schema { valueTypeName?: string; outputValueTypeName?: string; + additionalProperties?: Schema; +} + +export interface ArraySchema extends Schema { + items?: Schema; } export interface Property extends Schema {} @@ -242,7 +285,9 @@ export interface ParameterBodyMetadata { body?: ParameterBodySchema[]; } -export type ParameterBodySchema = Schema; +export interface ParameterBodySchema extends Schema { + oriSchema?: Schema; +} export interface ParameterMetadata { type: "query" | "path" | "header"; name: string; @@ -267,6 +312,18 @@ export type ResponseHeaderSchema = Schema; export type ResponseBodySchema = Schema; export type ContentBuilder = { - (model: RLCModel): File | undefined; - (model: RLCModel, hasSampleGenerated?: boolean): File | undefined; + (model: RLCModel): File | File[] | undefined; }; + +export type SampleParameterPosition = "client" | "path" | "method"; + +export type SampleParameters = Record< + SampleParameterPosition, + SampleParameter[] +>; + +export interface SampleParameter { + name: string; + assignment?: string; + value?: string; +} diff --git a/packages/rlc-common/src/metadata/buildPackageFile.ts b/packages/rlc-common/src/metadata/buildPackageFile.ts index 8df092a2b1..18109eddec 100644 --- a/packages/rlc-common/src/metadata/buildPackageFile.ts +++ b/packages/rlc-common/src/metadata/buildPackageFile.ts @@ -14,10 +14,10 @@ let hasPaging = false; let hasLRO = false; const clientFilePaths: string[] = []; -export function buildPackageFile(model: RLCModel, hasSamplesGenerated = false) { +export function buildPackageFile(model: RLCModel) { const project = new Project(); const filePath = "package.json"; - const packageJsonContents = restLevelPackage(model, hasSamplesGenerated); + const packageJsonContents = restLevelPackage(model); // return direclty if no content generated if (!packageJsonContents) { return; @@ -40,7 +40,7 @@ export function buildPackageFile(model: RLCModel, hasSamplesGenerated = false) { * This function defines the REST Level client package.json file * or High Level Client */ -function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) { +function restLevelPackage(model: RLCModel) { if (!model.options || !model.options.packageDetails) { return; } @@ -72,7 +72,7 @@ function restLevelPackage(model: RLCModel, hasSamplesGenerated: boolean) { generateTest = generateTest === true || generateTest === undefined; generateSample = (generateSample === true || generateSample === undefined) && - hasSamplesGenerated; + (model.sampleGroups ?? []).length > 0; const clientPackageName = packageDetails.name; let apiRefUrlQueryParameter: string = ""; packageDetails.version = packageDetails.version ?? "1.0.0-beta.1"; diff --git a/packages/rlc-common/src/metadata/buildTsConfig.ts b/packages/rlc-common/src/metadata/buildTsConfig.ts index 98e84b33f8..dcf1c3b300 100644 --- a/packages/rlc-common/src/metadata/buildTsConfig.ts +++ b/packages/rlc-common/src/metadata/buildTsConfig.ts @@ -39,14 +39,14 @@ const restLevelTsConfigNotInAzureSdkForJs: Record = { include: ["./src/**/*.ts"] }; -export function buildTsConfig(model: RLCModel, hasSamplesGenerated = false) { +export function buildTsConfig(model: RLCModel) { const { packageDetails, azureSdkForJs } = model.options || {}; let { generateTest, generateSample } = model.options || {}; // Take the undefined as true by default generateTest = generateTest === true || generateTest === undefined; generateSample = (generateSample === true || generateSample === undefined) && - hasSamplesGenerated; + (model.sampleGroups ?? []).length > 0; const clientPackageName = packageDetails?.name ?? ""; const project = new Project(); diff --git a/packages/rlc-common/src/static/paginateContent.ts b/packages/rlc-common/src/static/paginateContent.ts index 48f146c05b..db871d05c9 100644 --- a/packages/rlc-common/src/static/paginateContent.ts +++ b/packages/rlc-common/src/static/paginateContent.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + export const paginateContent = ` import { getPagedAsyncIterator, diff --git a/packages/rlc-common/src/static/pollingContent.ts b/packages/rlc-common/src/static/pollingContent.ts index e258c701b5..6bf61f8c35 100644 --- a/packages/rlc-common/src/static/pollingContent.ts +++ b/packages/rlc-common/src/static/pollingContent.ts @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + export const pollingContent = ` import { Client, HttpResponse } from "@azure-rest/core-client"; {{#if useLegacyLro}} diff --git a/packages/rlc-common/src/static/sampleTemplate.ts b/packages/rlc-common/src/static/sampleTemplate.ts new file mode 100644 index 0000000000..e27b992af0 --- /dev/null +++ b/packages/rlc-common/src/static/sampleTemplate.ts @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +export const sampleTemplate = ` +{{#each importedTypes}} +{{this}} +{{/each}} +import * as dotenv from "dotenv"; + +dotenv.config(); + +{{#each samples}} +/** + * This sample demonstrates how to {{this.description}} + * + * @summary {{this.description}} + {{#if this.originalFileLocation}} + * x-ms-original-file: {{this.originalFileLocation}} + {{/if}} + */ +async function {{name}}() { + {{#each this.clientParamAssignments}} + {{this}} + {{/each}} + const client = {{this.defaultFactoryName}}({{this.clientParamNames}}); + {{#each this.pathParamAssignments}} + {{this}} + {{/each}} + {{#each this.methodParamAssignments}} + {{this}} + {{/each}} + {{#if this.isPaging}} + const initialResponse = await client.path({{this.pathParamNames}}).{{method}}({{methodParamNames}}); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + {{else if this.isLRO}} + const initialResponse ={{#unless this.useLegacyLro}} await{{/unless}} client.path({{this.pathParamNames}}).{{method}}({{methodParamNames}}); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + {{else}} + const result = await client.path({{this.pathParamNames}}).{{method}}({{methodParamNames}}); + {{/if}} + console.log(result); +} + +{{/each}} + +async function main() { +{{#each samples}} + {{this.name}}(); +{{/each}} +} + +main().catch(console.error); +`; diff --git a/packages/rlc-common/src/transformSampleGroups.ts b/packages/rlc-common/src/transformSampleGroups.ts new file mode 100644 index 0000000000..cac59c9d72 --- /dev/null +++ b/packages/rlc-common/src/transformSampleGroups.ts @@ -0,0 +1,417 @@ +import { generateParameterTypeValue } from "./helpers/valueGenerationUtil.js"; +import { getClientName } from "./helpers/nameConstructors.js"; +import { normalizeName, NameType, camelCase } from "./helpers/nameUtils.js"; +import { buildSchemaObjectMap } from "./helpers/schemaHelpers.js"; +import { + RLCModel, + RLCSampleGroup, + Paths, + OperationMethod, + RLCSampleDetail, + SampleParameters, + SampleParameter, + Schema, + PathMetadata, + OperationParameter +} from "./interfaces.js"; + +/** + * Transform the sample data based RLC detail e.g path, operations & schemas + * @param model RLC detail + * @param allowMockValue allow to mock value if not exist, currently we always generate mock value + * @returns Generated sample data or undefined if not support to generate + */ +export function transformSampleGroups(model: RLCModel, allowMockValue = true) { + if (model.options?.multiClient || model.options?.isModularLibrary) { + // Not support to generate if multiple clients + // Not support to generate if modular libraries + return; + } + if ( + (model.sampleGroups && model.sampleGroups.length > 0) || + !allowMockValue + ) { + // Skip to transform if already has sample data + // Skip to transform if not allow to mock value + return; + } + const rlcSampleGroups: RLCSampleGroup[] = []; + // Get all paths + const paths: Paths = model.paths; + const clientName = getClientName(model); + const clientInterfaceName = clientName.endsWith("Client") + ? `${clientName}` + : `${clientName}Client`; + const defaultFactoryName = normalizeName( + camelCase(`create ${clientInterfaceName}`), + NameType.Method + ); + const packageName = model.options?.packageDetails?.name ?? ""; + const methodParameterMap = buildMethodParamMap(model); + const schemaObjectMap = buildSchemaObjectMap(model); + for (const path in paths) { + const pathDetails = paths[path]; + const methods = pathDetails.methods; + for (const method in methods) { + const importedDict: Record> = {}; + const detail: OperationMethod = methods[method][0]; + const operatonConcante = getOperationConcate( + detail.operationName, + pathDetails.operationGroupName, + model.options?.sourceFrom + ); + const operationPrefix = normalizeName( + camelCase(transformSpecialLetterToSpace(operatonConcante)), + NameType.Operation + ); + const sampleGroup: RLCSampleGroup = { + filename: `${operationPrefix}Sample`, + defaultFactoryName, + clientPackageName: packageName, + samples: [] + }; + + // initialize the sample + const sample: RLCSampleDetail = { + description: `call operation ${detail.operationName}`, + name: `${operationPrefix}Sample`, + path, + defaultFactoryName, + clientParamAssignments: [], + pathParamAssignments: [], + methodParamAssignments: [], + clientParamNames: "", + pathParamNames: "", + methodParamNames: "", + method, + isLRO: detail.operationHelperDetail?.lroDetails?.isLongRunning ?? false, + isPaging: detail.operationHelperDetail?.isPageable ?? false, + useLegacyLro: false + }; + // client-level, path-level and method-level parameter preparation + const parameters: SampleParameters = { + client: convertClientLevelParameters( + model, + importedDict, + schemaObjectMap + ), + path: convertPathLevelParameters(pathDetails, path, schemaObjectMap), + method: convertMethodLevelParameters( + methods[method], + schemaObjectMap, + methodParameterMap.get(operatonConcante) + ) + }; + // enrich parameter details + enrichParameterInSample(sample, parameters); + // enrich LRO and pagination info + enrichLROAndPagingInSample(detail, importedDict, packageName); + sampleGroup.samples.push(sample); + rlcSampleGroups.push(sampleGroup); + enrichImportedString( + sampleGroup, + importedDict, + defaultFactoryName, + packageName + ); + } + } + return rlcSampleGroups; +} + +function enrichLROAndPagingInSample( + operation: OperationMethod, + importedDict: Record>, + packageName: string +) { + const isLRO = + operation.operationHelperDetail?.lroDetails?.isLongRunning ?? false, + isPaging = operation.operationHelperDetail?.isPageable ?? false; + if (isPaging) { + if (isLRO) { + // TODO: report warning this is not supported + } + addValueInImportedDict(packageName, "paginate", importedDict); + } else if (isLRO) { + addValueInImportedDict(packageName, "getLongRunningPoller", importedDict); + } +} + +function transformSpecialLetterToSpace(str: string) { + if (!str) { + return str; + } + return str + .replace(/_/g, " ") + .replace(/\//g, " Or ") + .replace(/,|\.|\(|\)/g, " ") + .replace("'s ", " "); +} + +const tokenCredentialPackage = "@azure/identity"; +const apiKeyCredentialPackage = "@azure/core-auth"; + +function enrichImportedString( + sampleGroup: RLCSampleGroup, + importedDict: Record>, + defaultFactoryName: string, + packageName: string +) { + const importedTypes: string[] = []; + if (!importedDict[packageName] || importedDict[packageName].size === 0) { + importedTypes.push(`import ${defaultFactoryName} from "${packageName}";`); + } + for (const key in importedDict) { + const values = Array.from(importedDict[key]).join(", "); + const hasDefaultFactory = + key === packageName ? `${defaultFactoryName},` : ""; + importedTypes.push( + `import ${hasDefaultFactory} { ${values} } from "${key}";` + ); + } + sampleGroup.importedTypes = importedTypes; +} + +function enrichParameterInSample( + sample: RLCSampleDetail, + parameters: SampleParameters +) { + sample.clientParamAssignments = getAssignmentStrArray(parameters.client); + sample.clientParamNames = getContactParameterNames(parameters.client); + sample.pathParamAssignments = getAssignmentStrArray(parameters.path); + sample.pathParamNames = getContactParameterNames(parameters.path); + // Directly apply the inline option value as method parameter + sample.methodParamNames = + parameters.method.length > 0 ? parameters.method[0].value ?? "" : ""; +} + +function getAssignmentStrArray(parameters: SampleParameter[]) { + return parameters.filter((p) => !!p.assignment).map((p) => p.assignment!); +} + +function getContactParameterNames(parameters: SampleParameter[]) { + return parameters + .filter((p) => p.name != null) + .map((p) => p.name!) + .join(","); +} + +function convertClientLevelParameters( + model: RLCModel, + importedDict: Record>, + schemaMap: Map +): SampleParameter[] { + if (!model.options) { + return []; + } + const clientParams: SampleParameter[] = []; + const urlParameters = model?.urlInfo?.urlParameters?.filter( + // Do not include parameters with constant values in the signature, these should go in the options bag + (p) => p.value === undefined + ); + const { addCredentials, credentialScopes, credentialKeyHeaderName } = + model.options; + const hasUrlParameter = !!urlParameters, + hasCredentials = + addCredentials && + ((credentialScopes && credentialScopes.length > 0) || + credentialKeyHeaderName); + + if (hasUrlParameter) { + // convert the host parameters in url + const clientParamAssignments = urlParameters.map((urlParameter) => { + const urlValue = generateParameterTypeValue( + urlParameter.type, + urlParameter.name, + schemaMap + ); + const normalizedName = normalizeName( + urlParameter.name, + NameType.Parameter + ); + return { + name: normalizedName, + assignment: `const ${normalizedName} = ` + urlValue + `;` + }; + }); + + clientParams.push(...clientParamAssignments); + } + if (hasCredentials) { + // Currently only support token credential + if (credentialKeyHeaderName) { + clientParams.push({ + name: "credential", + assignment: `const credential = new AzureKeyCredential("{Your API key}");` + }); + addValueInImportedDict( + apiKeyCredentialPackage, + "AzureKeyCredential", + importedDict + ); + } else { + clientParams.push({ + name: "credential", + assignment: "const credential = new DefaultAzureCredential();" + }); + addValueInImportedDict( + tokenCredentialPackage, + "DefaultAzureCredential", + importedDict + ); + } + } + return clientParams; +} + +function convertPathLevelParameters( + pathDetail: PathMetadata, + path: string, + schemaMap: Map +): SampleParameter[] { + const pathItself = { + name: `"${path}"` + }; + const pathParams = (pathDetail || []).pathParameters.map((p) => { + const pathParam: SampleParameter = { + name: normalizeName(p.name, NameType.Parameter) + }; + const value = generateParameterTypeValue(p.type, p.name, schemaMap); + pathParam.assignment = `const ${pathParam.name} =` + value + `;`; + return pathParam; + }); + return [pathItself].concat(pathParams); +} + +function convertMethodLevelParameters( + methods: OperationMethod[], + schemaMap: Map, + operationParameter?: OperationParameter +): SampleParameter[] { + if ( + !methods || + methods.length === 0 || + !operationParameter || + operationParameter.parameters.length === 0 + ) { + return []; + } + const rawMethodParams = operationParameter.parameters; + const method = methods[0]; + const requestParameter = rawMethodParams[0]; + const hasInputParams = !!rawMethodParams && rawMethodParams.length > 0, + requireParam = !method.hasOptionalOptions; + if (!hasInputParams && !requireParam) { + return []; + } + + const allSideAssignments = [], + querySideAssignments: string[] = [], + headerSideAssignments: string[] = []; + if ( + !!requestParameter.body && + requestParameter.body && + requestParameter.body.body && + requestParameter.body.body?.length > 0 + ) { + const body = requestParameter.body.body[0]; + const bodyTypeName = body.typeName ?? body.type; + if (bodyTypeName !== "string" && body.oriSchema) { + schemaMap.set(bodyTypeName, body.oriSchema); + } + allSideAssignments.push( + ` body: ` + generateParameterTypeValue(bodyTypeName, "body", schemaMap) + ); + } + + requestParameter.parameters + ?.filter((p) => p.type === "query") + .forEach((p) => { + const name = `${p.name}`; + querySideAssignments.push( + `${name}: ` + generateParameterTypeValue(p.param.type, name, schemaMap) + ); + }); + + if (querySideAssignments.length > 0) { + allSideAssignments.push( + ` queryParameters: { ` + querySideAssignments.join(", ") + `}` + ); + } + requestParameter.parameters + ?.filter((p) => p.type === "header") + .filter((p) => p.name.toLowerCase() !== "contenttype") + .forEach((p) => { + const name = `${p.name}`; + headerSideAssignments.push( + `${name}: ` + generateParameterTypeValue(p.param.type, name, schemaMap) + ); + }); + if (headerSideAssignments.length > 0) { + allSideAssignments.push( + ` headers: { ` + headerSideAssignments.join(", ") + `}` + ); + } + const contentType = requestParameter.parameters + ?.filter((p) => p.type === "header") + .filter((p) => p.name.toLowerCase() === "contenttype"); + if (contentType && contentType.length > 0) { + allSideAssignments.push( + ` ${contentType[0].name}: ` + + generateParameterTypeValue( + contentType[0].param.type, + contentType[0].name, + schemaMap + ) + ); + } + let value: string = `{}`; + if (allSideAssignments.length > 0) { + value = `{ ` + allSideAssignments.join(", ") + `}`; + } else { + return []; + } + + const optionParam: SampleParameter = { + name: "options", + assignment: `const options =` + value + `;`, + value + }; + return [optionParam]; +} + +function addValueInImportedDict( + key: string, + val: string, + importedDict: Record> +) { + if (!importedDict[key]) { + importedDict[key] = new Set(); + } + importedDict[key].add(val); +} + +function buildMethodParamMap(model: RLCModel): Map { + const map = new Map(); + (model.parameters ?? []).forEach((p) => { + const operatonConcante = getOperationConcate( + p.operationName, + p.operationGroup, + model.options?.sourceFrom + ); + map.set(operatonConcante, p); + }); + return map; +} + +function getOperationConcate( + opName: string, + opGroup: string, + sourceFrom?: string +) { + return sourceFrom === "Swagger" + ? opGroup === "" || opGroup === "Client" + ? opName + : `${opGroup}${opName}` + : `${opGroup}_${opName}`; +} diff --git a/packages/rlc-common/test/helpers/typeUtil.spec.ts b/packages/rlc-common/test/helpers/typeUtil.spec.ts new file mode 100644 index 0000000000..ddabcac40a --- /dev/null +++ b/packages/rlc-common/test/helpers/typeUtil.spec.ts @@ -0,0 +1,295 @@ +import { expect } from "chai"; +import "mocha"; +import { + TypeScriptType, + getArrayObjectType, + getNativeArrayType, + getRecordType, + getUnionType, + isArray, + isBoolLiteral, + isConstant, + isNumericLiteral, + isRecord, + isStringLiteral, + isUnion, + leaveBracket, + leaveStringQuotes, + toTypeScriptTypeFromName, + toTypeScriptTypeFromSchema +} from "../../src/helpers/typeUtil.js"; + +describe("#isStringLiteral", () => { + it("should return true if the string is quoted", () => { + expect(isStringLiteral(`''`)).to.be.true; + expect(isStringLiteral(`""`)).to.be.true; + expect(isStringLiteral(`"'xxx'"`)).to.be.true; + expect(isStringLiteral(`"string"`)).to.be.true; + expect(isStringLiteral(`"string|test|aaa "`)).to.be.true; + expect(isStringLiteral(`'string'`)).to.be.true; + expect(isStringLiteral(`' string ssss '`)).to.be.true; + expect( + isStringLiteral( + `"啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€"` + ) + ).to.be.true; + }); + + it("should return false if the string is not quoted", () => { + expect(isStringLiteral(`string`)).to.be.false; + expect(isStringLiteral(`true`)).to.be.false; + expect(isStringLiteral(`123`)).to.be.false; + expect(isStringLiteral(`null`)).to.be.false; + expect(isStringLiteral(`undefined`)).to.be.false; + expect(isStringLiteral(`"application/json" | "application/octet-stream"`)) + .to.be.false; + }); +}); + +describe("#isNumericLiteral", () => { + it("should return true if the string is numeric", () => { + expect(isNumericLiteral(`123`)).to.be.true; + expect(isNumericLiteral(`0.123`)).to.be.true; + }); + + it("should return false if the string is not numeric", () => { + expect(isNumericLiteral(`string`)).to.be.false; + expect(isNumericLiteral(`"123"`)).to.be.false; + }); +}); + +describe("#isBoolLiteral", () => { + it("should return true if the string is boolean", () => { + expect(isBoolLiteral(`true`)).to.be.true; + expect(isBoolLiteral(`false`)).to.be.true; + }); + + it("should return false if the string is not boolean", () => { + expect(isBoolLiteral(`unknown`)).to.be.false; + expect(isBoolLiteral(`"true"`)).to.be.false; + expect(isBoolLiteral(`"false"`)).to.be.false; + expect(isBoolLiteral('"boolean"')).to.be.false; + }); +}); + +describe("#isConstant", () => { + it("should return true if the string is constant", () => { + expect(isConstant(`null`)).to.be.true; + }); + + it("should return false if the string is not constant", () => { + expect(isConstant(`undefined`)).to.be.false; + }); +}); + +describe("#isRecord", () => { + it("should return true if the string is record", () => { + expect(isRecord(`Record`)).to.be.true; + expect(isRecord(`Record`)).to.be.true; + expect(isRecord(`Record>`)).to.be.true; + expect(isRecord(`Record`)).to.be.true; + expect(isRecord(`Record>`)).to.be.true; + expect(isRecord(`Record`)).to.be.true; + expect(isRecord(`Record`)).to.be.true; + }); + + it("should return false if the string is not record", () => { + expect(isRecord(`Record | string`)).to.be.false; + }); +}); + +describe("#getRecordType", () => { + it("should return the type of the record", () => { + expect(getRecordType(`Record`)).to.equal("string"); + expect(getRecordType(`Record`)).to.equal( + 'string | "1"' + ); + expect(getRecordType(`Record>`)).to.equal( + "Record" + ); + expect(getRecordType(`Record`)).to.equal("string[]"); + expect(getRecordType(`Record>`)).to.equal( + "Array" + ); + expect(getRecordType(`Record`)).to.equal( + "SimpleModel" + ); + expect(getRecordType(`Record`)).to.equal(`"a" | "b"`); + }); +}); + +describe("#isArray", () => { + it("should return true if the string is array", () => { + expect(isArray(`string[]`)).to.be.true; + expect(isArray(`Array`)).to.be.true; + expect(isArray(`Array`)).to.be.true; + expect(isArray(`Array`)).to.be.true; + expect(isArray(`true[]`)).to.be.true; + expect(isArray(`false[]`)).to.be.true; + expect(isArray(`null[]`)).to.be.true; + expect(isArray(`undefined[]`)).to.be.true; + expect(isArray(`"string"[]`)).to.be.true; + expect(isArray(`123[]`)).to.be.true; + }); + + it("should return false if the string is not array", () => { + expect(isArray(`Record`)).to.be.false; + }); +}); + +describe("#getArrayObjectType", () => { + it("should return the type of the array", () => { + expect(getArrayObjectType(`Array`)).to.equal("Model"); + expect(getArrayObjectType(`Array`)).to.equal("A"); + expect(getArrayObjectType(`Array`)).to.equal( + "string | number" + ); + }); +}); + +describe("#getNativeArrayType", () => { + it("should return the type of the array", () => { + expect(getNativeArrayType(`string[]`)).to.equal("string"); + expect(getNativeArrayType(`"t"[]`)).to.equal(`"t"`); + expect(getNativeArrayType(`true[]`)).to.equal(`true`); + expect(getNativeArrayType(`123[]`)).to.equal(`123`); + }); +}); + +describe("#isUnion", () => { + it("should return true if the string is union", () => { + expect(isUnion(`string | number`)).to.be.true; + expect(isUnion(`string | "a"`)).to.be.true; + expect(isUnion(`1 | "a"`)).to.be.true; + expect(isUnion(`Record | string`)).to.be.true; + expect(isUnion(`string[] | string`)).to.be.true; + expect(isUnion(`"application/json" | "application/octet-stream"`)).to.be + .true; + expect(isUnion(`true | 123 | "application/xml"`)).to.be.true; + }); + + it("should return false if the string is not union", () => { + expect(isUnion(`Record`)).to.be.false; + expect(isUnion(`"sss | tt"`)).to.be.false; + expect(isUnion(`"application/json | application/octet-stream"`)).to.be + .false; + }); +}); + +describe("#getUnionType", () => { + it("should return the type of the union", () => { + expect(getUnionType(`string | number`)).to.equal("string"); + }); +}); + +describe("#leaveBracket", () => { + it("should return the string without bracket", () => { + expect(leaveBracket(`(string)`)).to.equal("string"); + }); + + it("should return the string without bracket", () => { + expect(leaveBracket(`" include (not in)"`)).to.equal(`" include (not in)"`); + }); +}); + +describe("#leaveStringQuotes", () => { + it("should return the string without quotes", () => { + expect(leaveStringQuotes(`"string"`)).to.equal("string"); + expect(leaveStringQuotes(`'string'`)).to.equal("string"); + }); + + it("should return the string without quotes", () => { + expect(leaveStringQuotes(`"s" | "b"`)).to.equal(`"s" | "b"`); + expect(leaveStringQuotes(`'s' | 'b'`)).to.equal(`'s' | 'b'`); + expect(leaveStringQuotes(`"s" | 'b'`)).to.equal(`"s" | 'b'`); + expect(leaveStringQuotes(`true`)).to.equal(`true`); + expect(leaveStringQuotes(`'sss"`)).to.equal(`'sss"`); + }); +}); + +describe("#toTypeScriptTypeFromName", () => { + it("should return the typeScriptType from the type name", () => { + expect(toTypeScriptTypeFromName("string")).to.equal(TypeScriptType.string); + expect(toTypeScriptTypeFromName("number")).to.equal(TypeScriptType.number); + expect(toTypeScriptTypeFromName("boolean")).to.equal( + TypeScriptType.boolean + ); + expect(toTypeScriptTypeFromName("Date")).to.equal(TypeScriptType.date); + expect(toTypeScriptTypeFromName("string[]")).to.equal(TypeScriptType.array); + expect(toTypeScriptTypeFromName("Record")).to.equal( + TypeScriptType.record + ); + expect(toTypeScriptTypeFromName("Date | string")).to.equal( + TypeScriptType.union + ); + expect(toTypeScriptTypeFromName(`"constant"`)).to.equal( + TypeScriptType.constant + ); + expect(toTypeScriptTypeFromName("unknown")).to.equal( + TypeScriptType.unknown + ); + }); + + it("should return undefined if the type name is not supported", () => { + expect(toTypeScriptTypeFromName("unknownType")).to.be.undefined; + }); +}); + +describe("#toTypeScriptTypeFromSchema", () => { + it("should return the typeScriptType from the schema", () => { + expect( + toTypeScriptTypeFromSchema({ type: "string", name: "foo" }) + ).to.equal(TypeScriptType.string); + expect( + toTypeScriptTypeFromSchema({ type: "number", name: "foo" }) + ).to.equal(TypeScriptType.number); + expect( + toTypeScriptTypeFromSchema({ type: "boolean", name: "foo" }) + ).to.equal(TypeScriptType.boolean); + expect( + toTypeScriptTypeFromSchema({ + type: "string", + name: "string", + typeName: "Date | string", + outputTypeName: "string" + }) + ).to.equal(TypeScriptType.date); + expect( + toTypeScriptTypeFromSchema({ type: "object", name: "foo" }) + ).to.equal(TypeScriptType.object); + expect(toTypeScriptTypeFromSchema({ type: "array", name: "foo" })).to.equal( + TypeScriptType.array + ); + expect( + toTypeScriptTypeFromSchema({ type: "dictionary", name: "foo" }) + ).to.equal(TypeScriptType.record); + expect( + toTypeScriptTypeFromSchema({ + type: "union", + name: "foo", + enum: [{ type: "number", format: "int32" }] + }) + ).to.equal(TypeScriptType.union); + expect( + toTypeScriptTypeFromSchema({ + type: "string", + enum: ["val1", "val2"], + name: "foo" + }) + ).to.equal(TypeScriptType.enum); + expect( + toTypeScriptTypeFromSchema({ + isConstant: true, + name: "foo", + type: `"test"` + }) + ).to.equal(TypeScriptType.constant); + expect( + toTypeScriptTypeFromSchema({ type: "unknown", name: "foo" }) + ).to.equal(TypeScriptType.unknown); + }); + it("should return undefined if the schema is not supported", () => { + expect(toTypeScriptTypeFromSchema({ type: "unknownType", name: "foo" })).to + .be.undefined; + }); +}); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/package.json b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/package.json index c0a021d83a..5a5041f17c 100644 --- a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "tsc -p . && rollup -c 2>&1", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha -r esm --require source-map-support/register --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", @@ -101,5 +101,11 @@ }, "browser": { "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + }, + "//sampleConfiguration": { + "productName": "Anomaly Detector", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/ai-anomaly-detector?view=azure-node-preview" } } diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/deleteMultivariateModelSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/deleteMultivariateModelSample.ts new file mode 100644 index 0000000000..0f769d1c8c --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/deleteMultivariateModelSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DeleteMultivariateModel + * + * @summary call operation DeleteMultivariateModel + */ +async function deleteMultivariateModelSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const modelId = "{Your modelId}"; + const result = await client + .path("/multivariate/models/{modelId}", modelId) + .delete(); + console.log(result); +} + +async function main() { + deleteMultivariateModelSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectMultivariateBatchAnomalySample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectMultivariateBatchAnomalySample.ts new file mode 100644 index 0000000000..ac420860cb --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectMultivariateBatchAnomalySample.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DetectMultivariateBatchAnomaly + * + * @summary call operation DetectMultivariateBatchAnomaly + */ +async function detectMultivariateBatchAnomalySample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const modelId = "{Your modelId}"; + const result = await client + .path("/multivariate/models/{modelId}:detect-batch", modelId) + .post({ + body: { + dataSource: "{Your dataSource}", + topContributorCount: 123, + startTime: new Date(), + endTime: new Date(), + }, + }); + console.log(result); +} + +async function main() { + detectMultivariateBatchAnomalySample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectMultivariateLastAnomalySample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectMultivariateLastAnomalySample.ts new file mode 100644 index 0000000000..1fefba310c --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectMultivariateLastAnomalySample.ts @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DetectMultivariateLastAnomaly + * + * @summary call operation DetectMultivariateLastAnomaly + */ +async function detectMultivariateLastAnomalySample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const modelId = "{Your modelId}"; + const result = await client + .path("/multivariate/models/{modelId}:detect-last", modelId) + .post({ + body: { + variables: [ + { + variable: "{Your variable}", + timestamps: ["{Your timestamps}"], + values: [123], + }, + ], + topContributorCount: 123, + }, + }); + console.log(result); +} + +async function main() { + detectMultivariateLastAnomalySample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateChangePointSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateChangePointSample.ts new file mode 100644 index 0000000000..b92bc85f11 --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateChangePointSample.ts @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DetectUnivariateChangePoint + * + * @summary call operation DetectUnivariateChangePoint + */ +async function detectUnivariateChangePointSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const result = await client + .path("/timeseries/changepoint/detect") + .post({ + body: { + series: [{ timestamp: new Date(), value: 123 }], + granularity: "yearly", + customInterval: 123, + period: 123, + stableTrendWindow: 123, + threshold: 123, + }, + }); + console.log(result); +} + +async function main() { + detectUnivariateChangePointSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateEntireSeriesSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateEntireSeriesSample.ts new file mode 100644 index 0000000000..2a8a87e9f6 --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateEntireSeriesSample.ts @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DetectUnivariateEntireSeries + * + * @summary call operation DetectUnivariateEntireSeries + */ +async function detectUnivariateEntireSeriesSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const result = await client + .path("/timeseries/entire/detect") + .post({ + body: { + series: [{ timestamp: new Date(), value: 123 }], + granularity: "yearly", + customInterval: 123, + period: 123, + maxAnomalyRatio: 123, + sensitivity: 123, + imputeMode: "auto", + imputeFixedValue: 123, + }, + }); + console.log(result); +} + +async function main() { + detectUnivariateEntireSeriesSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateLastPointSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateLastPointSample.ts new file mode 100644 index 0000000000..c27c3b84cb --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/detectUnivariateLastPointSample.ts @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DetectUnivariateLastPoint + * + * @summary call operation DetectUnivariateLastPoint + */ +async function detectUnivariateLastPointSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const result = await client + .path("/timeseries/last/detect") + .post({ + body: { + series: [{ timestamp: new Date(), value: 123 }], + granularity: "yearly", + customInterval: 123, + period: 123, + maxAnomalyRatio: 123, + sensitivity: 123, + imputeMode: "auto", + imputeFixedValue: 123, + }, + }); + console.log(result); +} + +async function main() { + detectUnivariateLastPointSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/getMultivariateBatchDetectionResultSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/getMultivariateBatchDetectionResultSample.ts new file mode 100644 index 0000000000..bf08d7d5d9 --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/getMultivariateBatchDetectionResultSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetMultivariateBatchDetectionResult + * + * @summary call operation GetMultivariateBatchDetectionResult + */ +async function getMultivariateBatchDetectionResultSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const resultId = "{Your resultId}"; + const result = await client + .path("/multivariate/detect-batch/{resultId}", resultId) + .get(); + console.log(result); +} + +async function main() { + getMultivariateBatchDetectionResultSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/getMultivariateModelSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/getMultivariateModelSample.ts new file mode 100644 index 0000000000..d83eeac8bb --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/getMultivariateModelSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetMultivariateModel + * + * @summary call operation GetMultivariateModel + */ +async function getMultivariateModelSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const modelId = "{Your modelId}"; + const result = await client + .path("/multivariate/models/{modelId}", modelId) + .get(); + console.log(result); +} + +async function main() { + getMultivariateModelSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/listMultivariateModelsSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/listMultivariateModelsSample.ts new file mode 100644 index 0000000000..fb4dc6a322 --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/listMultivariateModelsSample.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAnomalyDetectorClient, { + paginate, +} from "@msinternal/ai-anomaly-detector"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListMultivariateModels + * + * @summary call operation ListMultivariateModels + */ +async function listMultivariateModelsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const initialResponse = await client + .path("/multivariate/models") + .get({ queryParameters: { skip: 123, top: 123 } }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listMultivariateModelsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/trainMultivariateModelSample.ts b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/trainMultivariateModelSample.ts new file mode 100644 index 0000000000..4e7f728b73 --- /dev/null +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/samples-dev/trainMultivariateModelSample.ts @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAnomalyDetectorClient from "@msinternal/ai-anomaly-detector"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation TrainMultivariateModel + * + * @summary call operation TrainMultivariateModel + */ +async function trainMultivariateModelSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAnomalyDetectorClient(endpoint, credential); + const result = await client + .path("/multivariate/models") + .post({ + body: { + dataSource: "{Your dataSource}", + dataSchema: "OneTable", + startTime: new Date(), + endTime: new Date(), + displayName: "{Your displayName}", + slidingWindow: 123, + alignPolicy: { + alignMode: "Inner", + fillNAMethod: "Previous", + paddingValue: 123, + }, + status: "CREATED", + diagnosticsInfo: { + modelState: { + epochIds: [123], + trainLosses: [123], + validationLosses: [123], + latenciesInSeconds: [123], + }, + variableStates: [ + { + variable: "{Your variable}", + filledNARatio: 123, + effectiveCount: 123, + firstTimestamp: new Date(), + lastTimestamp: new Date(), + }, + ], + }, + }, + }); + console.log(result); +} + +async function main() { + trainMultivariateModelSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/tsconfig.json b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/tsconfig.json index 9ca43fa318..507de96bb4 100644 --- a/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/tsconfig.json +++ b/packages/typespec-test/test/anomalyDetector/generated/typespec-ts/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/ai-anomaly-detector": ["./src/index"] } }, - "include": ["./src/**/*.ts", "./test/**/*.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/package.json b/packages/typespec-test/test/authoring/generated/typespec-ts/package.json index 6256347842..d91fd24431 100644 --- a/packages/typespec-test/test/authoring/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "tsc -p . && rollup -c 2>&1", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha -r esm --require source-map-support/register --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", @@ -103,5 +103,11 @@ }, "browser": { "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + }, + "//sampleConfiguration": { + "productName": "Microsoft Cognitive Language Service - Analyze Text Authoring", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/authoring?view=azure-node-preview" } } diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/createOrUpdateSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/createOrUpdateSample.ts new file mode 100644 index 0000000000..1e387dc840 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/createOrUpdateSample.ts @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdate + * + * @summary call operation CreateOrUpdate + */ +async function createOrUpdateSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path("/authoring/analyze-text/projects/{projectName}", projectName) + .patch({ + body: { + projectKind: "CustomSingleLabelClassification", + storageInputContainerName: "{Your storageInputContainerName}", + settings: {}, + multilingual: true, + description: "{Your description}", + language: "{Your language}", + }, + contentType: "application/merge-patch+json", + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + createOrUpdateSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deleteDeploymentSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deleteDeploymentSample.ts new file mode 100644 index 0000000000..35ba5456c5 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deleteDeploymentSample.ts @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DeleteDeployment + * + * @summary call operation DeleteDeployment + */ +async function deleteDeploymentSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const deploymentName = "{Your deploymentName}"; + const initialResponse = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}", + projectName, + deploymentName + ) + .delete(); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + deleteDeploymentSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deleteSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deleteSample.ts new file mode 100644 index 0000000000..1023487163 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deleteSample.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Delete + * + * @summary call operation Delete + */ +async function deleteSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path("/authoring/analyze-text/projects/{projectName}", projectName) + .delete(); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + deleteSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deployProjectSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deployProjectSample.ts new file mode 100644 index 0000000000..c7b314d8d3 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/deployProjectSample.ts @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DeployProject + * + * @summary call operation DeployProject + */ +async function deployProjectSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const deploymentName = "{Your deploymentName}"; + const initialResponse = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}", + projectName, + deploymentName + ) + .put({ body: {} }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + deployProjectSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/exportSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/exportSample.ts new file mode 100644 index 0000000000..c35349c6ba --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/exportSample.ts @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Export + * + * @summary call operation Export + */ +async function exportSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path("/authoring/analyze-text/projects/{projectName}:export", projectName) + .post({ + queryParameters: { projectFileVersion: "{Your projectFileVersion}" }, + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + exportSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getDeploymentSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getDeploymentSample.ts new file mode 100644 index 0000000000..51c870291d --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getDeploymentSample.ts @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAuthoringClient from "@msinternal/authoring"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetDeployment + * + * @summary call operation GetDeployment + */ +async function getDeploymentSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const deploymentName = "{Your deploymentName}"; + const result = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}", + projectName, + deploymentName + ) + .get(); + console.log(result); +} + +async function main() { + getDeploymentSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getDeploymentStatusSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getDeploymentStatusSample.ts new file mode 100644 index 0000000000..d25ada9359 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getDeploymentStatusSample.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAuthoringClient from "@msinternal/authoring"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetDeploymentStatus + * + * @summary call operation GetDeploymentStatus + */ +async function getDeploymentStatusSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const deploymentName = "{Your deploymentName}"; + const jobId = "{Your jobId}"; + const result = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}/jobs/{jobId}", + projectName, + deploymentName, + jobId + ) + .get(); + console.log(result); +} + +async function main() { + getDeploymentStatusSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSample.ts new file mode 100644 index 0000000000..e9fe96d4c4 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAuthoringClient from "@msinternal/authoring"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function getSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const result = await client + .path("/authoring/analyze-text/projects/{projectName}", projectName) + .get(); + console.log(result); +} + +async function main() { + getSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSupportedLanguagesSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSupportedLanguagesSample.ts new file mode 100644 index 0000000000..8b23df4583 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSupportedLanguagesSample.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { paginate } from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetSupportedLanguages + * + * @summary call operation GetSupportedLanguages + */ +async function getSupportedLanguagesSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const initialResponse = await client + .path("/authoring/analyze-text/projects/global/languages") + .get({ queryParameters: { top: 123, skip: 123, maxpagesize: 123 } }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + getSupportedLanguagesSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSwapDeploymentsStatusSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSwapDeploymentsStatusSample.ts new file mode 100644 index 0000000000..5d8667dd6a --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/getSwapDeploymentsStatusSample.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAuthoringClient from "@msinternal/authoring"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetSwapDeploymentsStatus + * + * @summary call operation GetSwapDeploymentsStatus + */ +async function getSwapDeploymentsStatusSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const deploymentName = "{Your deploymentName}"; + const jobId = "{Your jobId}"; + const result = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments/{deploymentName}/swap/jobs/{jobId}", + projectName, + deploymentName, + jobId + ) + .get(); + console.log(result); +} + +async function main() { + getSwapDeploymentsStatusSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/importxSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/importxSample.ts new file mode 100644 index 0000000000..b9ee8b23c3 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/importxSample.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Importx + * + * @summary call operation Importx + */ +async function importxSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path("/authoring/analyze-text/projects/{projectName}:importx", projectName) + .post(); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + importxSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listDeploymentsSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listDeploymentsSample.ts new file mode 100644 index 0000000000..0adfd53567 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listDeploymentsSample.ts @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { paginate } from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListDeployments + * + * @summary call operation ListDeployments + */ +async function listDeploymentsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments", + projectName + ) + .get(); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listDeploymentsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listProjectsSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listProjectsSample.ts new file mode 100644 index 0000000000..c21ea02755 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listProjectsSample.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { paginate } from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListProjects + * + * @summary call operation ListProjects + */ +async function listProjectsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const initialResponse = await client + .path("/authoring/analyze-text/projects") + .get(); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listProjectsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listTrainingConfigVersionsSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listTrainingConfigVersionsSample.ts new file mode 100644 index 0000000000..d356f590f3 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/listTrainingConfigVersionsSample.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { paginate } from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListTrainingConfigVersions + * + * @summary call operation ListTrainingConfigVersions + */ +async function listTrainingConfigVersionsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const initialResponse = await client + .path("/authoring/analyze-text/projects/global/training-config-versions") + .get({ queryParameters: { top: 123, skip: 123, maxpagesize: 123 } }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listTrainingConfigVersionsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/swapDeploymentsSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/swapDeploymentsSample.ts new file mode 100644 index 0000000000..d35a294fc9 --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/swapDeploymentsSample.ts @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation SwapDeployments + * + * @summary call operation SwapDeployments + */ +async function swapDeploymentsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path( + "/authoring/analyze-text/projects/{projectName}/deployments:swap", + projectName + ) + .post({ + body: { + firstDeploymentName: "{Your firstDeploymentName}", + secondDeploymentName: "{Your secondDeploymentName}", + }, + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + swapDeploymentsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/trainSample.ts b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/trainSample.ts new file mode 100644 index 0000000000..a0fbbc1ceb --- /dev/null +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/samples-dev/trainSample.ts @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createAuthoringClient, { + getLongRunningPoller, +} from "@msinternal/authoring"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Train + * + * @summary call operation Train + */ +async function trainSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createAuthoringClient(endpoint, credential); + const projectName = "{Your projectName}"; + const initialResponse = await client + .path("/authoring/analyze-text/projects/{projectName}:train", projectName) + .post({ body: { modelLabel: "{Your modelLabel}" } }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + trainSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/authoring/generated/typespec-ts/tsconfig.json b/packages/typespec-test/test/authoring/generated/typespec-ts/tsconfig.json index 9ca43fa318..b02d09899a 100644 --- a/packages/typespec-test/test/authoring/generated/typespec-ts/tsconfig.json +++ b/packages/typespec-test/test/authoring/generated/typespec-ts/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/authoring": ["./src/index"] } }, - "include": ["./src/**/*.ts", "./test/**/*.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-test/test/authoring/tspconfig.yaml b/packages/typespec-test/test/authoring/tspconfig.yaml index 846321e9d2..e4aade1688 100644 --- a/packages/typespec-test/test/authoring/tspconfig.yaml +++ b/packages/typespec-test/test/authoring/tspconfig.yaml @@ -2,11 +2,12 @@ emit: - "@azure-tools/typespec-ts" - "@azure-tools/typespec-autorest" options: - "@azure-tools/typespec-autorest": - "emitter-output-dir": "{project-root}/generated/openapi" - "@azure-tools/typespec-ts": + "@azure-tools/typespec-autorest": + "emitter-output-dir": "{project-root}/generated/openapi" + "@azure-tools/typespec-ts": azureSdkForJs: false + generateSample: true "emitter-output-dir": "{project-root}/generated/typespec-ts" packageDetails: name: "@msinternal/authoring" - description: "Authoring Ledger Service" \ No newline at end of file + description: "Authoring Ledger Service" diff --git a/packages/typespec-test/test/healthinsight/generated/typespec-ts/package.json b/packages/typespec-test/test/healthinsight/generated/typespec-ts/package.json index 636ce024b1..cf77164acf 100644 --- a/packages/typespec-test/test/healthinsight/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/healthinsight/generated/typespec-ts/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "tsc -p . && rollup -c 2>&1", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha -r esm --require source-map-support/register --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", @@ -102,5 +102,11 @@ }, "browser": { "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + }, + "//sampleConfiguration": { + "productName": "Azure Health Insights", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@azure-rest/health-insights-clinicalmatching?view=azure-node-preview" } } diff --git a/packages/typespec-test/test/healthinsight/generated/typespec-ts/samples-dev/createJobSample.ts b/packages/typespec-test/test/healthinsight/generated/typespec-ts/samples-dev/createJobSample.ts new file mode 100644 index 0000000000..b0356c7fe0 --- /dev/null +++ b/packages/typespec-test/test/healthinsight/generated/typespec-ts/samples-dev/createJobSample.ts @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { AzureKeyCredential } from "@azure/core-auth"; +import createHealthInsightsClinicalMatchingClient, { + getLongRunningPoller, +} from "@azure-rest/health-insights-clinicalmatching"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateJob + * + * @summary call operation CreateJob + */ +async function createJobSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createHealthInsightsClinicalMatchingClient( + endpoint, + credential + ); + const initialResponse = await client + .path("/trialmatcher/jobs") + .post({ + body: { + patients: [ + { + id: "{Your id}", + info: { + sex: "female", + birthDate: new Date(), + clinicalInfo: [ + { + system: "{Your system}", + code: "{Your code}", + name: "{Your name}", + value: "{Your value}", + }, + ], + }, + data: [ + { + type: "note", + clinicalType: "consultation", + id: "{Your id}", + language: "{Your language}", + createdDateTime: new Date(), + content: { sourceType: "inline", value: "{Your value}" }, + }, + ], + }, + ], + configuration: { + verbose: true, + includeEvidence: true, + clinicalTrials: { + customTrials: [ + { + id: "{Your id}", + eligibilityCriteriaText: "{Your eligibilityCriteriaText}", + demographics: { + acceptedSex: "all", + acceptedAgeRange: { + minimumAge: { unit: "years", value: 123 }, + maximumAge: { unit: "years", value: 123 }, + }, + }, + metadata: { + phases: ["notApplicable"], + studyType: "interventional", + recruitmentStatus: "unknownStatus", + conditions: ["notApplicable"], + sponsors: ["notApplicable"], + contacts: [ + { + name: "{Your name}", + email: "{Your email}", + phone: "{Your phone}", + }, + ], + facilities: [ + { + name: "{Your name}", + city: "{Your city}", + state: "{Your state}", + countryOrRegion: "{Your countryOrRegion}", + }, + ], + }, + }, + ], + registryFilters: [ + { + conditions: ["notApplicable"], + studyTypes: ["notApplicable"], + recruitmentStatuses: ["notApplicable"], + sponsors: ["notApplicable"], + phases: ["notApplicable"], + purposes: ["notApplicable"], + ids: ["notApplicable"], + sources: ["notApplicable"], + facilityNames: ["notApplicable"], + facilityLocations: [ + { + city: "{Your city}", + state: "{Your state}", + countryOrRegion: "{Your countryOrRegion}", + }, + ], + facilityAreas: [ + { + type: "Feature", + geometry: { type: "Point", coordinates: [123] }, + properties: { subType: "Circle", radius: 123 }, + }, + ], + }, + ], + }, + }, + }, + headers: { + "Repeatability-Request-ID": "{Your Repeatability-Request-ID}", + "Repeatability-First-Sent": "{Your Repeatability-First-Sent}", + }, + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + createJobSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/healthinsight/generated/typespec-ts/samples-dev/getJobSample.ts b/packages/typespec-test/test/healthinsight/generated/typespec-ts/samples-dev/getJobSample.ts new file mode 100644 index 0000000000..0c546f9b1b --- /dev/null +++ b/packages/typespec-test/test/healthinsight/generated/typespec-ts/samples-dev/getJobSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createHealthInsightsClinicalMatchingClient from "@azure-rest/health-insights-clinicalmatching"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetJob + * + * @summary call operation GetJob + */ +async function getJobSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createHealthInsightsClinicalMatchingClient( + endpoint, + credential + ); + const jobId = "{Your jobId}"; + const result = await client.path("/trialmatcher/jobs/{jobId}", jobId).get(); + console.log(result); +} + +async function main() { + getJobSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/healthinsight/generated/typespec-ts/tsconfig.json b/packages/typespec-test/test/healthinsight/generated/typespec-ts/tsconfig.json index 9ca43fa318..8f5a1df6fa 100644 --- a/packages/typespec-test/test/healthinsight/generated/typespec-ts/tsconfig.json +++ b/packages/typespec-test/test/healthinsight/generated/typespec-ts/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@azure-rest/health-insights-clinicalmatching": ["./src/index"] } }, - "include": ["./src/**/*.ts", "./test/**/*.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-test/test/healthinsight/tspconfig.yaml b/packages/typespec-test/test/healthinsight/tspconfig.yaml index de633ce2b5..255b73c244 100644 --- a/packages/typespec-test/test/healthinsight/tspconfig.yaml +++ b/packages/typespec-test/test/healthinsight/tspconfig.yaml @@ -1,31 +1,32 @@ emit: [ - # "@azure-tools/typespec-csharp", - # "@azure-tools/typespec-python", - # "@azure-tools/typespec-java", - '@azure-tools/typespec-ts', - ] + # "@azure-tools/typespec-csharp", + # "@azure-tools/typespec-python", + # "@azure-tools/typespec-java", + "@azure-tools/typespec-ts", + ] options: - # "@azure-tools/typespec-csharp": - # namespace : "Azure.Health.Insights.ClinicalMatching" - # clear-output-folder : true - # new-project : false - # model-namespace : false - # "@azure-tools/typespec-java": - # namespace: "Com.Azure.Health.Insights.ClinicalMatching" - # clear-output-folder: true - # new-project: false - # model-namespace: false - # "@azure-tools/typespec-python": - # package-mode: "dataplane" - # package-name: "azure-healthinsights-clinicalmatching" - '@azure-tools/typespec-ts': - title: Health Insights Clinical Matching - generateMetadata: true - generateTest: true - azureSdkForJs: false - 'emitter-output-dir': '{project-root}/generated/typespec-ts' - packageDetails: - name: '@azure-rest/health-insights-clinicalmatching' - description: 'Azure Health Insights ClinicalMatching' - version: '1.0.0-beta.1' + # "@azure-tools/typespec-csharp": + # namespace : "Azure.Health.Insights.ClinicalMatching" + # clear-output-folder : true + # new-project : false + # model-namespace : false + # "@azure-tools/typespec-java": + # namespace: "Com.Azure.Health.Insights.ClinicalMatching" + # clear-output-folder: true + # new-project: false + # model-namespace: false + # "@azure-tools/typespec-python": + # package-mode: "dataplane" + # package-name: "azure-healthinsights-clinicalmatching" + "@azure-tools/typespec-ts": + title: Health Insights Clinical Matching + generateMetadata: true + generateTest: true + generateSample: true + azureSdkForJs: false + "emitter-output-dir": "{project-root}/generated/typespec-ts" + packageDetails: + name: "@azure-rest/health-insights-clinicalmatching" + description: "Azure Health Insights ClinicalMatching" + version: "1.0.0-beta.1" diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/package.json b/packages/typespec-test/test/loadTest/generated/typespec-ts/package.json index 2c94a538a8..3047b8da74 100644 --- a/packages/typespec-test/test/loadTest/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "tsc -p . && rollup -c 2>&1", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha -r esm --require source-map-support/register --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", @@ -103,5 +103,11 @@ }, "browser": { "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + }, + "//sampleConfiguration": { + "productName": "Azure Load Testing", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@azure-rest/load-testing" } } diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateAppComponentsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateAppComponentsSample.ts new file mode 100644 index 0000000000..c1035f786c --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateAppComponentsSample.ts @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdateAppComponents + * + * @summary call operation CreateOrUpdateAppComponents + */ +async function loadTestAdministrationCreateOrUpdateAppComponentsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client + .path("/tests/{testId}/app-components", testId) + .patch({ + body: { + components: { + key: { + resourceName: "{Your resourceName}", + resourceType: "{Your resourceType}", + displayName: "{Your displayName}", + kind: "{Your kind}", + }, + }, + }, + contentType: "application/merge-patch+json", + }); + console.log(result); +} + +async function main() { + loadTestAdministrationCreateOrUpdateAppComponentsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateServerMetricsConfigSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateServerMetricsConfigSample.ts new file mode 100644 index 0000000000..6a50c53bac --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateServerMetricsConfigSample.ts @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdateServerMetricsConfig + * + * @summary call operation CreateOrUpdateServerMetricsConfig + */ +async function loadTestAdministrationCreateOrUpdateServerMetricsConfigSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client + .path("/tests/{testId}/server-metrics-config", testId) + .patch({ + body: { + metrics: { + key: { + resourceId: "{Your resourceId}", + metricNamespace: "{Your metricNamespace}", + displayDescription: "{Your displayDescription}", + name: "{Your name}", + aggregation: "{Your aggregation}", + unit: "{Your unit}", + resourceType: "{Your resourceType}", + }, + }, + }, + contentType: "application/merge-patch+json", + }); + console.log(result); +} + +async function main() { + loadTestAdministrationCreateOrUpdateServerMetricsConfigSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateTestSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateTestSample.ts new file mode 100644 index 0000000000..0d6b1bd79f --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationCreateOrUpdateTestSample.ts @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdateTest + * + * @summary call operation CreateOrUpdateTest + */ +async function loadTestAdministrationCreateOrUpdateTestSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client + .path("/tests/{testId}", testId) + .patch({ + body: { + passFailCriteria: { + passFailMetrics: { + key: { + clientMetric: "response_time_ms", + aggregate: "count", + condition: "{Your condition}", + requestName: "{Your requestName}", + value: 123, + action: "continue", + }, + }, + }, + secrets: { key: { value: "{Your value}", type: "AKV_SECRET_URI" } }, + certificate: { + value: "{Your value}", + type: "AKV_CERT_URI", + name: "{Your name}", + }, + environmentVariables: { key: "{Your environmentVariables}" }, + loadTestConfiguration: { + engineInstances: 123, + splitAllCSVs: true, + quickStartTest: true, + optionalLoadTestConfig: { + endpointUrl: "{Your endpointUrl}", + virtualUsers: 123, + rampUpTime: 123, + duration: 123, + }, + }, + description: "{Your description}", + displayName: "{Your displayName}", + subnetId: "{Your subnetId}", + keyvaultReferenceIdentityType: "{Your keyvaultReferenceIdentityType}", + keyvaultReferenceIdentityId: "{Your keyvaultReferenceIdentityId}", + }, + contentType: "application/merge-patch+json", + }); + console.log(result); +} + +async function main() { + loadTestAdministrationCreateOrUpdateTestSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationDeleteTestFileSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationDeleteTestFileSample.ts new file mode 100644 index 0000000000..7a255992af --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationDeleteTestFileSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DeleteTestFile + * + * @summary call operation DeleteTestFile + */ +async function loadTestAdministrationDeleteTestFileSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const fileName = "{Your fileName}"; + const result = await client + .path("/tests/{testId}/files/{fileName}", testId, fileName) + .delete(); + console.log(result); +} + +async function main() { + loadTestAdministrationDeleteTestFileSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationDeleteTestSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationDeleteTestSample.ts new file mode 100644 index 0000000000..1b2d9b3531 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationDeleteTestSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DeleteTest + * + * @summary call operation DeleteTest + */ +async function loadTestAdministrationDeleteTestSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client.path("/tests/{testId}", testId).delete(); + console.log(result); +} + +async function main() { + loadTestAdministrationDeleteTestSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetAppComponentsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetAppComponentsSample.ts new file mode 100644 index 0000000000..e58bf2c27f --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetAppComponentsSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetAppComponents + * + * @summary call operation GetAppComponents + */ +async function loadTestAdministrationGetAppComponentsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client + .path("/tests/{testId}/app-components", testId) + .get(); + console.log(result); +} + +async function main() { + loadTestAdministrationGetAppComponentsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetServerMetricsConfigSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetServerMetricsConfigSample.ts new file mode 100644 index 0000000000..623062d372 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetServerMetricsConfigSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetServerMetricsConfig + * + * @summary call operation GetServerMetricsConfig + */ +async function loadTestAdministrationGetServerMetricsConfigSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client + .path("/tests/{testId}/server-metrics-config", testId) + .get(); + console.log(result); +} + +async function main() { + loadTestAdministrationGetServerMetricsConfigSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetTestFileSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetTestFileSample.ts new file mode 100644 index 0000000000..823faa9de9 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetTestFileSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetTestFile + * + * @summary call operation GetTestFile + */ +async function loadTestAdministrationGetTestFileSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const fileName = "{Your fileName}"; + const result = await client + .path("/tests/{testId}/files/{fileName}", testId, fileName) + .get(); + console.log(result); +} + +async function main() { + loadTestAdministrationGetTestFileSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetTestSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetTestSample.ts new file mode 100644 index 0000000000..2da12bd037 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationGetTestSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetTest + * + * @summary call operation GetTest + */ +async function loadTestAdministrationGetTestSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const result = await client.path("/tests/{testId}", testId).get(); + console.log(result); +} + +async function main() { + loadTestAdministrationGetTestSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationListTestFilesSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationListTestFilesSample.ts new file mode 100644 index 0000000000..78a19b2794 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationListTestFilesSample.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DefaultAzureCredential } from "@azure/identity"; +import createAzureLoadTestingClient, { + paginate, +} from "@azure-rest/load-testing"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListTestFiles + * + * @summary call operation ListTestFiles + */ +async function loadTestAdministrationListTestFilesSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const initialResponse = await client + .path("/tests/{testId}/files", testId) + .get(); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + loadTestAdministrationListTestFilesSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationListTestsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationListTestsSample.ts new file mode 100644 index 0000000000..b992b4d2a3 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationListTestsSample.ts @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DefaultAzureCredential } from "@azure/identity"; +import createAzureLoadTestingClient, { + paginate, +} from "@azure-rest/load-testing"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListTests + * + * @summary call operation ListTests + */ +async function loadTestAdministrationListTestsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const initialResponse = await client + .path("/tests") + .get({ + queryParameters: { + orderby: "{Your orderby}", + search: "{Your search}", + lastModifiedStartTime: "{Your lastModifiedStartTime}", + lastModifiedEndTime: "{Your lastModifiedEndTime}", + maxpagesize: 123, + }, + }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + loadTestAdministrationListTestsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationUploadTestFileSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationUploadTestFileSample.ts new file mode 100644 index 0000000000..1346fe49c7 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestAdministrationUploadTestFileSample.ts @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation UploadTestFile + * + * @summary call operation UploadTestFile + */ +async function loadTestAdministrationUploadTestFileSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testId = "{Your testId}"; + const fileName = "{Your fileName}"; + const result = await client + .path("/tests/{testId}/files/{fileName}", testId, fileName) + .put({ + body: "{Your body}", + queryParameters: { fileType: "{Your fileType}" }, + contentType: "application/octet-stream", + }); + console.log(result); +} + +async function main() { + loadTestAdministrationUploadTestFileSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateAppComponentsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateAppComponentsSample.ts new file mode 100644 index 0000000000..a5bdc47bf2 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateAppComponentsSample.ts @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdateAppComponents + * + * @summary call operation CreateOrUpdateAppComponents + */ +async function loadTestRunCreateOrUpdateAppComponentsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}/app-components", testRunId) + .patch({ + body: { + components: { + key: { + resourceName: "{Your resourceName}", + resourceType: "{Your resourceType}", + displayName: "{Your displayName}", + kind: "{Your kind}", + }, + }, + }, + contentType: "application/merge-patch+json", + }); + console.log(result); +} + +async function main() { + loadTestRunCreateOrUpdateAppComponentsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateServerMetricsConfigSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateServerMetricsConfigSample.ts new file mode 100644 index 0000000000..ef76829cbc --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateServerMetricsConfigSample.ts @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdateServerMetricsConfig + * + * @summary call operation CreateOrUpdateServerMetricsConfig + */ +async function loadTestRunCreateOrUpdateServerMetricsConfigSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}/server-metrics-config", testRunId) + .patch({ + body: { + metrics: { + key: { + resourceId: "{Your resourceId}", + metricNamespace: "{Your metricNamespace}", + displayDescription: "{Your displayDescription}", + name: "{Your name}", + aggregation: "{Your aggregation}", + unit: "{Your unit}", + resourceType: "{Your resourceType}", + }, + }, + }, + contentType: "application/merge-patch+json", + }); + console.log(result); +} + +async function main() { + loadTestRunCreateOrUpdateServerMetricsConfigSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateTestRunSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateTestRunSample.ts new file mode 100644 index 0000000000..6e0bc1fc31 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunCreateOrUpdateTestRunSample.ts @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DefaultAzureCredential } from "@azure/identity"; +import createAzureLoadTestingClient, { + getLongRunningPoller, +} from "@azure-rest/load-testing"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdateTestRun + * + * @summary call operation CreateOrUpdateTestRun + */ +async function loadTestRunCreateOrUpdateTestRunSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const initialResponse = await client + .path("/test-runs/{testRunId}", testRunId) + .patch({ + body: { + passFailCriteria: { + passFailMetrics: { + key: { + clientMetric: "response_time_ms", + aggregate: "count", + condition: "{Your condition}", + requestName: "{Your requestName}", + value: 123, + action: "continue", + }, + }, + }, + secrets: { key: { value: "{Your value}", type: "AKV_SECRET_URI" } }, + certificate: { + value: "{Your value}", + type: "AKV_CERT_URI", + name: "{Your name}", + }, + environmentVariables: { key: "{Your environmentVariables}" }, + loadTestConfiguration: { + engineInstances: 123, + splitAllCSVs: true, + quickStartTest: true, + optionalLoadTestConfig: { + endpointUrl: "{Your endpointUrl}", + virtualUsers: 123, + rampUpTime: 123, + duration: 123, + }, + }, + displayName: "{Your displayName}", + testId: "{Your testId}", + description: "{Your description}", + }, + queryParameters: { oldTestRunId: "{Your oldTestRunId}" }, + contentType: "application/merge-patch+json", + }); + const poller = await getLongRunningPoller(client, initialResponse); + const result = await poller.pollUntilDone(); + console.log(result); +} + +async function main() { + loadTestRunCreateOrUpdateTestRunSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunDeleteTestRunSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunDeleteTestRunSample.ts new file mode 100644 index 0000000000..5367df2146 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunDeleteTestRunSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation DeleteTestRun + * + * @summary call operation DeleteTestRun + */ +async function loadTestRunDeleteTestRunSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}", testRunId) + .delete(); + console.log(result); +} + +async function main() { + loadTestRunDeleteTestRunSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetAppComponentsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetAppComponentsSample.ts new file mode 100644 index 0000000000..32ed1f6285 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetAppComponentsSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetAppComponents + * + * @summary call operation GetAppComponents + */ +async function loadTestRunGetAppComponentsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}/app-components", testRunId) + .get(); + console.log(result); +} + +async function main() { + loadTestRunGetAppComponentsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetTestRunFileSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetTestRunFileSample.ts new file mode 100644 index 0000000000..a9cb92fb25 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetTestRunFileSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetTestRunFile + * + * @summary call operation GetTestRunFile + */ +async function loadTestRunGetTestRunFileSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const fileName = "{Your fileName}"; + const result = await client + .path("/test-runs/{testRunId}/files/{fileName}", testRunId, fileName) + .get(); + console.log(result); +} + +async function main() { + loadTestRunGetTestRunFileSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetTestRunSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetTestRunSample.ts new file mode 100644 index 0000000000..dde838d252 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunGetTestRunSample.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetTestRun + * + * @summary call operation GetTestRun + */ +async function loadTestRunGetTestRunSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client.path("/test-runs/{testRunId}", testRunId).get(); + console.log(result); +} + +async function main() { + loadTestRunGetTestRunSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricDefinitionsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricDefinitionsSample.ts new file mode 100644 index 0000000000..2757e27354 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricDefinitionsSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListMetricDefinitions + * + * @summary call operation ListMetricDefinitions + */ +async function loadTestRunListMetricDefinitionsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}/metric-definitions", testRunId) + .get({ queryParameters: { metricNamespace: "{Your metricNamespace}" } }); + console.log(result); +} + +async function main() { + loadTestRunListMetricDefinitionsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricDimensionValuesSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricDimensionValuesSample.ts new file mode 100644 index 0000000000..cd60cc1c6d --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricDimensionValuesSample.ts @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DefaultAzureCredential } from "@azure/identity"; +import createAzureLoadTestingClient, { + paginate, +} from "@azure-rest/load-testing"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListMetricDimensionValues + * + * @summary call operation ListMetricDimensionValues + */ +async function loadTestRunListMetricDimensionValuesSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const name = "{Your name}"; + const initialResponse = await client + .path( + "/test-runs/{testRunId}/metric-dimensions/{name}/values", + testRunId, + name + ) + .get({ + queryParameters: { + interval: "{Your interval}", + metricName: "{Your metricName}", + metricNamespace: "{Your metricNamespace}", + timespan: "{Your timespan}", + }, + }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + loadTestRunListMetricDimensionValuesSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricNamespacesSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricNamespacesSample.ts new file mode 100644 index 0000000000..8cb876b323 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricNamespacesSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListMetricNamespaces + * + * @summary call operation ListMetricNamespaces + */ +async function loadTestRunListMetricNamespacesSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}/metric-namespaces", testRunId) + .get(); + console.log(result); +} + +async function main() { + loadTestRunListMetricNamespacesSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricsSample.ts new file mode 100644 index 0000000000..ba84fbe6e3 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListMetricsSample.ts @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DefaultAzureCredential } from "@azure/identity"; +import createAzureLoadTestingClient, { + paginate, +} from "@azure-rest/load-testing"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListMetrics + * + * @summary call operation ListMetrics + */ +async function loadTestRunListMetricsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const initialResponse = await client + .path("/test-runs/{testRunId}/metrics", testRunId) + .post({ + body: { filters: [{ name: "{Your name}", values: ["{Your values}"] }] }, + queryParameters: { + aggregation: "{Your aggregation}", + interval: "{Your interval}", + metricName: "{Your metricName}", + metricNamespace: "{Your metricNamespace}", + timespan: "{Your timespan}", + }, + }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + loadTestRunListMetricsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListTestRunsSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListTestRunsSample.ts new file mode 100644 index 0000000000..f36af67e6c --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunListTestRunsSample.ts @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import { DefaultAzureCredential } from "@azure/identity"; +import createAzureLoadTestingClient, { + paginate, +} from "@azure-rest/load-testing"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListTestRuns + * + * @summary call operation ListTestRuns + */ +async function loadTestRunListTestRunsSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const initialResponse = await client + .path("/test-runs") + .get({ + queryParameters: { + orderby: "{Your orderby}", + search: "{Your search}", + testId: "{Your testId}", + executionFrom: "{Your executionFrom}", + executionTo: "{Your executionTo}", + status: "{Your status}", + maxpagesize: 123, + }, + }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + loadTestRunListTestRunsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunStopTestRunSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunStopTestRunSample.ts new file mode 100644 index 0000000000..e2e0cb48b1 --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunStopTestRunSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation StopTestRun + * + * @summary call operation StopTestRun + */ +async function loadTestRunStopTestRunSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}:stop", testRunId) + .post(); + console.log(result); +} + +async function main() { + loadTestRunStopTestRunSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunTestRunListServerMetricsConfigSample.ts b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunTestRunListServerMetricsConfigSample.ts new file mode 100644 index 0000000000..21a91c086e --- /dev/null +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/samples-dev/loadTestRunTestRunListServerMetricsConfigSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureLoadTestingClient from "@azure-rest/load-testing"; +import { DefaultAzureCredential } from "@azure/identity"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation TestRunListServerMetricsConfig + * + * @summary call operation TestRunListServerMetricsConfig + */ +async function loadTestRunTestRunListServerMetricsConfigSample() { + const endpoint = "{Your endpoint}"; + const credential = new DefaultAzureCredential(); + const client = createAzureLoadTestingClient(endpoint, credential); + const testRunId = "{Your testRunId}"; + const result = await client + .path("/test-runs/{testRunId}/server-metrics-config", testRunId) + .get(); + console.log(result); +} + +async function main() { + loadTestRunTestRunListServerMetricsConfigSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/loadTest/generated/typespec-ts/tsconfig.json b/packages/typespec-test/test/loadTest/generated/typespec-ts/tsconfig.json index 9ca43fa318..aa523bd16b 100644 --- a/packages/typespec-test/test/loadTest/generated/typespec-ts/tsconfig.json +++ b/packages/typespec-test/test/loadTest/generated/typespec-ts/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@azure-rest/load-testing": ["./src/index"] } }, - "include": ["./src/**/*.ts", "./test/**/*.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-test/test/loadTest/tspconfig.yaml b/packages/typespec-test/test/loadTest/tspconfig.yaml index 131c6cf81e..316ca1138f 100644 --- a/packages/typespec-test/test/loadTest/tspconfig.yaml +++ b/packages/typespec-test/test/loadTest/tspconfig.yaml @@ -22,6 +22,7 @@ options: description: Azure Load Testing Client generateMetadata: true generateTest: true + generateSample: true azureSdkForJs: false enableOperationGroup: true packageDetails: diff --git a/packages/typespec-test/test/openai/generated/typespec-ts/package.json b/packages/typespec-test/test/openai/generated/typespec-ts/package.json index 499699561a..2aa22cf767 100644 --- a/packages/typespec-test/test/openai/generated/typespec-ts/package.json +++ b/packages/typespec-test/test/openai/generated/typespec-ts/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "tsc -p . && rollup -c 2>&1", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\"", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"test/**/*.ts\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "karma start --single-run", "integration-test:node": "nyc mocha -r esm --require source-map-support/register --timeout 5000000 --full-trace \"dist-esm/test/{,!(browser)/**/}*.spec.js\"", @@ -100,5 +100,11 @@ }, "browser": { "./dist-esm/test/public/utils/env.js": "./dist-esm/test/public/utils/env.browser.js" + }, + "//sampleConfiguration": { + "productName": "Azure OpenAI API", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/openai?view=azure-node-preview" } } diff --git a/packages/typespec-test/test/openai/generated/typespec-ts/samples-dev/getCompletionsSample.ts b/packages/typespec-test/test/openai/generated/typespec-ts/samples-dev/getCompletionsSample.ts new file mode 100644 index 0000000000..5e9ed42b03 --- /dev/null +++ b/packages/typespec-test/test/openai/generated/typespec-ts/samples-dev/getCompletionsSample.ts @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createOpenAIClient from "@msinternal/openai"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetCompletions + * + * @summary call operation GetCompletions + */ +async function getCompletionsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createOpenAIClient(endpoint, credential); + const deploymentId = "{Your deploymentId}"; + const result = await client + .path("/deployments/{deploymentId}/completions", deploymentId) + .post({ + body: { + prompt: ["{Your prompt}"], + max_tokens: 123, + temperature: 123, + top_p: 123, + logit_bias: { key: 123 }, + user: "{Your user}", + n: 123, + logprobs: 123, + model: "{Your model}", + echo: true, + stop: ["{Your stop}"], + completion_config: "{Your completion_config}", + cache_level: 123, + presence_penalty: 123, + frequency_penalty: 123, + best_of: 123, + }, + }); + console.log(result); +} + +async function main() { + getCompletionsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/openai/generated/typespec-ts/samples-dev/getEmbeddingsSample.ts b/packages/typespec-test/test/openai/generated/typespec-ts/samples-dev/getEmbeddingsSample.ts new file mode 100644 index 0000000000..d9a398dd7d --- /dev/null +++ b/packages/typespec-test/test/openai/generated/typespec-ts/samples-dev/getEmbeddingsSample.ts @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createOpenAIClient from "@msinternal/openai"; +import { AzureKeyCredential } from "@azure/core-auth"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation GetEmbeddings + * + * @summary call operation GetEmbeddings + */ +async function getEmbeddingsSample() { + const endpoint = "{Your endpoint}"; + const credential = new AzureKeyCredential("{Your API key}"); + const client = createOpenAIClient(endpoint, credential); + const deploymentId = "{Your deploymentId}"; + const result = await client + .path("/deployments/{deploymentId}/embeddings", deploymentId) + .post({ + body: { + user: "{Your user}", + input_type: "{Your input_type}", + model: "{Your model}", + input: "{Your input}", + }, + }); + console.log(result); +} + +async function main() { + getEmbeddingsSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-test/test/openai/generated/typespec-ts/tsconfig.json b/packages/typespec-test/test/openai/generated/typespec-ts/tsconfig.json index 9ca43fa318..af73efb9b6 100644 --- a/packages/typespec-test/test/openai/generated/typespec-ts/tsconfig.json +++ b/packages/typespec-test/test/openai/generated/typespec-ts/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/openai": ["./src/index"] } }, - "include": ["./src/**/*.ts", "./test/**/*.ts"] + "include": ["./src/**/*.ts", "./test/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-test/test/openai/tspconfig.yaml b/packages/typespec-test/test/openai/tspconfig.yaml index 02b0631d4b..171efab49a 100644 --- a/packages/typespec-test/test/openai/tspconfig.yaml +++ b/packages/typespec-test/test/openai/tspconfig.yaml @@ -5,7 +5,7 @@ options: "@azure-tools/typespec-ts": generateMetadata: true generateTest: true - multiClient: true + generateSample: true azureSdkForJs: false "emitter-output-dir": "{project-root}/generated/typespec-ts" packageDetails: diff --git a/packages/typespec-ts/.eslintrc.json b/packages/typespec-ts/.eslintrc.json index 9fa7b6e2fb..a761226390 100644 --- a/packages/typespec-ts/.eslintrc.json +++ b/packages/typespec-ts/.eslintrc.json @@ -1,8 +1,12 @@ { "parser": "@typescript-eslint/parser", "parserOptions": { "project": "./tsconfig.json" }, - "plugins": ["@typescript-eslint"], - "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"], + "plugins": ["@typescript-eslint", "require-extensions"], + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:require-extensions/recommended" + ], "rules": { "@typescript-eslint/no-non-null-assertion": "off", "@typescript-eslint/no-explicit-any": "off", diff --git a/packages/typespec-ts/package.json b/packages/typespec-ts/package.json index a4f4e5e793..e4f1b5a484 100644 --- a/packages/typespec-ts/package.json +++ b/packages/typespec-ts/package.json @@ -63,7 +63,8 @@ "@azure/core-lro": "^2.5.4", "@azure/core-rest-pipeline": "^1.12.0", "@azure/logger": "^1.0.4", - "@azure/core-util": "^1.4.0" + "@azure/core-util": "^1.4.0", + "eslint-plugin-require-extensions": "0.1.3" }, "peerDependencies": { "@azure-tools/typespec-azure-core": ">=0.34.0 <1.0.0", diff --git a/packages/typespec-ts/src/index.ts b/packages/typespec-ts/src/index.ts index 184da08647..fcb210c48a 100644 --- a/packages/typespec-ts/src/index.ts +++ b/packages/typespec-ts/src/index.ts @@ -29,7 +29,8 @@ import { buildLogger, RLCOptions, hasUnexpectedHelper, - RLCModel + RLCModel, + buildSamples } from "@azure-tools/rlc-common"; import { transformRLCModel } from "./transform/transform.js"; import { emitContentByBuilder, emitModels } from "./utils/emitUtil.js"; @@ -137,6 +138,12 @@ export async function $onEmit(context: EmitContext) { await emitContentByBuilder(program, buildPaginateHelper, rlcModels); await emitContentByBuilder(program, buildPollingHelper, rlcModels); await emitContentByBuilder(program, buildSerializeHelper, rlcModels); + await emitContentByBuilder( + program, + buildSamples, + rlcModels, + dpgContext.generationPathDetail?.metadataDir + ); } } diff --git a/packages/typespec-ts/src/transform/transform.ts b/packages/typespec-ts/src/transform/transform.ts index 10c08d5042..ad859f98bb 100644 --- a/packages/typespec-ts/src/transform/transform.ts +++ b/packages/typespec-ts/src/transform/transform.ts @@ -35,6 +35,7 @@ import { transformApiVersionInfo } from "./transformApiVersionInfo.js"; import { getClientLroOverload } from "../utils/operationUtil.js"; import { transformTelemetryInfo } from "./transformTelemetryInfo.js"; import { SdkContext } from "../utils/interfaces.js"; +import { transformSampleGroups } from "@azure-tools/rlc-common"; export async function transformRLCModel( client: SdkClient, @@ -60,7 +61,6 @@ export async function transformRLCModel( const importSet = new Map>(); const paths: Paths = transformPaths(program, client, dpgContext); const schemas: Schema[] = transformSchemas(program, client, dpgContext); - const responses: OperationResponse[] = transformToResponseTypes( importSet, client, @@ -77,7 +77,7 @@ export async function transformRLCModel( const urlInfo = transformUrlInfo(dpgContext); const apiVersionInfo = transformApiVersionInfo(client, dpgContext, urlInfo); const telemetryOptions = transformTelemetryInfo(dpgContext, client); - return { + const model: RLCModel = { srcPath, libraryName, paths, @@ -91,6 +91,12 @@ export async function transformRLCModel( urlInfo, telemetryOptions }; + model.sampleGroups = transformSampleGroups( + model, + options?.generateSample === + true /* Enable mock sample content if generateSample === true */ + ); + return model; } export function transformUrlInfo(dpgContext: SdkContext): UrlInfo | undefined { diff --git a/packages/typespec-ts/src/transform/transformParameters.ts b/packages/typespec-ts/src/transform/transformParameters.ts index 1c9c56aabe..b611479f06 100644 --- a/packages/typespec-ts/src/transform/transformParameters.ts +++ b/packages/typespec-ts/src/transform/transformParameters.ts @@ -304,7 +304,8 @@ function transformNormalBody( name: "body", type: overrideType ?? type, required: parameters?.bodyParameter?.optional === false, - description: descriptions.join("\n\n") + description: descriptions.join("\n\n"), + oriSchema: schema } ] }; diff --git a/packages/typespec-ts/src/utils/emitUtil.ts b/packages/typespec-ts/src/utils/emitUtil.ts index a68af04bdd..b1ce4c2d14 100644 --- a/packages/typespec-ts/src/utils/emitUtil.ts +++ b/packages/typespec-ts/src/utils/emitUtil.ts @@ -29,9 +29,15 @@ export async function emitContentByBuilder( builderFnOrList = [builderFnOrList]; } for (const builderFn of builderFnOrList) { - const contentFile = builderFn(rlcModels); - if (contentFile) { - await emitFile(contentFile, program, emitterOutputDir); + let contentFiles: File[] | File | undefined = builderFn(rlcModels); + if (!contentFiles) { + continue; + } + if (!Array.isArray(contentFiles)) { + contentFiles = [contentFiles]; + } + for (const file of contentFiles) { + await emitFile(file, program, emitterOutputDir); } } } diff --git a/packages/typespec-ts/src/utils/modelUtils.ts b/packages/typespec-ts/src/utils/modelUtils.ts index 96fdc51fd0..2dd242793c 100644 --- a/packages/typespec-ts/src/utils/modelUtils.ts +++ b/packages/typespec-ts/src/utils/modelUtils.ts @@ -652,11 +652,11 @@ function getSchemaForModel( function getSchemaForLiteral(type: Type): any { switch (type.kind) { case "Number": - return { type: `${type.value}` }; + return { type: `${type.value}`, isConstant: true }; case "String": - return { type: `"${type.value}"` }; + return { type: `"${type.value}"`, isConstant: true }; case "Boolean": - return { type: `${type.value}` }; + return { type: `${type.value}`, isConstant: true }; } if (type.kind === undefined) { if (typeof type === "string") { @@ -732,7 +732,7 @@ function applyIntrinsicDecorators( function getSchemaForEnumMember(program: Program, e: EnumMember) { const value = e.value ?? e.name; const type = enumMemberType(e) === "string" ? `"${value}"` : `${value}`; - return { type, description: getDoc(program, e) }; + return { type, description: getDoc(program, e), isConstant: true }; } function getSchemaForEnum(program: Program, e: Enum) { diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/booleanValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/booleanValueGetSample.ts new file mode 100644 index 0000000000..484c431f41 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/booleanValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function booleanValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/boolean").get(); + console.log(result); +} + +async function main() { + booleanValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/booleanValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/booleanValuePutSample.ts new file mode 100644 index 0000000000..fe11bf8319 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/booleanValuePutSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function booleanValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/boolean").put({ body: [true] }); + console.log(result); +} + +async function main() { + booleanValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/datetimeValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/datetimeValueGetSample.ts new file mode 100644 index 0000000000..cb0eef01de --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/datetimeValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function datetimeValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/datetime").get(); + console.log(result); +} + +async function main() { + datetimeValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/datetimeValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/datetimeValuePutSample.ts new file mode 100644 index 0000000000..103d5b0196 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/datetimeValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function datetimeValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client + .path("/type/array/datetime") + .put({ body: [new Date()] }); + console.log(result); +} + +async function main() { + datetimeValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/durationValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/durationValueGetSample.ts new file mode 100644 index 0000000000..b2902925b2 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/durationValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function durationValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/duration").get(); + console.log(result); +} + +async function main() { + durationValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/durationValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/durationValuePutSample.ts new file mode 100644 index 0000000000..4c77d4d4ab --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/durationValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function durationValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client + .path("/type/array/duration") + .put({ body: ["{Your body}"] }); + console.log(result); +} + +async function main() { + durationValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/float32ValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/float32ValueGetSample.ts new file mode 100644 index 0000000000..4a44e17624 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/float32ValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function float32ValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/float32").get(); + console.log(result); +} + +async function main() { + float32ValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/float32ValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/float32ValuePutSample.ts new file mode 100644 index 0000000000..2e5d850992 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/float32ValuePutSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function float32ValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/float32").put({ body: [123] }); + console.log(result); +} + +async function main() { + float32ValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int32ValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int32ValueGetSample.ts new file mode 100644 index 0000000000..46f722ee06 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int32ValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function int32ValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/int32").get(); + console.log(result); +} + +async function main() { + int32ValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int32ValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int32ValuePutSample.ts new file mode 100644 index 0000000000..47f5d51d5b --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int32ValuePutSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function int32ValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/int32").put({ body: [123] }); + console.log(result); +} + +async function main() { + int32ValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int64ValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int64ValueGetSample.ts new file mode 100644 index 0000000000..40236e878c --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int64ValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function int64ValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/int64").get(); + console.log(result); +} + +async function main() { + int64ValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int64ValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int64ValuePutSample.ts new file mode 100644 index 0000000000..6a0f838cdf --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/int64ValuePutSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function int64ValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/int64").put({ body: [123] }); + console.log(result); +} + +async function main() { + int64ValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/modelValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/modelValueGetSample.ts new file mode 100644 index 0000000000..623ade0881 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/modelValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function modelValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/model").get(); + console.log(result); +} + +async function main() { + modelValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/modelValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/modelValuePutSample.ts new file mode 100644 index 0000000000..182b429571 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/modelValuePutSample.ts @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function modelValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client + .path("/type/array/model") + .put({ + body: [ + { property: "{Your property}", children: [{} as any /**FIXME */] }, + ], + }); + console.log(result); +} + +async function main() { + modelValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/nullableFloatValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/nullableFloatValueGetSample.ts new file mode 100644 index 0000000000..1c7daa0d55 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/nullableFloatValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function nullableFloatValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/nullable-float").get(); + console.log(result); +} + +async function main() { + nullableFloatValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/nullableFloatValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/nullableFloatValuePutSample.ts new file mode 100644 index 0000000000..c303a12b15 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/nullableFloatValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function nullableFloatValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client + .path("/type/array/nullable-float") + .put({ body: [123] }); + console.log(result); +} + +async function main() { + nullableFloatValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/stringValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/stringValueGetSample.ts new file mode 100644 index 0000000000..21811a62c9 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/stringValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function stringValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/string").get(); + console.log(result); +} + +async function main() { + stringValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/stringValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/stringValuePutSample.ts new file mode 100644 index 0000000000..585468e229 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/stringValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function stringValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client + .path("/type/array/string") + .put({ body: ["{Your body}"] }); + console.log(result); +} + +async function main() { + stringValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/unknownValueGetSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/unknownValueGetSample.ts new file mode 100644 index 0000000000..44047a2e0b --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/unknownValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function unknownValueGetSample() { + const client = createArrayItemTypesClient(); + const result = await client.path("/type/array/unknown").get(); + console.log(result); +} + +async function main() { + unknownValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/unknownValuePutSample.ts b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/unknownValuePutSample.ts new file mode 100644 index 0000000000..f36a166926 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/samples-dev/unknownValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createArrayItemTypesClient from "@msinternal/array-itemtypes"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function unknownValuePutSample() { + const client = createArrayItemTypesClient(); + const result = await client + .path("/type/array/unknown") + .put({ body: ["Unknown Type"] }); + console.log(result); +} + +async function main() { + unknownValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/tspconfig.yaml b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/tspconfig.yaml index d6e1d18846..016c7abe78 100644 --- a/packages/typespec-ts/test/integration/generated/arrays/itemTypes/tspconfig.yaml +++ b/packages/typespec-ts/test/integration/generated/arrays/itemTypes/tspconfig.yaml @@ -8,6 +8,7 @@ options: addCredentials: false azureSdkForJs: false isTypeSpecTest: true + generateSample: true title: ArrayItemTypesClient enableOperationGroup: true packageDetails: diff --git a/packages/typespec-ts/test/integration/generated/azure/core/package.json b/packages/typespec-ts/test/integration/generated/azure/core/package.json index 18013086f5..a934c2bee6 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/package.json +++ b/packages/typespec-ts/test/integration/generated/azure/core/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "echo skipped.", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "echo skipped", "integration-test:node": "echo skipped", @@ -77,5 +77,11 @@ "rollup-plugin-sourcemaps": "^0.6.3", "uglify-js": "^3.4.9" }, - "type": "module" + "type": "module", + "//sampleConfiguration": { + "productName": "_Specs_AzureCoreBasic", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/azurecore" + } } diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/createOrReplaceSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/createOrReplaceSample.ts new file mode 100644 index 0000000000..b059d8996f --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/createOrReplaceSample.ts @@ -0,0 +1,32 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrReplace + * + * @summary call operation CreateOrReplace + */ +async function createOrReplaceSample() { + const client = createAzureCoreClient(); + const id = 123; + const result = await client + .path("/azure/core/basic/users/{id}", id) + .put({ + body: { + name: "{Your name}", + orders: [{ userId: 123, detail: "{Your detail}" }], + }, + }); + console.log(result); +} + +async function main() { + createOrReplaceSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/createOrUpdateSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/createOrUpdateSample.ts new file mode 100644 index 0000000000..82baf9bdd1 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/createOrUpdateSample.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation CreateOrUpdate + * + * @summary call operation CreateOrUpdate + */ +async function createOrUpdateSample() { + const client = createAzureCoreClient(); + const id = 123; + const result = await client + .path("/azure/core/basic/users/{id}", id) + .patch({ + body: { + name: "{Your name}", + orders: [{ userId: 123, detail: "{Your detail}" }], + }, + contentType: "application/merge-patch+json", + }); + console.log(result); +} + +async function main() { + createOrUpdateSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/deleteSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/deleteSample.ts new file mode 100644 index 0000000000..a4a0dc800c --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/deleteSample.ts @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Delete + * + * @summary call operation Delete + */ +async function deleteSample() { + const client = createAzureCoreClient(); + const id = 123; + const result = await client.path("/azure/core/basic/users/{id}", id).delete(); + console.log(result); +} + +async function main() { + deleteSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/exportSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/exportSample.ts new file mode 100644 index 0000000000..d7e4fbc7ae --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/exportSample.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Export + * + * @summary call operation Export + */ +async function exportSample() { + const client = createAzureCoreClient(); + const id = 123; + const result = await client + .path("/azure/core/basic/users/{id}:export", id) + .post({ queryParameters: { format: "{Your format}" } }); + console.log(result); +} + +async function main() { + exportSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/getSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/getSample.ts new file mode 100644 index 0000000000..6e62de153a --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/getSample.ts @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function getSample() { + const client = createAzureCoreClient(); + const id = 123; + const result = await client.path("/azure/core/basic/users/{id}", id).get(); + console.log(result); +} + +async function main() { + getSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listSample.ts new file mode 100644 index 0000000000..e3e88ca655 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listSample.ts @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient, { paginate } from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation List + * + * @summary call operation List + */ +async function listSample() { + const client = createAzureCoreClient(); + const initialResponse = await client + .path("/azure/core/basic/users") + .get({ + queryParameters: { + top: 123, + skip: 123, + maxpagesize: 123, + orderby: "{Your orderby}", + filter: "{Your filter}", + select: "{Your select}", + expand: "{Your expand}", + }, + }); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listWithCustomPageModelSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listWithCustomPageModelSample.ts new file mode 100644 index 0000000000..0b3462ccb4 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listWithCustomPageModelSample.ts @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient, { paginate } from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListWithCustomPageModel + * + * @summary call operation ListWithCustomPageModel + */ +async function listWithCustomPageModelSample() { + const client = createAzureCoreClient(); + const initialResponse = await client + .path("/azure/core/basic/custom-page") + .get(); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listWithCustomPageModelSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listWithPageSample.ts b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listWithPageSample.ts new file mode 100644 index 0000000000..9e68740cd3 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/azure/core/samples-dev/listWithPageSample.ts @@ -0,0 +1,29 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createAzureCoreClient, { paginate } from "@msinternal/azurecore"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ListWithPage + * + * @summary call operation ListWithPage + */ +async function listWithPageSample() { + const client = createAzureCoreClient(); + const initialResponse = await client.path("/azure/core/basic/page").get(); + const pageData = paginate(client, initialResponse); + const result = []; + for await (const item of pageData) { + result.push(item); + } + console.log(result); +} + +async function main() { + listWithPageSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/azure/core/tsconfig.json b/packages/typespec-ts/test/integration/generated/azure/core/tsconfig.json index b0bce971f9..a9c7d0ade6 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/tsconfig.json +++ b/packages/typespec-ts/test/integration/generated/azure/core/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/azurecore": ["./src/index"] } }, - "include": ["./src/**/*.ts"] + "include": ["./src/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-ts/test/integration/generated/azure/core/tspconfig.yaml b/packages/typespec-ts/test/integration/generated/azure/core/tspconfig.yaml index 22534328d5..0d228a6a7a 100644 --- a/packages/typespec-ts/test/integration/generated/azure/core/tspconfig.yaml +++ b/packages/typespec-ts/test/integration/generated/azure/core/tspconfig.yaml @@ -8,6 +8,7 @@ options: addCredentials: false azureSdkForJs: false isTypeSpecTest: true + generateSample: true title: AzureCoreClient packageDetails: name: "@msinternal/azurecore" diff --git a/packages/typespec-ts/test/integration/generated/dictionary/package.json b/packages/typespec-ts/test/integration/generated/dictionary/package.json index 67330ff2c3..590a1dfdc6 100644 --- a/packages/typespec-ts/test/integration/generated/dictionary/package.json +++ b/packages/typespec-ts/test/integration/generated/dictionary/package.json @@ -27,11 +27,11 @@ "build:samples": "echo skipped.", "build:test": "echo skipped.", "build:debug": "echo skipped.", - "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "check-format": "prettier --list-different --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "clean": "rimraf --glob dist dist-browser dist-esm test-dist temp types *.tgz *.log", "execute:samples": "echo skipped", "extract-api": "rimraf review && mkdirp ./review && api-extractor run --local", - "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" ", + "format": "prettier --write --config ../../../.prettierrc.json --ignore-path ../../../.prettierignore \"src/**/*.ts\" \"*.{js,json}\" \"samples-dev/**/*.ts\"", "generate:client": "echo skipped", "integration-test:browser": "echo skipped", "integration-test:node": "echo skipped", @@ -76,5 +76,11 @@ "rollup-plugin-sourcemaps": "^0.6.3", "uglify-js": "^3.4.9" }, - "type": "module" + "type": "module", + "//sampleConfiguration": { + "productName": "TypeDictionary", + "productSlugs": ["azure"], + "disableDocsMs": true, + "apiRefLink": "https://docs.microsoft.com/javascript/api/@msinternal/dictionary" + } } diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/booleanValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/booleanValueGetSample.ts new file mode 100644 index 0000000000..5f06d7db16 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/booleanValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function booleanValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/boolean").get(); + console.log(result); +} + +async function main() { + booleanValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/booleanValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/booleanValuePutSample.ts new file mode 100644 index 0000000000..f32a39487c --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/booleanValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function booleanValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/boolean") + .put({ body: { key: true } }); + console.log(result); +} + +async function main() { + booleanValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/datetimeValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/datetimeValueGetSample.ts new file mode 100644 index 0000000000..c14877f94c --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/datetimeValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function datetimeValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/datetime").get(); + console.log(result); +} + +async function main() { + datetimeValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/datetimeValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/datetimeValuePutSample.ts new file mode 100644 index 0000000000..62e4868d1e --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/datetimeValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function datetimeValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/datetime") + .put({ body: { key: new Date() } }); + console.log(result); +} + +async function main() { + datetimeValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/durationValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/durationValueGetSample.ts new file mode 100644 index 0000000000..adf43bd49e --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/durationValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function durationValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/duration").get(); + console.log(result); +} + +async function main() { + durationValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/durationValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/durationValuePutSample.ts new file mode 100644 index 0000000000..004fdf9c64 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/durationValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function durationValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/duration") + .put({ body: { key: "{Your body}" } }); + console.log(result); +} + +async function main() { + durationValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/float32ValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/float32ValueGetSample.ts new file mode 100644 index 0000000000..f06e3ceacd --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/float32ValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function float32ValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/float32").get(); + console.log(result); +} + +async function main() { + float32ValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/float32ValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/float32ValuePutSample.ts new file mode 100644 index 0000000000..df5475632c --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/float32ValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function float32ValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/float32") + .put({ body: { key: 123 } }); + console.log(result); +} + +async function main() { + float32ValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int32ValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int32ValueGetSample.ts new file mode 100644 index 0000000000..ab86e64c49 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int32ValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function int32ValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/int32").get(); + console.log(result); +} + +async function main() { + int32ValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int32ValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int32ValuePutSample.ts new file mode 100644 index 0000000000..2483e1ce36 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int32ValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function int32ValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/int32") + .put({ body: { key: 123 } }); + console.log(result); +} + +async function main() { + int32ValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int64ValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int64ValueGetSample.ts new file mode 100644 index 0000000000..0b7066b16d --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int64ValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function int64ValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/int64").get(); + console.log(result); +} + +async function main() { + int64ValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int64ValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int64ValuePutSample.ts new file mode 100644 index 0000000000..02933ba1bc --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/int64ValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function int64ValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/int64") + .put({ body: { key: 123 } }); + console.log(result); +} + +async function main() { + int64ValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/modelValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/modelValueGetSample.ts new file mode 100644 index 0000000000..ea165bd2ea --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/modelValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function modelValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/model").get(); + console.log(result); +} + +async function main() { + modelValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/modelValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/modelValuePutSample.ts new file mode 100644 index 0000000000..53f32d7bb3 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/modelValuePutSample.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function modelValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/model") + .put({ + body: { + key: { + property: "{Your property}", + children: { key: {} as any /**FIXME */ }, + }, + }, + }); + console.log(result); +} + +async function main() { + modelValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/nullableFloatValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/nullableFloatValueGetSample.ts new file mode 100644 index 0000000000..647886420d --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/nullableFloatValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function nullableFloatValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/nullable-float").get(); + console.log(result); +} + +async function main() { + nullableFloatValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/nullableFloatValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/nullableFloatValuePutSample.ts new file mode 100644 index 0000000000..1bf0837a6d --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/nullableFloatValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function nullableFloatValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/nullable-float") + .put({ body: { key: 123 } }); + console.log(result); +} + +async function main() { + nullableFloatValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/recursiveModelValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/recursiveModelValueGetSample.ts new file mode 100644 index 0000000000..b383e48a91 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/recursiveModelValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function recursiveModelValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/model/recursive").get(); + console.log(result); +} + +async function main() { + recursiveModelValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/recursiveModelValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/recursiveModelValuePutSample.ts new file mode 100644 index 0000000000..4c7ac0c8bc --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/recursiveModelValuePutSample.ts @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function recursiveModelValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/model/recursive") + .put({ + body: { + key: { + property: "{Your property}", + children: { key: {} as any /**FIXME */ }, + }, + }, + }); + console.log(result); +} + +async function main() { + recursiveModelValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/stringValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/stringValueGetSample.ts new file mode 100644 index 0000000000..0d55a7b2fb --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/stringValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function stringValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/string").get(); + console.log(result); +} + +async function main() { + stringValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/stringValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/stringValuePutSample.ts new file mode 100644 index 0000000000..445c693f21 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/stringValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function stringValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/string") + .put({ body: { key: "{Your body}" } }); + console.log(result); +} + +async function main() { + stringValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/unknownValueGetSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/unknownValueGetSample.ts new file mode 100644 index 0000000000..476e50ffa2 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/unknownValueGetSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Get + * + * @summary call operation Get + */ +async function unknownValueGetSample() { + const client = createDictClient(); + const result = await client.path("/type/dictionary/unknown").get(); + console.log(result); +} + +async function main() { + unknownValueGetSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/unknownValuePutSample.ts b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/unknownValuePutSample.ts new file mode 100644 index 0000000000..10f593199b --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/dictionary/samples-dev/unknownValuePutSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createDictClient from "@msinternal/dictionary"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation Put + * + * @summary call operation Put + */ +async function unknownValuePutSample() { + const client = createDictClient(); + const result = await client + .path("/type/dictionary/unknown") + .put({ body: { key: "Unknown Type" } }); + console.log(result); +} + +async function main() { + unknownValuePutSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/dictionary/tsconfig.json b/packages/typespec-ts/test/integration/generated/dictionary/tsconfig.json index b0bce971f9..cef6e6e75e 100644 --- a/packages/typespec-ts/test/integration/generated/dictionary/tsconfig.json +++ b/packages/typespec-ts/test/integration/generated/dictionary/tsconfig.json @@ -19,7 +19,8 @@ "allowSyntheticDefaultImports": true, "esModuleInterop": true, "outDir": "./dist-esm", - "declarationDir": "./types" + "declarationDir": "./types", + "paths": { "@msinternal/dictionary": ["./src/index"] } }, - "include": ["./src/**/*.ts"] + "include": ["./src/**/*.ts", "samples-dev/**/*.ts"] } diff --git a/packages/typespec-ts/test/integration/generated/dictionary/tspconfig.yaml b/packages/typespec-ts/test/integration/generated/dictionary/tspconfig.yaml index 3a8ddc607e..3a99986a91 100644 --- a/packages/typespec-ts/test/integration/generated/dictionary/tspconfig.yaml +++ b/packages/typespec-ts/test/integration/generated/dictionary/tspconfig.yaml @@ -8,6 +8,7 @@ options: addCredentials: false azureSdkForJs: false isTypeSpecTest: true + generateSample: true title: DictClient enableOperationGroup: true packageDetails: diff --git a/packages/typespec-ts/test/integration/generated/union-body/samples-dev/requestUnionBodySample.ts b/packages/typespec-ts/test/integration/generated/union-body/samples-dev/requestUnionBodySample.ts new file mode 100644 index 0000000000..ec3a36bb84 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/union-body/samples-dev/requestUnionBodySample.ts @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionBodyClient from "@msinternal/union-body"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation RequestUnionBody + * + * @summary call operation RequestUnionBody + */ +async function requestUnionBodySample() { + const endpoint = "{Your endpoint}"; + const client = createUnionBodyClient(endpoint); + const result = await client + .path("/request-union-body") + .post({ body: { payMethod: "01" } }); + console.log(result); +} + +async function main() { + requestUnionBodySample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/union-body/samples-dev/responseUnionBodySample.ts b/packages/typespec-ts/test/integration/generated/union-body/samples-dev/responseUnionBodySample.ts new file mode 100644 index 0000000000..6099e2ecba --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/union-body/samples-dev/responseUnionBodySample.ts @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionBodyClient from "@msinternal/union-body"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ResponseUnionBody + * + * @summary call operation ResponseUnionBody + */ +async function responseUnionBodySample() { + const endpoint = "{Your endpoint}"; + const client = createUnionBodyClient(endpoint); + const result = await client.path("/response-union-body").get(); + console.log(result); +} + +async function main() { + responseUnionBodySample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/union-body/tspconfig.yaml b/packages/typespec-ts/test/integration/generated/union-body/tspconfig.yaml index a77bf2db10..8bd5a4a8fa 100644 --- a/packages/typespec-ts/test/integration/generated/union-body/tspconfig.yaml +++ b/packages/typespec-ts/test/integration/generated/union-body/tspconfig.yaml @@ -7,6 +7,7 @@ options: addCredentials: false azureSdkForJs: false isTypeSpecTest: true + generateSample: true title: UnionBodyClient packageDetails: name: "@msinternal/union-body" diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveFirstNamedUnionValueSample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveFirstNamedUnionValueSample.ts new file mode 100644 index 0000000000..48fb2c71a9 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveFirstNamedUnionValueSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ReceiveFirstNamedUnionValue + * + * @summary call operation ReceiveFirstNamedUnionValue + */ +async function receiveFirstNamedUnionValueSample() { + const client = createUnionsClient(); + const result = await client.path("/type/union/receive/model1").get(); + console.log(result); +} + +async function main() { + receiveFirstNamedUnionValueSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveIntArraySample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveIntArraySample.ts new file mode 100644 index 0000000000..db6107168b --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveIntArraySample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ReceiveIntArray + * + * @summary call operation ReceiveIntArray + */ +async function receiveIntArraySample() { + const client = createUnionsClient(); + const result = await client.path("/type/union/receive/int-array").get(); + console.log(result); +} + +async function main() { + receiveIntArraySample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveSecondNamedUnionValueSample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveSecondNamedUnionValueSample.ts new file mode 100644 index 0000000000..e873d79f73 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveSecondNamedUnionValueSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ReceiveSecondNamedUnionValue + * + * @summary call operation ReceiveSecondNamedUnionValue + */ +async function receiveSecondNamedUnionValueSample() { + const client = createUnionsClient(); + const result = await client.path("/type/union/receive/model2").get(); + console.log(result); +} + +async function main() { + receiveSecondNamedUnionValueSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveStringSample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveStringSample.ts new file mode 100644 index 0000000000..aa1e7950bb --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/receiveStringSample.ts @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation ReceiveString + * + * @summary call operation ReceiveString + */ +async function receiveStringSample() { + const client = createUnionsClient(); + const result = await client.path("/type/union/receive/string").get(); + console.log(result); +} + +async function main() { + receiveStringSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendFirstNamedUnionValueSample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendFirstNamedUnionValueSample.ts new file mode 100644 index 0000000000..207546ac0a --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendFirstNamedUnionValueSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation SendFirstNamedUnionValue + * + * @summary call operation SendFirstNamedUnionValue + */ +async function sendFirstNamedUnionValueSample() { + const client = createUnionsClient(); + const result = await client + .path("/type/union/model1") + .post({ body: { namedUnion: { name: "{Your name}", prop1: 123 } } }); + console.log(result); +} + +async function main() { + sendFirstNamedUnionValueSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendIntArraySample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendIntArraySample.ts new file mode 100644 index 0000000000..81913e9a76 --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendIntArraySample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation SendIntArray + * + * @summary call operation SendIntArray + */ +async function sendIntArraySample() { + const client = createUnionsClient(); + const result = await client + .path("/type/union/int-array") + .post({ body: { simpleUnion: 123 } }); + console.log(result); +} + +async function main() { + sendIntArraySample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendIntSample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendIntSample.ts new file mode 100644 index 0000000000..4efe2648cf --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendIntSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation SendInt + * + * @summary call operation SendInt + */ +async function sendIntSample() { + const client = createUnionsClient(); + const result = await client + .path("/type/union/int") + .post({ body: { simpleUnion: 123 } }); + console.log(result); +} + +async function main() { + sendIntSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendSecondNamedUnionValueSample.ts b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendSecondNamedUnionValueSample.ts new file mode 100644 index 0000000000..d082ae4dec --- /dev/null +++ b/packages/typespec-ts/test/integration/generated/unions/samples-dev/sendSecondNamedUnionValueSample.ts @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +import createUnionsClient from "@msinternal/unions"; +import * as dotenv from "dotenv"; + +dotenv.config(); + +/** + * This sample demonstrates how to call operation SendSecondNamedUnionValue + * + * @summary call operation SendSecondNamedUnionValue + */ +async function sendSecondNamedUnionValueSample() { + const client = createUnionsClient(); + const result = await client + .path("/type/union/model2") + .post({ body: { namedUnion: { name: "{Your name}", prop1: 123 } } }); + console.log(result); +} + +async function main() { + sendSecondNamedUnionValueSample(); +} + +main().catch(console.error); diff --git a/packages/typespec-ts/test/integration/generated/unions/tspconfig.yaml b/packages/typespec-ts/test/integration/generated/unions/tspconfig.yaml index 5900994c87..702d139abe 100644 --- a/packages/typespec-ts/test/integration/generated/unions/tspconfig.yaml +++ b/packages/typespec-ts/test/integration/generated/unions/tspconfig.yaml @@ -7,6 +7,7 @@ options: addCredentials: false azureSdkForJs: false isTypeSpecTest: true + generateSample: true title: UnionsClient packageDetails: name: "@msinternal/unions" diff --git a/packages/typespec-ts/test/tsconfig.json b/packages/typespec-ts/test/tsconfig.json index 1189a989e2..4455d07f98 100644 --- a/packages/typespec-ts/test/tsconfig.json +++ b/packages/typespec-ts/test/tsconfig.json @@ -1,5 +1,5 @@ { "extends": "../tsconfig.test.json", - "include": ["./**/*.ts", "./**/**/*.ts"], + "include": ["./**/*.ts", "./**/**/*.ts", "./**/**/**/*.ts"], "exclude": ["./integration/**/*.ts"] } diff --git a/packages/typespec-ts/test/unit/sample/generateSampleContent.spec.ts b/packages/typespec-ts/test/unit/sample/generateSampleContent.spec.ts new file mode 100644 index 0000000000..a7aa36aacf --- /dev/null +++ b/packages/typespec-ts/test/unit/sample/generateSampleContent.spec.ts @@ -0,0 +1,390 @@ +import { + RLCModel, + buildSchemaObjectMap, + generateParameterTypeValue +} from "@azure-tools/rlc-common"; +import { emitSchemasFromTypeSpec } from "../../util/emitUtil.js"; +import { assert } from "chai"; + +describe("Integration test for mocking sample", () => { + describe("request body", () => { + it("string", async () => { + const schemaMap = await emitSchemasFromTypeSpec(` + op getModel(@body input: string): void; + `); + const mockStr = generateParameterTypeValue( + "string", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + const res = "{Your input}"; + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + it("boolean", async () => { + const schemaMap = await emitSchemasFromTypeSpec(` + op getModel(@body input: boolean): void; + `); + const mockStr = generateParameterTypeValue( + "boolean", + "prop", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel), + new Set() + ); + assert.strictEqual(mockStr, `true`); + }); + + it("string[]", async () => { + const schemaMap = await emitSchemasFromTypeSpec(` + op getModel(@body input: string[]): void; + `); + const mockStr = generateParameterTypeValue( + "string[]", + "prop", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel), + new Set() + ); + const res = ["{Your prop}"]; + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + it("simple model", async () => { + const schemaMap = await emitSchemasFromTypeSpec(` + model Test { + prop: string; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel), + new Set() + ); + const res = { prop: "{Your prop}" }; + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + describe("complex model", () => { + describe("object", () => { + it("self-referenced model", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model A { + foo: B[]; + } + model B { + bar: A; + } + model Test { + selfReferenced: B; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + // console.log(mockStr); + assert.deepEqual( + mockStr, + `{"selfReferenced": {"bar": {"foo": [{} as any /**FIXME */]}}}` + ); + }); + + it("inheritance model", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + kind: string; + } + model B extends A{ + bar: string; + kind: "B"; + } + model Test { + inheritance: B; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + const res = { + inheritance: { bar: "{Your bar}", kind: "B", foo: "{Your foo}" } + }; + // console.log(mockStr); + assert.deepEqual(JSON.parse(mockStr!), res); + }); + }); + + it("primitives", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model Test { + // primitives + stringLiteral: "string literal"; + booleanLiteral: true; + numberLiteral: 1; + offsetDate: offsetDateTime; + nullable: null; + nullableString: string | null; + unknownValue: unknown; + } + op getModel(@body input: Test): void; + ` + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + // console.log(mockStr); + const res = { + stringLiteral: "string literal", + booleanLiteral: true, + numberLiteral: 1, + offsetDate: "{Your offsetDate}", + nullable: null, + nullableString: "{Your nullableString}", + unknownValue: "Unknown Type" + }; + assert.isNotNull(mockStr); + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + it("date", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model Test { + date: utcDateTime; + } + op getModel(@body input: Test): void; + ` + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + assert.deepEqual(mockStr, `{"date": new Date()}`); + }); + + it("enum", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + @fixed + enum FixedEnum { + English, + Chinese, + } + + @doc("Translation Language Values") + enum ExtensibleEnum { + English, + Chinese, + } + model Test { + fixedEnum: FixedEnum; + extensibleEnum: ExtensibleEnum; + otherStringEnum: "Chinese"; + otherLiteralUnion: "string1" | "string2"; + otherString: string; + testExtensibleEnum: ExtensibleEnum; + testFixedEnum: FixedEnum; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + // console.log(mockStr); + const res = { + fixedEnum: "English", + extensibleEnum: "English", + otherStringEnum: "Chinese", + otherLiteralUnion: "string1", + otherString: "{Your otherString}", + testExtensibleEnum: "English", + testFixedEnum: "English" + }; + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + it("array", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model B { + bar: string; + } + model Test { + objectArray: A[]; + complexArray: (A | B | string)[]; + simpleArray: string[]; + recordArray: Record[]; + literalArray: "string1"[]; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + const res = { + simpleArray: ["{Your simpleArray}"], + objectArray: [{ foo: "{Your foo}" }], + complexArray: [{ foo: "{Your foo}" }], + recordArray: [{ key: "{Your recordArray}" }], + literalArray: ["string1"] + }; + // console.log(mockStr); + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + describe("union", () => { + it("|", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model B { + bar: string; + } + model Test { + modelUnion: A | B; + stringUnion: "string1" | "string2"; + complexUnion: "string1" | 1 | true | A; + unionOfUnion: (A | B) | (1 | 2); + nullableLiteral: "string1" | null; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + const res = { + modelUnion: { foo: "{Your foo}" }, + stringUnion: "string1", + complexUnion: "string1", + unionOfUnion: { foo: "{Your foo}" }, + nullableLiteral: "string1" + }; + // console.log(mockStr); + assert.deepEqual(JSON.parse(mockStr!), res); + }); + + it("named union", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + @doc("This is a base model.") + model BaseModel { + name: string; + } + + @doc("The first one of the unioned model type.") + model Model1 extends BaseModel { + prop1: int32; + } + + @doc("The second one of the unioned model type.") + model Model2 extends BaseModel { + prop2: int32; + } + + union MyNamedUnion { + one: Model1, + two: Model2, + } + model Test { + namedUnion: MyNamedUnion; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + const res = { namedUnion: { prop1: 123, name: "{Your name}" } }; + // console.log(mockStr); + assert.deepEqual(JSON.parse(mockStr!), res); + }); + }); + + it("record", async () => { + const schemaMap = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model B { + bar: string; + } + model Test { + pro: B; + simpleRecord: Record; + objectRecord: Record; + complexRecord: Record; + recordOfRecord: Record>; + recordOfLiteral: Record<"string1">; + recordOfArray: Record; + } + op getModel(@body input: Test): void; + `, + true + ); + const mockStr = generateParameterTypeValue( + "Test", + "input", + buildSchemaObjectMap({ schemas: schemaMap } as RLCModel) + ); + assert.isNotNull(mockStr); + const res = { + pro: { bar: "{Your bar}" }, + simpleRecord: { key: "{Your simpleRecord}" }, + objectRecord: { key: { foo: "{Your foo}" } }, + complexRecord: { key: { bar: "{Your bar}" } }, + recordOfRecord: { key: { key: "{Your recordOfRecord}" } }, + recordOfLiteral: { key: "string1" }, + recordOfArray: { key: ["{Your recordOfArray}"] } + }; + // console.log(mockStr); + assert.deepEqual(JSON.parse(mockStr!), res); + }); + }); + }); +}); diff --git a/packages/typespec-ts/test/unit/transform/transformSchemas.spec.ts b/packages/typespec-ts/test/unit/transform/transformSchemas.spec.ts new file mode 100644 index 0000000000..5bd465a818 --- /dev/null +++ b/packages/typespec-ts/test/unit/transform/transformSchemas.spec.ts @@ -0,0 +1,489 @@ +import { ObjectSchema } from "@azure-tools/rlc-common"; +import { emitSchemasFromTypeSpec } from "../../util/emitUtil.js"; +import { assert } from "chai"; + +describe("#transformSchemas", () => { + describe("verify first property", () => { + async function verifyFirstProperty(tspType: string) { + const schemaOutput = await emitSchemasFromTypeSpec(` + model Test { + prop: ${tspType}; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + assert.deepEqual(first.usage, ["input", "output"]); + assert.strictEqual(first.name, "Test"); + assert.strictEqual(first.type, "object"); + return first.properties![`"prop"`]; + } + it("generate string type", async () => { + const property = await verifyFirstProperty("string"); + assert.isNotNull(property); + assert.deepEqual(property, { + type: "string", + description: undefined, + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate number type", async () => { + const property = await verifyFirstProperty("int32"); + assert.isNotNull(property); + assert.deepEqual(property, { + type: "number", + format: "int32", + description: undefined, + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate boolean type", async () => { + const property = await verifyFirstProperty("boolean"); + assert.isNotNull(property); + assert.strictEqual(property!.type, "boolean"); + }); + + it("generate date type", async () => { + const property = await verifyFirstProperty("utcDateTime"); + assert.isNotNull(property); + assert.strictEqual(property!.type, "string"); + assert.strictEqual(property!.typeName, "Date | string"); + assert.strictEqual(property!.outputTypeName, "string"); + }); + + it("generate string array", async () => { + const property = await verifyFirstProperty(`string[]`); + assert.isNotNull(property); + // console.log(property); + assert.deepEqual(property, { + type: "array", + items: { + type: "string", + description: "A sequence of textual characters." + }, + description: undefined, + typeName: "string[]", + usage: ["input", "output"], + required: true + } as any); + }); + + it("generate string literal array", async () => { + const property = await verifyFirstProperty(`"sss"[]`); + assert.isNotNull(property); + // console.log(property); + assert.deepEqual(property, { + type: "array", + items: { + type: `"sss"`, + isConstant: true + }, + description: undefined, + typeName: `"sss"[]`, + usage: ["input", "output"], + required: true + } as any); + }); + + it("generate string literal record", async () => { + const property = await verifyFirstProperty(`Record<"sss">`); + assert.isNotNull(property); + // console.log(property); + assert.deepEqual(property, { + type: "dictionary", + outputTypeName: "Record", + outputValueTypeName: "undefined", + valueTypeName: undefined, + additionalProperties: { + type: `"sss"`, + isConstant: true + }, + description: undefined, + typeName: "Record", + usage: ["input", "output"], + required: true + } as any); + }); + + it("generate string literal", async () => { + const property = await verifyFirstProperty(`"foo"`); + assert.isNotNull(property); + assert.strictEqual(property!.type, `"foo"`); + assert.isUndefined(property!.typeName); + assert.isUndefined(property!.outputTypeName); + assert.strictEqual(property!.isConstant, true); + }); + + it("generate number literal", async () => { + const property = await verifyFirstProperty(`1`); + assert.isNotNull(property); + assert.strictEqual(property!.type, `1`); + assert.isUndefined(property!.typeName); + assert.isUndefined(property!.outputTypeName); + assert.strictEqual(property!.isConstant, true); + }); + + it("generate boolean literal", async () => { + const property = await verifyFirstProperty(`true`); + assert.isNotNull(property); + assert.strictEqual(property!.type, `true`); + assert.isUndefined(property!.typeName); + assert.isUndefined(property!.outputTypeName); + assert.strictEqual(property!.isConstant, true); + }); + + it("generate literal union", async () => { + const property = await verifyFirstProperty(`true | "test" | 1`); + assert.isNotNull(property); + assert.strictEqual(property!.type, `union`); + assert.strictEqual(property!.typeName, 'true | "test" | 1'); + assert.strictEqual(property!.outputTypeName, 'true | "test" | 1'); + assert.isUndefined(property!.isConstant); + assert.strictEqual(property!.enum!.length, 3); + assert.strictEqual(property!.enum![0].type, "true"); + assert.strictEqual(property!.enum![0].isConstant, true); + }); + + it("generate string literal union", async () => { + const property = await verifyFirstProperty(`"a" | "test"`); + assert.isNotNull(property); + assert.deepEqual(property, { + enum: [ + { type: '"a"', isConstant: true }, + { type: '"test"', isConstant: true } + ], + type: "union", + typeName: '"a" | "test"', + outputTypeName: '"a" | "test"', + required: true, + usage: ["input", "output"], + description: undefined + } as any); + }); + + it("generate primitive union", async () => { + const property = await verifyFirstProperty( + `string | int32 | boolean | utcDateTime` + ); + assert.isNotNull(property); + // console.log(property); + assert.deepEqual(property, { + enum: [ + { + type: "string", + description: "A sequence of textual characters." + }, + { type: "number", format: "int32" }, + { type: "boolean", description: undefined }, + { + type: "string", + format: undefined, + description: undefined, + typeName: "Date | string", + outputTypeName: "string" + } + ], + type: "union", + typeName: "string | number | boolean | Date | string", + outputTypeName: "string | number | boolean | string", + required: true, + usage: ["input", "output"], + description: undefined + } as any); + }); + + it("generate fixed enum", async () => { + const schemaOutput = await emitSchemasFromTypeSpec( + ` + #suppress "@azure-tools/typespec-azure-core/use-extensible-enum" "for test" + @fixed + @doc("Translation Language Values") + enum TranslationLanguageValues { + @doc("English descriptions") + English, + @doc("Chinese descriptions") + Chinese, + } + model Test { + prop: TranslationLanguageValues; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `, + true + ); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + const property = first.properties![`"prop"`]; + // console.log(first, property, property?.enum); + assert.isNotNull(property); + assert.deepEqual(property, { + type: '"English"|"Chinese"', + description: undefined, + enum: ["English", "Chinese"], + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate extensible enum", async () => { + const schemaOutput = await emitSchemasFromTypeSpec( + ` + @doc("Translation Language Values") + enum TranslationLanguageValues { + @doc("English descriptions") + English, + @doc("Chinese descriptions") + Chinese, + } + model Test { + prop: TranslationLanguageValues; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `, + true + ); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + const property = first.properties![`"prop"`]; + assert.isNotNull(property); + assert.deepEqual(property, { + type: '"English"|"Chinese"', + name: "string", + typeName: "string", + description: "Possible values: English, Chinese", + enum: ["English", "Chinese"], + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate union model", async () => { + const schemaOutput = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model B { + bar: string; + } + model Test { + prop: A | B; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `, + true + ); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + const property = first.properties![`"prop"`]; + // console.log(first, property, property?.enum); + assert.isNotNull(property); + assert.deepEqual(property, { + type: "union", + outputTypeName: "AOutput | BOutput", + typeName: "A | B", + description: undefined, + enum: [ + { + name: "A", + type: "object", + description: "", + typeName: "A", + properties: { + '"foo"': { + description: undefined, + required: true, + type: "string", + usage: ["input", "output"] + } + }, + outputTypeName: "AOutput", + usage: ["input", "output"] + }, + { + name: "B", + type: "object", + description: "", + typeName: "B", + properties: { + '"bar"': { + description: undefined, + required: true, + type: "string", + usage: ["input", "output"] + } + }, + outputTypeName: "BOutput", + usage: ["input", "output"] + } + ], + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate array model", async () => { + const schemaOutput = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model Test { + prop: A[]; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `, + true + ); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + const property = first.properties![`"prop"`]; + // console.log(first, property, property?.enum); + assert.isNotNull(property); + assert.deepEqual(property, { + type: "array", + outputTypeName: "Array", + typeName: "Array", + description: undefined, + items: { + name: "A", + type: "object", + description: "", + typeName: "A", + properties: {}, + outputTypeName: "AOutput", + usage: ["input", "output"] + }, + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate record model", async () => { + const schemaOutput = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model Test { + prop: Record; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `, + true + ); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + const property = first.properties![`"prop"`]; + // console.log(first, property, property?.enum); + assert.isNotNull(property); + assert.deepEqual(property, { + type: "dictionary", + outputTypeName: "Record", + outputValueTypeName: "AOutput", + typeName: "Record", + valueTypeName: "A", + description: undefined, + additionalProperties: { + name: "A", + type: "object", + description: "", + typeName: "A", + properties: {}, + outputTypeName: "AOutput", + usage: ["input", "output"] + }, + required: true, + usage: ["input", "output"] + } as any); + }); + + it("generate record ", async () => { + const schemaOutput = await emitSchemasFromTypeSpec( + ` + model A { + foo: string; + } + model B { + baz: string; + } + model Test { + prop: Record; + } + @route("/models") + @get + op getModel(@body input: Test): Test; + `, + true + ); + assert.isNotNull(schemaOutput); + const first = schemaOutput?.[0] as ObjectSchema; + const property = first.properties![`"prop"`]; + // console.log(first, property, (property as any)?.additionalProperties); + assert.isNotNull(property); + assert.deepEqual(property, { + type: "dictionary", + outputTypeName: "Record", + typeName: "Record", + description: undefined, + additionalProperties: { + enum: [ + { + name: "A", + type: "object", + description: "", + typeName: "A", + properties: { + '"foo"': { + type: "string", + description: undefined, + required: true, + usage: ["input", "output"] + } + }, + outputTypeName: "AOutput", + usage: ["input", "output"] + }, + { + name: "B", + type: "object", + description: "", + typeName: "B", + properties: { + '"baz"': { + type: "string", + description: undefined, + required: true, + usage: ["input", "output"] + } + }, + outputTypeName: "BOutput", + usage: ["input", "output"] + } + ], + type: "union", + typeName: "A | B", + outputTypeName: "AOutput | BOutput" + }, + required: true, + usage: ["input", "output"] + } as any); + }); + }); +}); diff --git a/packages/typespec-ts/test/util/emitUtil.ts b/packages/typespec-ts/test/util/emitUtil.ts index 25f93211c4..7f01386237 100644 --- a/packages/typespec-ts/test/util/emitUtil.ts +++ b/packages/typespec-ts/test/util/emitUtil.ts @@ -24,7 +24,10 @@ import { getRLCClients } from "../../src/utils/clientUtils.js"; import { expectDiagnosticEmpty } from "@typespec/compiler/testing"; import { transformHelperFunctionDetails } from "../../src/transform/transformHelperFunctionDetails.js"; import { emitCodeModel } from "../../src/modular/buildCodeModel.js"; -import { buildModels, buildModelsOptions } from "../../src/modular/emitModels.js"; +import { + buildModels, + buildModelsOptions +} from "../../src/modular/emitModels.js"; import { buildOperationFiles } from "../../src/modular/buildOperations.js"; import { buildClientContext } from "../../src/modular/buildClientContext.js"; import { Project } from "ts-morph"; @@ -58,6 +61,29 @@ export async function emitPageHelperFromTypeSpec( }); } +export async function emitSchemasFromTypeSpec( + tspContent: string, + needAzureCore: boolean = false, + needTCGC: boolean = false +) { + const context = await rlcEmitterFor( + tspContent, + true, + needAzureCore, + false, + needTCGC + ); + const program = context.program; + const dpgContext = createDpgContextTestHelper(context.program); + const clients = getRLCClients(dpgContext); + let rlcSchemas: Schema[] = []; + if (clients && clients[0]) { + rlcSchemas = transformSchemas(program, clients[0], dpgContext); + } + expectDiagnosticEmpty(program.diagnostics); + return rlcSchemas; +} + export async function emitModelsFromTypeSpec( tspContent: string, needAzureCore: boolean = false, @@ -144,7 +170,14 @@ export async function emitClientFactoryFromTypeSpec( isEmptyDiagnostic = true, withRawContent = false ) { - const context = await rlcEmitterFor(tspContent, false, needAzureCore, false, false, withRawContent); + const context = await rlcEmitterFor( + tspContent, + false, + needAzureCore, + false, + false, + withRawContent + ); const program = context.program; const dpgContext = createDpgContextTestHelper(context.program); const urlInfo = transformUrlInfo(dpgContext); @@ -215,7 +248,10 @@ export async function getRLCClientsFromTypeSpec(tspContent: string) { return clients; } -export async function emitModularModelsFromTypeSpec(tspContent: string, needOptions: boolean = false) { +export async function emitModularModelsFromTypeSpec( + tspContent: string, + needOptions: boolean = false +) { const context = await rlcEmitterFor(tspContent, true); const dpgContext = createDpgContextTestHelper(context.program); const serviceNameToRlcModelsMap: Map = new Map< @@ -244,7 +280,10 @@ export async function emitModularModelsFromTypeSpec(tspContent: string, needOpti modularCodeModel.clients[0] ) { if (needOptions) { - return buildModelsOptions(modularCodeModel, modularCodeModel.clients[0]); + return buildModelsOptions( + modularCodeModel, + modularCodeModel.clients[0] + ); } return buildModels(modularCodeModel, modularCodeModel.clients[0]); } @@ -293,8 +332,18 @@ export async function emitModularOperationsFromTypeSpec(tspContent: string) { return undefined; } -export async function emitModularClientContextFromTypeSpec(tspContent: string, withRawContent: boolean = false) { - const context = await rlcEmitterFor(tspContent, true, false, false, false, withRawContent); +export async function emitModularClientContextFromTypeSpec( + tspContent: string, + withRawContent: boolean = false +) { + const context = await rlcEmitterFor( + tspContent, + true, + false, + false, + false, + withRawContent + ); const dpgContext = createDpgContextTestHelper(context.program); const serviceNameToRlcModelsMap: Map = new Map< string, @@ -330,4 +379,4 @@ export async function emitModularClientContextFromTypeSpec(tspContent: string, w } expectDiagnosticEmpty(dpgContext.program.diagnostics); return undefined; -} \ No newline at end of file +}