Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/SwaggerWcf/Models/DefinitionProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public DefinitionProperty()

public bool UniqueItems { get; set; }

public List<int> Enum { get; set; }
public List<string> Enum { get; set; }

public decimal MultipleOf { get; set; }

Expand Down Expand Up @@ -155,7 +155,7 @@ public void Serialize(JsonWriter writer)
{
writer.WritePropertyName("enum");
writer.WriteStartArray();
foreach (int e in Enum)
foreach (string e in Enum)
{
writer.WriteValue(e);
}
Expand Down
4 changes: 2 additions & 2 deletions src/SwaggerWcf/Models/DefinitionSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class DefinitionSchema

public List<DefinitionProperty> Properties { get; set; }

public List<int> Enum { get; set; }
public List<string> Enum { get; set; }

public void Serialize(JsonWriter writer)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ public void Serialize(JsonWriter writer)
{
writer.WritePropertyName("enum");
writer.WriteStartArray();
foreach (int e in Enum)
foreach (string e in Enum)
{
writer.WriteValue(e);
}
Expand Down
10 changes: 5 additions & 5 deletions src/SwaggerWcf/Support/DefinitionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private static Definition ConvertTypeToDefinition(Type definitionType, IList<str

if (schema.TypeFormat.Type == ParameterType.Integer && schema.TypeFormat.Format == "enum")
{
schema.Enum = new List<int>();
schema.Enum = new List<string>();

Type propType = definitionType;

Expand Down Expand Up @@ -215,14 +215,14 @@ public static void ApplyAttributeOptions(IEnumerable<SwaggerWcfPropertyAttribute
ApplyIfValid(LastValidValue(attrs, a => a._MultipleOf), x => prop.MultipleOf = x.Value);
}

public static int GetEnumMemberValue(Type enumType, string enumName)
public static string GetEnumMemberValue(Type enumType, string enumName)
{
if (string.IsNullOrWhiteSpace(enumName))
return 0;
return "";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use string.Empty instead

var enumVal = Enum.Parse(enumType, enumName, true);
var underlyingType = Enum.GetUnderlyingType(enumType);
var val = Convert.ChangeType(enumVal, underlyingType);
return Convert.ToInt32(val);
var val = enumName;//Convert.ChangeType(enumVal, underlyingType);
return val;
}

public static string GetEnumDescription(Enum value)
Expand Down
2 changes: 1 addition & 1 deletion src/SwaggerWcf/Support/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static TypeFormat MapSwaggerType(Type type, IList<Type> definitions = nul
//it's an enum, use string as the property type and enum values will be serialized later
if (type.IsEnum)
{
return new TypeFormat(ParameterType.Integer, "enum");
return new TypeFormat(ParameterType.String, "enum");
}

//it's a collection/array, so it will use the swagger "container" syntax
Expand Down
4 changes: 2 additions & 2 deletions src/SwaggerWcf/Support/TypeFieldsProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static DefinitionProperty ProcessField(FieldInfo propertyInfo, IList<str

if ((prop.TypeFormat.Type == ParameterType.Integer && prop.TypeFormat.Format == "enum") || (prop.TypeFormat.Type == ParameterType.Array && prop.Items.TypeFormat.Format == "enum"))
{
prop.Enum = new List<int>();
prop.Enum = new List<string>();

Type propType = propertyInfo.FieldType;

Expand All @@ -144,7 +144,7 @@ private static DefinitionProperty ProcessField(FieldInfo propertyInfo, IList<str
var enumMemberItem = Enum.Parse(propType, enumName, true);
string enumMemberDescription = DefinitionsBuilder.GetEnumDescription((Enum)enumMemberItem);
enumMemberDescription = (string.IsNullOrWhiteSpace(enumMemberDescription)) ? "" : $"({enumMemberDescription})";
int enumMemberValue = DefinitionsBuilder.GetEnumMemberValue(propType, enumName);
string enumMemberValue = DefinitionsBuilder.GetEnumMemberValue(propType, enumName);
if (prop.Description != null) prop.Enum.Add(enumMemberValue);
enumDescription += $" {enumName}{System.Web.HttpUtility.HtmlEncode(" = ")}{enumMemberValue} {enumMemberDescription}\r\n";
}
Expand Down
4 changes: 2 additions & 2 deletions src/SwaggerWcf/Support/TypePropertiesProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static DefinitionProperty ProcessProperty(PropertyInfo propertyInfo, ILi

if ((prop.TypeFormat.Type == ParameterType.Integer && prop.TypeFormat.Format == "enum") || (prop.TypeFormat.Type == ParameterType.Array && prop.Items.TypeFormat.Format == "enum"))
{
prop.Enum = new List<int>();
prop.Enum = new List<string>();

Type propType = propertyInfo.PropertyType;

Expand All @@ -144,7 +144,7 @@ private static DefinitionProperty ProcessProperty(PropertyInfo propertyInfo, ILi
var enumMemberItem = Enum.Parse(propType, enumName, true);
string enumMemberDescription = DefinitionsBuilder.GetEnumDescription((Enum)enumMemberItem);
enumMemberDescription = (string.IsNullOrWhiteSpace(enumMemberDescription)) ? "" : $"({enumMemberDescription})";
int enumMemberValue = DefinitionsBuilder.GetEnumMemberValue(propType, enumName);
string enumMemberValue = DefinitionsBuilder.GetEnumMemberValue(propType, enumName);
if (prop.Description != null) prop.Enum.Add(enumMemberValue);
enumDescription += $" {enumName}{System.Web.HttpUtility.HtmlEncode(" = ")}{enumMemberValue} {enumMemberDescription}\r\n";
}
Expand Down
Binary file modified src/SwaggerWcf/www/swagger-ui.zip
Binary file not shown.