private Schema CreatePrimitiveSchema(JsonPrimitiveContract primitiveContract)
{
Schema schema;
if (primitiveContract.PropertyInfo() != null && primitiveContract.PropertyInfo().CustomAttributes != null)
{
//var isIgnored = primitiveContract.PropertyInfo().CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(SwaggerIgnore));
var isIgnored = primitiveContract.PropertyInfo().GetCustomAttribute<SwaggerIgnore>();
if (isIgnored != null)
{
return null;
}
//var customRouteName = primitiveContract.PropertyInfo().GetCustomAttribute<SwaggerRouteName>();
//if (customRouteName != null)
//{
// //
//}
}
var type = Nullable.GetUnderlyingType(primitiveContract.UnderlyingType) ?? primitiveContract.UnderlyingType;
if (type.IsEnum)
return CreateEnumSchema(primitiveContract, type);
switch (type.FullName)
{
case "System.Int16":
case "System.UInt16":
case "System.Int32":
case "System.UInt32":
schema = new Schema { type = "integer", format = "int32" };
break;
case "System.Int64":
case "System.UInt64":
schema = new Schema { type = "integer", format = "int64" };
break;
case "System.Single":
schema = new Schema { type = "number", format = "float" };
break;
case "System.Double":
case "System.Decimal":
schema = new Schema { type = "number", format = "double" };
break;
case "System.Byte":
case "System.SByte":
schema = new Schema { type = "string", format = "byte" };
break;
case "System.Boolean":
schema = new Schema { type = "boolean" };
break;
case "System.DateTime":
case "System.DateTimeOffset":
schema = new Schema { type = "string", format = "date-time" };
break;
default:
schema = new Schema { type = "string" };
break;
}
schema.WithValidationProperties(primitiveContract);
return schema;
}