How to signal to Swagger-UI a string array (for multiple values)

1,844 views
Skip to first unread message

Christopher Ambler

unread,
Sep 18, 2014, 11:02:03 AM9/18/14
to scalat...@googlegroups.com
I have the following field in a command:

  val domainSource: Field[Seq[String]] = asType[Seq[String]]("domain_source").description("Which domain sources should be returned").optional.
    sourcedFrom(ValueSource.Query).withDefaultValue(Seq("ALL")).allowableValues("ALL", "CCTLD", "PREMIUM", "KEYWORDSPIN", "EXTENSION", "KEYWORDASSIST").
    position(19)

This fails, of course, because the allowableValues is expecting a Seq (just like withDefaultValue)

I could make the allowable values a bunch of Seq and mix up all of the options, but that is clearly nonsensical. If the field is just a string, I'm given a dropdown in Swagger-UI allowing me to select one of the allowable values. But this is multiselect, so I need to be able to select one or more than one.

There must be a proper way to do this.

Am I once again missing the obvious? ;)

Christopher Ambler

unread,
Sep 18, 2014, 11:13:04 AM9/18/14
to scalat...@googlegroups.com
Looking at the PetStore example and then looking at Scalatra, it would appear that the "allowMultiple" decoration is missing completely.

There's no way to mark a parameter as expecting this, and then no way to note it as a "string" for Swagger-UI but convert it into a Seq (or List) coming in.

Was this a deliberate omission?

Christopher Ambler

unread,
Sep 18, 2014, 2:48:53 PM9/18/14
to scalat...@googlegroups.com
And after more digging, I see that the allowMultiple is, in fact, in the code, but commented out.

Any idea why?

Ivan Porto Carrero

unread,
Sep 18, 2014, 6:46:58 PM9/18/14
to scalat...@googlegroups.com
it is from an old version of the swagger spec. 

The type tells you whether it allows multiple or not. When I implemented this allowMultiple wasn't in the swagger 1.2 spec. So it was removed.

Now that I've looked at the newer 1.2 spec document allowMultiple is back, but I still think it's redundant information.
If you absolutely need it we can put it back but I've found that in many of those cases you might actually be better of modeling that as a body for your request than a query param. 

In 2.0 allow multiple is completely gone.

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero - Mob: +1 (415) 323-8084
Web: http://flanders.co.nz
Twitter: http://twitter.com/casualjim


On Thu, Sep 18, 2014 at 11:48 AM, Christopher Ambler <const.d...@gmail.com> wrote:
And after more digging, I see that the allowMultiple is, in fact, in the code, but commented out.

Any idea why?

--
You received this message because you are subscribed to the Google Groups "scalatra-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalatra-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Ambler

unread,
Sep 19, 2014, 2:26:17 PM9/19/14
to scalat...@googlegroups.com
So let me ask a different way -

Swagger-UI takes a string with allowableValues and builds a dropdown, allowing one to pick a single choice.

With allowMultiple=true, Swagger-UI builds a select box with multi-select enabled, allowing you to pick none, one or more strings.

It's that latter functionality that I need. This is on a GET, so I don't get a body. It's a comma-separated list of strings on the query string. Now yes, I can make this a simple string and parse it myself, but then I don't get the benefit of constrained allowable values in Swagger. I get a string that I then need to keep documentation on and validate and keep those in sync.

See the problem?

So if allowMultiple is gone in 2.0, what replaces it? How do we create a multi-value parameter with a constrained list of allowable values?

naresh k

unread,
Dec 9, 2014, 6:55:34 AM12/9/14
to scalat...@googlegroups.com
I have the same issue, can someone help me on this.

Thanks & Regards,
Naresh.K

Ameni Gaaloul

unread,
Apr 20, 2018, 6:57:08 AM4/20/18
to scalatra-user
"Swagger-UI builds a select box with multi-select enabled, allowing you to pick none, one or more strings."
Exactly what i m looking for. can you help me?
Reply all
Reply to author
Forward
0 new messages