Skip to content
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

Support for adding array parameters e.g. access_codes/list editing parameter access_code_ids #68

Merged
merged 6 commits into from
Jan 11, 2024
Merged
Changes from 1 commit
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
61 changes: 36 additions & 25 deletions lib/interact-for-open-api-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,33 +200,44 @@ export const interactForOpenApiObject = async (
args.params[paramToEdit] = value

return interactForOpenApiObject(args, ctx)
} else if (prop.type === "array" && (prop as any)?.items?.enum) {
const value = (
await prompts({
name: "value",
message: `${paramToEdit}:`,
type: "autocompleteMultiselect",
choices: (prop as any).items.enum.map((v: string) => ({
title: v.toString(),
value: v.toString(),
})),
})
).value
} else if (prop.type === "array") {
if (
(prop as any)?.items?.type === "string" &&
!(prop as any)?.items?.enum
) {
let values = []
console.log(
`Enter multiple values for ${paramToEdit}, leave empty when done.`
)
while (true) {
const { value } = await prompts({
Copy link
Contributor

Choose a reason for hiding this comment

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

Create a subfunction in a seperate file called "interact for array"

name: "value",
message: `${paramToEdit}:`,
type: "text",
})

if (value) {
values.push(value)
} else {
break
}
}

args.params[paramToEdit] = values
return interactForOpenApiObject(args, ctx)
}
} else if ((prop as any)?.items?.enum) {
const { value } = await prompts({
name: "value",
message: `${paramToEdit}:`,
type: "autocompleteMultiselect",
choices: (prop as any).items.enum.map((v: string) => ({
title: v,
value: v,
})),
})
args.params[paramToEdit] = value
return interactForOpenApiObject(args, ctx)
} else if (
prop.type === "array" &&
(prop as any)?.items?.type === "string"
) {
const value = (
await prompts({
name: "value",
message: `${paramToEdit}:`,
type: "text",
})
).value
args.params[paramToEdit] = [value]
return interactForOpenApiObject(args, ctx)
} else if (prop.type === "object") {
args.params[paramToEdit] = await interactForOpenApiObject(
{
Expand Down
Loading