Skip to content

Commit

Permalink
feat: handle updating objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mikewuu committed Jan 23, 2024
1 parent 0d794ee commit 22529fb
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion lib/interact-for-open-api-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ export const interactForOpenApiObject = async (
},
]
: []),
...(haveAllRequiredParams && args.isSubProperty
? [
{
title: `[Set Property]`,
value: "set_property",
},
]
: []),
...(haveAllRequiredParams && args.isSubProperty
? [
{
title: `[Remove Property]`,
value: "remove_property",
},
]
: []),
...(haveAllRequiredParams && args.isSubProperty
? [
{
Expand Down Expand Up @@ -108,6 +124,48 @@ export const interactForOpenApiObject = async (
],
})

if (paramToEdit === "set_property") {
const name = (
await prompts({
name: "value",
message: "property?",
type: "text",
})
).value

const value = (
await prompts({
name: "value",
message: "value?",
type: "text",
})
).value

args.params[name] = value

return {
...args.params,
[name]: value,
}
}

if (paramToEdit === "remove_property") {
const name = (
await prompts({
name: "value",
message: "name?",
type: "text",
})
).value

const { [name]: _, ...otherParams } = args.params
return otherParams
}

if (paramToEdit === undefined) {
return args.params
}

if (paramToEdit === "empty") {
return undefined
}
Expand Down Expand Up @@ -225,7 +283,7 @@ export const interactForOpenApiObject = async (
args.params[paramToEdit] = await interactForOpenApiObject(
{
command: args.command,
params: {},
params: args.params[paramToEdit] ?? {},
schema: prop,
isSubProperty: true,
subPropertyPath: paramToEdit,
Expand Down

0 comments on commit 22529fb

Please sign in to comment.