public static IArgumentDescriptor ID( this IArgumentDescriptor descriptor, NameString typeName = default) { if (descriptor is null) { throw new ArgumentNullException(nameof(descriptor)); } descriptor.Extend().OnBeforeCreate(RewriteInputFieldType); descriptor.Extend().OnBeforeCompletion( (c, d) => AddSerializerToInputField(c, d, typeName)); return(descriptor); }
/// <summary> /// Instructs FairyBread to add the given validator/s to the argument. /// </summary> public static IArgumentDescriptor ValidateWith( this IArgumentDescriptor descriptor, params Type[] validatorTypes) { descriptor.Extend().OnBeforeNaming((completionContext, argDef) => { if (!argDef.ContextData.TryGetValue(WellKnownContextData.ExplicitValidatorTypes, out var explicitValidatorTypesRaw) || explicitValidatorTypesRaw is not List <Type> explicitValidatorTypes) { argDef.ContextData[WellKnownContextData.ExplicitValidatorTypes] = new List <Type>(validatorTypes.Distinct()); return; } foreach (var validatorType in validatorTypes) { if (!explicitValidatorTypes.Contains(validatorType)) { explicitValidatorTypes.Add(validatorType); } } }); return(descriptor); }
/// <summary> /// Skip object validation. /// </summary> public static IArgumentDescriptor SkipValidation( this IArgumentDescriptor descriptor) { descriptor.Extend().OnBeforeCreate( d => d.ContextData[ArgumentValidationKeys.Skip] = true); return(descriptor); }
/// <summary> /// Validate the specified properties only. /// This will inspect all rule sets in search for the specified property names. /// </summary> public static IArgumentDescriptor ValidateProperties( this IArgumentDescriptor descriptor, params string[] properties) { descriptor.Extend().OnBeforeCreate( d => d.ContextData[ArgumentValidationKeys.Properties] = properties); return(descriptor); }
/// <summary> /// Validate the specified rule sets only. /// By default, only unspecified "default" rule set is being validated. /// To validate all rule sets pass "*". /// </summary> public static IArgumentDescriptor ValidateRuleSets( this IArgumentDescriptor descriptor, params string[] ruleSets) { descriptor.Extend().OnBeforeCreate( d => d.ContextData[ArgumentValidationKeys.RuleSets] = ruleSets); return(descriptor); }
public static IArgumentDescriptor UseValidation( this IArgumentDescriptor descriptor) { descriptor .Extend() .OnBeforeCreate(definition => definition.ContextData.Add(ValidateAttribute.ValidateContextDataKey, true)); return(descriptor); }
/// <summary> /// Instructs FairyBread to not run any validation for this argument. /// </summary> public static IArgumentDescriptor DontValidate( this IArgumentDescriptor descriptor) { descriptor.Extend().OnBeforeNaming((completionContext, argDef) => { argDef.ContextData[WellKnownContextData.DontValidate] = true; }); return(descriptor); }
public static IArgumentDescriptor Input( this IArgumentDescriptor descriptor, string argumentName = "input", string?typeName = null) { ExtensionData contextData = descriptor.Extend().Definition.ContextData; contextData[InputContextData.Input] = new InputContextData(typeName, argumentName); return(descriptor); }
/// <summary> /// Configures argument for validation /// </summary> public static IArgumentDescriptor UseFluentValidation( this IArgumentDescriptor argumentDescriptor, Action <ArgumentValidationBuilder>?configure = null) { argumentDescriptor.Extend().OnBeforeCreate(argumentDefinition => { var options = argumentDefinition.ContextData.GetOrCreateArgumentOptions(); configure?.Invoke(new DefaultArgumentValidationBuilder(options)); }); return(argumentDescriptor); }