Пример #1
0
        /// <summary>
        /// 获取 Body 示例
        /// </summary>
        /// <param name="apiSchema"></param>
        /// <returns></returns>
        private object GetExapmple(OpenApiSchema apiSchema)
        {
            object exapmle = null;

            if (apiSchema.IsObject(Schemas))
            {
                var key = apiSchema.Reference.Id;
                exapmle = GetExapmple(key);
            }
            else if (apiSchema.IsArray())
            {
                if (apiSchema.IsBaseTypeArray())
                {
                    exapmle = new[] { GetDefaultValue(apiSchema.Items.Type) }
                }
                ;
                else
                {
                    exapmle = new[] { GetExapmple(apiSchema.Items.Reference.Id) }
                };
            }
            else if (apiSchema.IsEnum(Schemas))
            {
                var key = apiSchema.Reference.Id;
                exapmle = GetEnum(key).Select(x => x.Value).Min();
            }
            else
            {
                exapmle = GetDefaultValue(apiSchema.Type);
            }
            return(exapmle);
        }