private Schema CreateEnumSchema(JsonPrimitiveContract primitiveContract, Type type)
{
var stringEnumConverter = primitiveContract.Converter as StringEnumConverter
?? _jsonSerializerSettings.Converters.OfType<StringEnumConverter>().FirstOrDefault();
if (_describeAllEnumsAsStrings || stringEnumConverter != null)
{
var camelCase = _describeStringEnumsInCamelCase
|| (stringEnumConverter != null && stringEnumConverter.CamelCaseText);
return new Schema
{
type = "string",
example = type.GetEnumNames().FirstOrDefault(),
@enum = camelCase
? type.GetEnumNames().Select(name => name.ToCamelCase()).ToArray()
: type.GetEnumNames()
};
}
return new Schema
{
type = "integer",
format = "int32",
example = type.GetEnumNames().FirstOrDefault(),
@enum = type.GetEnumValues().Cast<object>().ToArray()
};
}