Exemplo n.º 1
0
 /// <summary>Initializes a new instance of the <see cref="OasXMsEnumExtension" /> class.</summary>
 /// <param name="enumType">Type of the enum.</param>
 /// <param name="commentDocs">The comment docs.</param>
 /// <param name="namingPolicy">The naming policy.</param>
 /// <param name="enumModeling">The enum modeling.</param>
 public OasXMsEnumExtension(
     Type enumType,
     IList <XDocument> commentDocs,
     JsonNamingPolicy namingPolicy,
     OasEnumModeling enumModeling = OasEnumModeling.AsString)
 {
     this.enumType     = enumType;
     this.commentDocs  = commentDocs;
     this.enumModeling = enumModeling;
     this.namingPolicy = namingPolicy;
 }
Exemplo n.º 2
0
        internal static string GetOpenApiSchemaType(Type type, OasEnumModeling enumModeling = OasEnumModeling.AsString)
        {
            var rootType = TypeExtensions.GetRootType(type);

            if (TypeExtensions.IsDictionaryType(rootType))
            {
                return("object");
            }

            if (rootType == typeof(bool))
            {
                return("boolean");
            }

            if (TypeExtensions.IsIntegerType(rootType))
            {
                return("integer");
            }

            if (TypeExtensions.IsNumericType(rootType))
            {
                return("number");
            }

            if (TypeExtensions.IsEnumType(rootType) && enumModeling != OasEnumModeling.AsIntegerEnum)
            {
                return("string");
            }

            if (TypeExtensions.IsEnumType(rootType) && enumModeling == OasEnumModeling.AsIntegerEnum)
            {
                return("integer");
            }

            if (TypeExtensions.IsStringType(rootType) || TypeExtensions.IsDateType(rootType) || rootType == typeof(Guid) || rootType == typeof(Uri))
            {
                return("string");
            }

            if (typeof(IEnumerable).IsAssignableFrom(rootType))
            {
                return("array");
            }

            return("object");
        }