in src/Microsoft.OpenApi.OData.Reader/Generator/OpenApiExampleGenerator.cs [114:187]
private static IOpenApiAny GetTypeNameForExample(IEdmTypeReference edmTypeReference)
{
switch (edmTypeReference.TypeKind())
{
case EdmTypeKind.Primitive:
if (edmTypeReference.IsBinary())
{
// return new OpenApiBinary(new byte[] { 0x00 }); issue on binary writing
return new OpenApiString(Convert.ToBase64String(new byte[] { 0x00 }));
}
else if (edmTypeReference.IsBoolean())
{
return new OpenApiBoolean(true);
}
else if (edmTypeReference.IsByte())
{
return new OpenApiByte(0x00);
}
else if (edmTypeReference.IsDate())
{
return new OpenApiDate(DateTime.MinValue);
}
else if (edmTypeReference.IsDateTimeOffset())
{
return new OpenApiDateTime(DateTimeOffset.MinValue);
}
else if (edmTypeReference.IsDecimal() || edmTypeReference.IsDouble())
{
return new OpenApiDouble(0D);
}
else if (edmTypeReference.IsFloating())
{
return new OpenApiFloat(0F);
}
else if (edmTypeReference.IsGuid())
{
return new OpenApiString(Guid.Empty.ToString());
}
else if (edmTypeReference.IsInt16() || edmTypeReference.IsInt32())
{
return new OpenApiInteger(0);
}
else if (edmTypeReference.IsInt64())
{
return new OpenApiLong(0L);
}
else
{
return new OpenApiString(edmTypeReference.AsPrimitive().PrimitiveDefinition().Name);
}
case EdmTypeKind.Entity:
case EdmTypeKind.Complex:
case EdmTypeKind.Enum:
OpenApiObject obj = new OpenApiObject();
obj["@odata.type"] = new OpenApiString(edmTypeReference.FullName());
return obj;
case EdmTypeKind.Collection:
OpenApiArray array = new OpenApiArray();
IEdmTypeReference elementType = edmTypeReference.AsCollection().ElementType();
array.Add(GetTypeNameForExample(elementType));
return array;
case EdmTypeKind.TypeDefinition:
var typedef = edmTypeReference.AsTypeDefinition().TypeDefinition();
return GetTypeNameForExample(new EdmPrimitiveTypeReference(typedef.UnderlyingType, edmTypeReference.IsNullable));
case EdmTypeKind.Untyped:
case EdmTypeKind.EntityReference:
default:
throw new OpenApiException("Not support for the type kind " + edmTypeReference.TypeKind());
}
}