Table of Contents

Class CloudflareApiOptionsValidator

Namespace
Cloudflare.NET.Core.Validation
Assembly
Cloudflare.NET.dll

Validates CloudflareApiOptions to ensure all required configuration is present and valid. This validator is invoked at startup when using ValidateOnStart(), providing immediate feedback for configuration issues rather than waiting for the first API call to fail.

public class CloudflareApiOptionsValidator : IValidateOptions<CloudflareApiOptions>
Inheritance
CloudflareApiOptionsValidator
Implements
Inherited Members

Remarks

This validator checks that the API token is provided, which is required for authentication with the Cloudflare API. Additional validation (such as AccountId for R2 or GraphQL URL for Analytics) is performed by package-specific validators.

The validation errors are designed to be clear and actionable, mentioning "Cloudflare" explicitly so developers can quickly identify the source of configuration issues.

When registered as IValidateOptions<TOptions>, this validator skips named options by default. Factories should use ValidateConfiguration(string?, CloudflareApiOptions, CloudflareValidationRequirements) directly for explicit validation of named client configurations with custom exception types.

Constructors

CloudflareApiOptionsValidator()

Initializes a new instance of the CloudflareApiOptionsValidator class with default validation requirements (ApiToken required) and default skip behavior for named options.

public CloudflareApiOptionsValidator()

CloudflareApiOptionsValidator(CloudflareValidationRequirements)

Initializes a new instance of the CloudflareApiOptionsValidator class with specific validation requirements and default skip behavior for named options.

public CloudflareApiOptionsValidator(CloudflareValidationRequirements requirements)

Parameters

requirements CloudflareValidationRequirements

The validation requirements to apply.

CloudflareApiOptionsValidator(CloudflareValidationRequirements, bool)

Initializes a new instance of the CloudflareApiOptionsValidator class with specific validation requirements and explicit skip behavior control.

public CloudflareApiOptionsValidator(CloudflareValidationRequirements requirements, bool skipNamedOptions)

Parameters

requirements CloudflareValidationRequirements

The validation requirements to apply.

skipNamedOptions bool

If true, the validator returns Skip for named options (non-default names). Set to false when performing explicit validation in factories.

Methods

Validate(string?, CloudflareApiOptions)

Validates a specific named options instance (or all when name is null).

public ValidateOptionsResult Validate(string? name, CloudflareApiOptions options)

Parameters

name string

The name of the options instance being validated.

options CloudflareApiOptions

The options instance.

Returns

ValidateOptionsResult

The ValidateOptionsResult result.

ValidateConfiguration(string?, CloudflareApiOptions, CloudflareValidationRequirements)

Validates the specified CloudflareApiOptions against the given requirements. This method is intended for use by factories to perform explicit validation with proper error messages that include the client name.

public static ValidateOptionsResult ValidateConfiguration(string? name, CloudflareApiOptions options, CloudflareValidationRequirements requirements)

Parameters

name string

The options name. For named clients, this should be the client name to include in error messages. For default clients, pass null or DefaultName.

options CloudflareApiOptions

The options to validate.

requirements CloudflareValidationRequirements

The validation requirements to apply.

Returns

ValidateOptionsResult

A ValidateOptionsResult indicating success or failure with error messages.