Skip to content

Commit 4db6e90

Browse files
committed
fixed enums on properties
1 parent 9740b64 commit 4db6e90

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

modules/swagger-core/src/main/java/com/wordnik/swagger/jackson/ModelResolver.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public Property resolveProperty(JavaType propType, ModelConverterContext context
4848

4949
// primitive or null
5050
property = getPrimitiveProperty(typeName);
51-
// modelProp.setQualifiedType(_typeQName(propType));
5251
// And then properties specific to subset of property types:
5352
if (propType.isContainerType()) {
5453
JavaType keyType = propType.getKeyType();
@@ -142,6 +141,7 @@ protected void _addEnumProps(Class<?> propClass, Property property) {
142141
final boolean useIndex = _mapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_INDEX);
143142
final boolean useToString = _mapper.isEnabled(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
144143
// List<AllowableValue> enums = new ArrayList<AllowableValue>();
144+
145145
@SuppressWarnings("unchecked")
146146
Class<Enum<?>> enumClass = (Class<Enum<?>>) propClass;
147147
for (Enum<?> en : enumClass.getEnumConstants()) {
@@ -329,6 +329,27 @@ else if(or.toLowerCase().startsWith("map[")) {
329329
property.setExample(_findExampleValue(member));
330330
property.setReadOnly(_findReadOnly(member));
331331

332+
333+
334+
if(property instanceof StringProperty) {
335+
if(mp != null) {
336+
String allowableValues = mp.allowableValues();
337+
LOGGER.debug("allowableValues " + allowableValues);
338+
if(!"".equals(allowableValues)) {
339+
String[] parts = allowableValues.split(",");
340+
LOGGER.debug("found " + parts.length + " parts");
341+
for(String part : parts) {
342+
if(property instanceof StringProperty) {
343+
StringProperty sp = (StringProperty) property;
344+
sp._enum(part.trim());
345+
LOGGER.debug("added enum value " + part);
346+
}
347+
}
348+
}
349+
}
350+
}
351+
352+
332353
if(property != null) {
333354
// check for XML annotations
334355
XmlElementWrapper wrapper = member.getAnnotation(XmlElementWrapper.class);

0 commit comments

Comments
 (0)