Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/autorest.typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"source-map-support": "^0.5.16",
"ts-morph": "^15.1.0",
"@azure/core-auth": "^1.6.0",
"@azure-tools/rlc-common": "workspace:^0.24.0"
"@azure-tools/rlc-common": "workspace:^0.25.0"
},
"devDependencies": {
"@azure-tools/test-recorder": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./types/index.d.ts",
"mainEntryPointFilePath": "./types/src/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"main": "dist/index.js",
"module": "./dist-esm/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/dpg-customization-rest.d.ts",
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./types/index.d.ts",
"mainEntryPointFilePath": "./types/src/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"main": "dist/index.js",
"module": "./dist-esm/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/header-rest.d.ts",
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./types/index.d.ts",
"mainEntryPointFilePath": "./types/src/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"main": "dist/index.js",
"module": "./dist-esm/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/media-types-service-rest.d.ts",
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./types/index.d.ts",
"mainEntryPointFilePath": "./types/src/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"main": "dist/index.js",
"module": "./dist-esm/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/multiple-inheritance-rest.d.ts",
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
Expand Down
2 changes: 1 addition & 1 deletion packages/rlc-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/rlc-common",
"version": "0.24.0",
"version": "0.25.0",
"description": "",
"type": "module",
"main": "dist/index.js",
Expand Down
6 changes: 3 additions & 3 deletions packages/rlc-common/src/metadata/buildApiExtractorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { Project } from "ts-morph";
import { RLCModel } from "../interfaces.js";

export function buildApiExtractorConfig(model: RLCModel) {
const { generateTest } = model.options || {};
const { packageDetails, isModularLibrary } = model.options || {};
const { packageDetails, isModularLibrary, generateTest, generateSample } =
model.options || {};
const project = new Project();
const config = {
$schema:
"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
mainEntryPointFilePath: `./types${
generateTest || isModularLibrary ? "/src" : ""
generateTest || isModularLibrary || generateSample ? "/src" : ""
}/index.d.ts`,
docModel: {
enabled: true
Expand Down
5 changes: 4 additions & 1 deletion packages/rlc-common/src/metadata/buildPackageFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ function restLevelPackage(model: RLCModel) {
keywords: ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
license: "MIT",
main: "dist/index.js",
module: generateTest ? "./dist-esm/src/index.js" : "./dist-esm/index.js",
module:
generateTest || generateSample
? "./dist-esm/src/index.js"
: "./dist-esm/index.js",
types: `./types/${
packageDetails.nameWithoutScope ?? packageDetails.name
}.d.ts`,
Expand Down
36 changes: 28 additions & 8 deletions packages/rlc-common/src/transformSampleGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,6 @@ function transformSpecialLetterToSpace(str: string) {
.replace("'s ", " ");
}

const tokenCredentialPackage = "@azure/identity";
const apiKeyCredentialPackage = "@azure/core-auth";

function enrichImportedString(
sampleGroup: RLCSampleGroup,
importedDict: Record<string, Set<string>>,
Expand Down Expand Up @@ -209,11 +206,17 @@ function convertClientLevelParameters(
// 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 {
addCredentials,
credentialScopes,
credentialKeyHeaderName,
customHttpAuthHeaderName,
flavor
} = model.options;
const hasUrlParameter = !!urlParameters,
hasCredentials =
addCredentials && (credentialScopes || credentialKeyHeaderName);
addCredentials &&
(credentialScopes || credentialKeyHeaderName || customHttpAuthHeaderName);

if (hasUrlParameter) {
// convert the host parameters in url
Expand All @@ -237,7 +240,11 @@ function convertClientLevelParameters(
}
if (hasCredentials) {
// Currently only support token credential
if (credentialKeyHeaderName) {
const apiKeyCredentialPackage =
flavor === "azure" ? "@azure/core-auth" : "@typespec/ts-http-runtime";
const tokenCredentialPackage =
flavor === "azure" ? "@azure/identity" : "@typespec/ts-http-runtime";
if (credentialKeyHeaderName && flavor === "azure") {
clientParams.push({
name: "credential",
assignment: `const credential = new AzureKeyCredential("{Your API key}");`
Expand All @@ -247,7 +254,15 @@ function convertClientLevelParameters(
"AzureKeyCredential",
importedDict
);
} else {
} else if (
(credentialKeyHeaderName && flavor !== "azure") ||
customHttpAuthHeaderName
) {
clientParams.push({
name: "credential",
assignment: `const credential = { key: "{Your API key}"};`
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also for the KeyCredential mock value here.

});
} else if (flavor === "azure") {
clientParams.push({
name: "credential",
assignment: "const credential = new DefaultAzureCredential();"
Expand All @@ -257,6 +272,11 @@ function convertClientLevelParameters(
"DefaultAzureCredential",
importedDict
);
} else {
clientParams.push({
name: "credential",
assignment: `const credential = {getToken: () => Promise.resolve({ token: "{Your token}", expiresOnTimestamp: 0 })};`
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joheredi I wonder if you have any concerns for this part for generating the mock value for token credential as we don't have @azure/identity in non-branded scope.

});
}
}
return clientParams;
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@azure-tools/typespec-autorest": ">=0.40.0 <1.0.0",
"@typespec/openapi3": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.40.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0",
"@azure-tools/typespec-client-generator-core": ">=0.40.0 <1.0.0",
"@typespec/compiler": ">=0.54.0 <1.0.0",
"@typespec/http": ">=0.54.0 <1.0.0",
"@typespec/rest": ">=0.54.0 <1.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"mainEntryPointFilePath": "./types/index.d.ts",
"mainEntryPointFilePath": "./types/src/index.d.ts",
"docModel": { "enabled": true },
"apiReport": { "enabled": true, "reportFolder": "./review" },
"dtsRollup": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"keywords": ["node", "azure", "cloud", "typescript", "browser", "isomorphic"],
"license": "MIT",
"main": "dist/index.js",
"module": "./dist-esm/index.js",
"module": "./dist-esm/src/index.js",
"types": "./types/todo-non-branded.d.ts",
"repository": "github:Azure/azure-sdk-for-js",
"bugs": { "url": "https://github.com/Azure/azure-sdk-for-js/issues" },
Expand All @@ -26,11 +26,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",
Expand Down Expand Up @@ -71,5 +71,11 @@
"rollup": "^2.66.1",
"rollup-plugin-sourcemaps": "^0.6.3",
"uglify-js": "^3.4.9"
},
"//sampleConfiguration": {
"productName": "Todo App",
"productSlugs": ["azure"],
"disableDocsMs": true,
"apiRefLink": "https://docs.microsoft.com/javascript/api/@notabrand/todo-non-branded?view=azure-node-preview"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed under the MIT license.

import createTodoClient from "@notabrand/todo-non-branded";
import * as dotenv from "dotenv";

dotenv.config();

/**
* This sample demonstrates how to call operation CreateUrlAttachment
*
* @summary call operation CreateUrlAttachment
*/
async function todoItemsAttachmentsCreateUrlAttachmentSample() {
const endpoint = "{Your endpoint}";
const credential = { key: "{Your API key}" };
const client = createTodoClient(endpoint, credential);
const itemId = 123;
const result = await client
.path("/items/{itemId}/attachments", itemId)
.post({
body: {
contents: { description: "{Your description}", url: "{Your url}" },
},
contentType: "application/json",
});
console.log(result);
}

async function main() {
todoItemsAttachmentsCreateUrlAttachmentSample();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed under the MIT license.

import createTodoClient from "@notabrand/todo-non-branded";
import * as dotenv from "dotenv";

dotenv.config();

/**
* This sample demonstrates how to call operation List
*
* @summary call operation List
*/
async function todoItemsAttachmentsListSample() {
const endpoint = "{Your endpoint}";
const credential = { key: "{Your API key}" };
const client = createTodoClient(endpoint, credential);
const itemId = 123;
const result = await client.path("/items/{itemId}/attachments", itemId).get();
console.log(result);
}

async function main() {
todoItemsAttachmentsListSample();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Licensed under the MIT license.

import createTodoClient from "@notabrand/todo-non-branded";
import * as dotenv from "dotenv";

dotenv.config();

/**
* This sample demonstrates how to call operation CreateJson
*
* @summary call operation CreateJson
*/
async function todoItemsCreateJsonSample() {
const endpoint = "{Your endpoint}";
const credential = { key: "{Your API key}" };
const client = createTodoClient(endpoint, credential);
const result = await client
.path("/items")
.post({
body: {
item: {
id: 123,
title: "{Your title}",
ownedBy: 123,
description: "{Your description}",
status: "NotStarted",
labels: ["{Your labels}"],
},
attachments: [{ description: "{Your description}", url: "{Your url}" }],
},
contentType: "application/json",
});
console.log(result);
}

async function main() {
todoItemsCreateJsonSample();
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed under the MIT license.

import createTodoClient from "@notabrand/todo-non-branded";
import * as dotenv from "dotenv";

dotenv.config();

/**
* This sample demonstrates how to call operation Delete
*
* @summary call operation Delete
*/
async function todoItemsDeleteSample() {
const endpoint = "{Your endpoint}";
const credential = { key: "{Your API key}" };
const client = createTodoClient(endpoint, credential);
const id = 123;
const result = await client.path("/items/{id}", id).delete();
console.log(result);
}

async function main() {
todoItemsDeleteSample();
}

main().catch(console.error);
Loading