-
Notifications
You must be signed in to change notification settings - Fork 80
fix issues in todo: anonymous array model import and sample mock value for credential #2342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
436a95e
cc8417a
c4f2f16
905fc3b
3aebff2
b2bc868
62ad4ea
68619d9
3c78c9a
dc528cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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>>, | ||
|
|
@@ -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 | ||
|
|
@@ -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}");` | ||
|
|
@@ -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}"};` | ||
| }); | ||
| } else if (flavor === "azure") { | ||
| clientParams.push({ | ||
| name: "credential", | ||
| assignment: "const credential = new DefaultAzureCredential();" | ||
|
|
@@ -257,6 +272,11 @@ function convertClientLevelParameters( | |
| "DefaultAzureCredential", | ||
| importedDict | ||
| ); | ||
| } else { | ||
| clientParams.push({ | ||
| name: "credential", | ||
| assignment: `const credential = {getToken: () => Promise.resolve({ token: "{Your token}", expiresOnTimestamp: 0 })};` | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }); | ||
| } | ||
| } | ||
| return clientParams; | ||
|
|
||
| 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); |
There was a problem hiding this comment.
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.