Skip to content

Commit

Permalink
Support for array parameters is added
Browse files Browse the repository at this point in the history
  • Loading branch information
mastafit committed Jan 10, 2024
1 parent e540622 commit 4d3e30f
Showing 1 changed file with 36 additions and 25 deletions.
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({
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

0 comments on commit 4d3e30f

Please sign in to comment.