From 86f295b4f3f69ac6d7fe04c758bc5a0098b65cfb Mon Sep 17 00:00:00 2001 From: Bojan Zivanovic Date: Fri, 30 Dec 2022 20:48:24 +0100 Subject: [PATCH] Add support for textareas in the body form. Used for body parameters that have x-multiline: true in their definition. --- cmd/broom/profile.go | 4 ++++ go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- operation.go | 1 + spec.go | 2 ++ spec_test.go | 16 ++++++++++++++++ testdata/openapi3.yaml | 12 ++++++++++++ testdata/swagger.yaml | 12 ++++++++++++ 8 files changed, 62 insertions(+), 15 deletions(-) diff --git a/cmd/broom/profile.go b/cmd/broom/profile.go index f1336b0..5713ece 100644 --- a/cmd/broom/profile.go +++ b/cmd/broom/profile.go @@ -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) diff --git a/go.mod b/go.mod index 638398c..4339871 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 ) diff --git a/go.sum b/go.sum index 278b60b..4a6c996 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/operation.go b/operation.go index 57f7e44..a3364b4 100644 --- a/operation.go +++ b/operation.go @@ -243,6 +243,7 @@ type Parameter struct { Default any Deprecated bool Required bool + Multiline bool } // Label returns a human-readable parameter label. diff --git a/spec.go b/spec.go index 1a26c10..397fbd4 100644 --- a/spec.go +++ b/spec.go @@ -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", @@ -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 diff --git a/spec_test.go b/spec_test.go index 7f4326b..e5de092 100644 --- a/spec_test.go +++ b/spec_test.go @@ -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", @@ -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", diff --git a/testdata/openapi3.yaml b/testdata/openapi3.yaml index d7b35f4..3eb94db 100644 --- a/testdata/openapi3.yaml +++ b/testdata/openapi3.yaml @@ -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. @@ -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. @@ -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. diff --git a/testdata/swagger.yaml b/testdata/swagger.yaml index bdb3705..11e360c 100644 --- a/testdata/swagger.yaml +++ b/testdata/swagger.yaml @@ -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. @@ -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. @@ -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.