List of Enums does not show the list of enum values in the Swagger schema
Hello,
If I have the model:
public class ATM
{
public enum Currency
{
USA,
CANADA
}
private List<Currency> supportedCurrencies;
}
The generated model in the schema would like something like:
ATM": {
"id": "ATM",
"description": "",
"properties": {
"supportedCurrencies": {
"$ref": "array",
"description": "",
"items": {
"$ref": "Currency"
}
}
}
}
But there's no mention of the available enum values. Is it possible to fix this, and if so, what should the model look like?
Would there just be an extra enum property under 'supportedCurrencies', or would the enum property appear under 'items'?
Thanks
Can you please upgrade to swagger-core 1.3.x? There will be an enum array of allowable values.
I'm using 1.3.0. I see the enum array for other properties that are an enum type, just not when they are of type List<SomeEnum>
This issue still effects v1.3.2. Items are displayed in swagger-ui as "array[ObjectClassName]" and that is all.
Here is the raw data for a resource containing a property of a list of DayOfWeek enums (names being SUNDAY, MONDAY, etc.):
{...
"daysOfWeek":{"type":"array","items":{"$ref":"DayOfWeek"}},
...}
That is the only mention of "DayOfWeek" in the entire raw data.
PS - If my model includes both a single enum value and a list of enum values, then the swagger-ui output looks like this:
...
dayOfWeek (DayOfWeek) = ['SUNDAY' or 'MONDAY' or 'TUESDAY' or 'WEDNESDAY' or 'THURSDAY' or 'FRIDAY' or 'SATURDAY'],
daysOfWeek (array[DayOfWeek]),
...
From raw data including:
{...
"dayOfWeek":{"$ref":"DayOfWeek","enum":["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]},
"daysOfWeek":{"type":"array","items":{"$ref":"DayOfWeek"}}
...}
...so enums obviously do work, just not if they are encapsulated into an array or list.
I've added a fix for this in our fork of swagger-core. Now the API description will include an enum attribute on the items object, if the items in the container are enums.
https://github.com/pingidentity/swagger-core/commit/86cc9879c73a8ee147a0c150082f01a00937080c
I'm experiencing the same. I have a list of enum values and it would really help me if this is incorporated into swagger-core.
I'm only now seeing this. @rage-shadowman - the sample you posted regarding the single enum reference rather than the array one is actually wrong and shouldn't be like it. The correct output should have been something like
"dayOfWeek":{"type":"string","enum":["SUNDAY","MONDAY","TUESDAY","WEDNESDAY","THURSDAY","FRIDAY","SATURDAY"]}
The 1.2 spec does not allow defining an enumeration on a list of values, so this means the alternative for now would be to have an object (model) containing one field with an enumerated value, and then have a list of that model. This is how I'd expect swagger-core to deal with Enum lists at the moment at least.
@webron How does this deal with possible multiple values?
My interface actually expects a json value like this:
{
...
"daysOfWeek" : [ "SUNDAY","TUESDAY" ],
...
}
My corresponding java code would be List<DayOfWeek> daysOfWeek.
@TimSoethout - I understand what you're trying to do, but officially, there's no way to enforce that using the current swagger specification.
If you look at https://github.com/wordnik/swagger-spec/blob/master/versions/1.2.md#434-items-object you'll see that "enum" is not supported when the type is "array".
That said, it doesn't mean it shouldn't allow it, which is why I opened this issue - https://github.com/wordnik/swagger-spec/issues/35 - which you can follow.
@webron That's funny because when I built the swagger config files manually (as opposed to using swagger-core to generate them as I am doing now) it worked with the following:
"daysOfWeek": {
"type": "array",
"allowableValues": {
"valueType": "LIST",
"values": [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY" ]
}
},
displaying in swagger-ui as:
daysOfWeek (array) = ['MONDAY' or 'TUESDAY' or 'WEDNESDAY' or 'THURSDAY' or 'FRIDAY' or 'SATURDAY' or 'SUNDAY'],
That doesn't mean swagger-ui doesn't have extended functionality ;-) On May 7, 2014 11:15 PM, "Shadow Man" [email protected] wrote:
@webron https://github.com/webron That's funny because when I built the swagger config files manually (as opposed to using swagger-core to generate them as I am doing now) it worked with the following:
"daysOfWeek": { "type": "array", "allowableValues": { "valueType": "LIST", "values": [ "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY" ] } },displaying in swagger-ui as:
daysOfWeek (array) = ['MONDAY' or 'TUESDAY' or 'WEDNESDAY' or 'THURSDAY' or 'FRIDAY' or 'SATURDAY' or 'SUNDAY'],
— Reply to this email directly or view it on GitHubhttps://github.com/wordnik/swagger-core/issues/375#issuecomment-42477547 .
Looks like this is a spec question. Closing...
I have following enum for generation of enum i like to display successValue and okValue instead of just OK and SUCCESS. Any help would be appreciated `package com.main;
import com.fasterxml.jackson.databind.annotation.JsonSerialize; @JsonSerialize(using = SerialiazerEnum.class) public enum ActionType { SUCCESS("successValue"), OK("okValue"); private final String value; ActionType(String value) { this.value = value; } @Override public String toString() { return value; } }`