/// <inheritdoc />
        public void Apply(OpenApiSchema schema, SchemaFilterContext context)
        {
            if (schema == null)
            {
                throw new ArgumentNullException(nameof(schema));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Nothing is required
            schema.Required.Clear();

            // Could be nullable type, make sure to get the right one
            Type nonNullableType = context.Type.IsConstructedGenericType
                                ? context.Type.GenericTypeArguments.First()
                                : context.Type;

            if (nonNullableType != context.Type &&
                !context.Type.GetInterfaces().Any(x => x == typeof(IEnumerable)))
            {
                schema.Nullable = true;
            }

            if (!schema.Enum?.Any() ?? false)
            {
                return;
            }

            OpenApiEnumVarNamesExtension.Apply(schema, nonNullableType);
        }
Beispiel #2
0
        /// <inheritdoc />
        public void Apply(OpenApiSchema schema, SchemaFilterContext context)
        {
            if (schema == null)
            {
                throw new ArgumentNullException(nameof(schema));
            }
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Nothing is required
            schema.Required.Clear();

            if (!schema.Enum?.Any() ?? false)
            {
                return;
            }

            // Could be nullable type, make sure to get the right one
            Type enumType = context.Type.IsConstructedGenericType
                                ? context.Type.GenericTypeArguments.First()
                                : context.Type;

            OpenApiEnumVarNamesExtension.Apply(schema, enumType);
        }