Skip to content

Commit

Permalink
Add support for textareas in the body form.
Browse files Browse the repository at this point in the history
Used for body parameters that have x-multiline: true in their definition.
  • Loading branch information
bojanz committed Dec 30, 2022
1 parent 0cbdb6f commit 86f295b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 15 deletions.
4 changes: 4 additions & 0 deletions cmd/broom/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ func bodyForm(op broom.Operation) (string, bool) {
form.AddDropDown(paramLabel, param.Enum, initialOption, func(option string, optionIndex int) {
values.Set(paramName, option)
})
} else if param.Multiline {
form.AddTextArea(paramLabel, paramDefault, 40, 0, 0, func(text string) {
values.Set(paramName, text)
})
} else {
form.AddInputField(paramLabel, paramDefault, 40, nil, func(text string) {
values.Set(paramName, text)
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ go 1.18

require (
github.com/gdamore/tcell/v2 v2.5.3
github.com/getkin/kin-openapi v0.108.0
github.com/getkin/kin-openapi v0.112.0
github.com/ghodss/yaml v1.0.0
github.com/google/go-cmp v0.5.9
github.com/grokify/html-strip-tags-go v0.0.1
github.com/iancoleman/strcase v0.2.0
github.com/rivo/tview v0.0.0-20221115143349-ed3ea789e9f7
github.com/rivo/tview v0.0.0-20221229180733-b86a50a5126c
github.com/spf13/pflag v1.0.5
github.com/tidwall/pretty v1.2.1
gopkg.in/yaml.v2 v2.4.0
Expand All @@ -26,8 +26,8 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/term v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/sys v0.3.0 // indirect
golang.org/x/term v0.3.0 // indirect
golang.org/x/text v0.5.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdk
github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg=
github.com/gdamore/tcell/v2 v2.5.3 h1:b9XQrT6QGbgI7JvZOJXFNczOQeIYbo8BfeSMzt2sAV0=
github.com/gdamore/tcell/v2 v2.5.3/go.mod h1:wSkrPaXoiIWZqW/g7Px4xc79di6FTcpB8tvaKJ6uGBo=
github.com/getkin/kin-openapi v0.108.0 h1:EYf0GtsKa4hQNIlplGS+Au7NEfGQ1F7MoHD2kcVevPQ=
github.com/getkin/kin-openapi v0.108.0/go.mod h1:QtwUNt0PAAgIIBEvFWYfB7dfngxtAaqCX1zYHMZDeK8=
github.com/getkin/kin-openapi v0.112.0 h1:lnLXx3bAG53EJVI4E/w0N8i1Y/vUZUEsnrXkgnfn7/Y=
github.com/getkin/kin-openapi v0.112.0/go.mod h1:QtwUNt0PAAgIIBEvFWYfB7dfngxtAaqCX1zYHMZDeK8=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
Expand Down Expand Up @@ -44,8 +44,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/tview v0.0.0-20221115143349-ed3ea789e9f7 h1:9m4q3Li2CP/O4yfbZYJhySCuUg/VpV4jZhpvUcUYu8E=
github.com/rivo/tview v0.0.0-20221115143349-ed3ea789e9f7/go.mod h1:YX2wUZOcJGOIycErz2s9KvDaP0jnWwRCirQMPLPpQ+Y=
github.com/rivo/tview v0.0.0-20221229180733-b86a50a5126c h1:Xa0IDAwI/b4D3AQwFOhvOeYB/H0N8Bhhe3XJWSa2vjg=
github.com/rivo/tview v0.0.0-20221229180733-b86a50a5126c/go.mod h1:lBUy/T5kyMudFzWUH/C2moN+NlU5qF505vzOyINXuUQ=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand All @@ -63,15 +63,15 @@ github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220318055525-2edf467146b5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A=
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.2.0 h1:z85xZCsEl7bi/KwbNADeBYoOP0++7W1ipu+aGnpwzRM=
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 1 addition & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ type Parameter struct {
Default any
Deprecated bool
Required bool
Multiline bool
}

// Label returns a human-readable parameter label.
Expand Down
2 changes: 2 additions & 0 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func newOperationFromSpec(method string, path string, params openapi3.Parameters
required = true
}
}
_, multiline := schema.Value.Extensions["x-multiline"]

op.Parameters.Add(Parameter{
In: "body",
Expand All @@ -153,6 +154,7 @@ func newOperationFromSpec(method string, path string, params openapi3.Parameters
Default: schema.Value.Default,
Deprecated: schema.Value.Deprecated,
Required: required,
Multiline: multiline,
})
}
break
Expand Down
16 changes: 16 additions & 0 deletions spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ func TestLoadOperations(t *testing.T) {
Default: any("USD"),
Required: true,
},
broom.Parameter{
In: "body",
Name: "description",
Description: "The product description.",
Type: "string",
Default: nil,
Multiline: true,
},
broom.Parameter{
In: "body",
Name: "name",
Expand Down Expand Up @@ -154,6 +162,14 @@ func TestLoadOperations(t *testing.T) {
Enum: []string{"EUR", "USD"},
Default: nil,
},
broom.Parameter{
In: "body",
Name: "description",
Description: "The product description.",
Type: "string",
Default: nil,
Multiline: true,
},
broom.Parameter{
In: "body",
Name: "name",
Expand Down
12 changes: 12 additions & 0 deletions testdata/openapi3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ paths:
sku:
type: string
description: The product sku.
description:
type: string
description: The product description.
x-multiline: true
price:
type: integer
description: The product price, in cents.
Expand Down Expand Up @@ -161,6 +165,10 @@ paths:
sku:
type: string
description: The product sku.
description:
type: string
description: The product description.
x-multiline: true
price:
type: integer
description: The product price, in cents.
Expand Down Expand Up @@ -218,6 +226,10 @@ components:
sku:
type: string
description: The product sku.
description:
type: string
description: The product description.
x-multiline: true
price:
type: integer
description: The product price, in cents.
Expand Down
12 changes: 12 additions & 0 deletions testdata/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ paths:
sku:
type: string
description: The product sku.
description:
type: string
description: The product description.
x-multiline: true
price:
type: integer
description: The product price, in cents.
Expand Down Expand Up @@ -181,6 +185,10 @@ paths:
sku:
type: string
description: The product sku.
description:
type: string
description: The product description.
x-multiline: true
price:
type: integer
description: The product price, in cents.
Expand Down Expand Up @@ -230,6 +238,10 @@ definitions:
sku:
type: string
description: The product sku.
description:
type: string
description: The product description.
x-multiline: true
price:
type: integer
description: The product price, in cents.
Expand Down

0 comments on commit 86f295b

Please sign in to comment.