allowableValues from Enum.values()?

3,085 views
Skip to first unread message

Michael Hosier

unread,
Aug 12, 2013, 2:44:50 PM8/12/13
to swagger-sw...@googlegroups.com
Is it possible to provide the allowableValues value from an enum using something like MyEnum.values()? It doesn't seem possible. What I really want is to just avoid having to statically type the enum names for obvious reasons, such as refactoring breaking this.

tony tam

unread,
Aug 12, 2013, 2:54:46 PM8/12/13
to swagger-sw...@googlegroups.com
Do you mean for a model property or an operation parameter?  If a model property, this is already supported:

Michael Hosier

unread,
Aug 12, 2013, 3:01:42 PM8/12/13
to swagger-sw...@googlegroups.com
Sorry, this specific instance is for a QueryParam in the ApiParam annotation. I have to declare it as 'allowableValues = "ENTRY1,ENTRY2,ENTRY3"', instead of using something like MyEnum.values() or new ArrayList<MyEnum>(MyEnum.values()), for example. Or even in this case I would say just using MyEnum.class as a value for allowableValues would be awesome, much like the response = MyClass.class feature.  Does this make sense or am I just missing something?
Message has been deleted

tony tam

unread,
Aug 13, 2013, 10:49:18 AM8/13/13
to swagger-sw...@googlegroups.com
Hi,
I believe enums are supported but only inside another object--they're explicitly ignored at the top-level for either response or input.  I have to say, I don't recall the exact reason why:


It might be worth hacking in there and seeing if it can be supported, and offering up a pull request if so.

Dilip Krishnan

unread,
Aug 13, 2013, 10:52:31 PM8/13/13
to swagger-sw...@googlegroups.com
This is supported in swagger-springmvc. I could possibly looking at submitting a PR

-D

Michael Hosier

unread,
Aug 14, 2013, 1:00:01 PM8/14/13
to swagger-sw...@googlegroups.com
Thanks for the code snippet. I will look into that. Your offer to generate a PR is generous, it seems like this would be a good thing to add into core.
Reply all
Reply to author
Forward
0 new messages