Skip to content

Validation Generator: enforce model metadata attributes and documentation #959

Description

@ooples

Context

Child issue of #956 (Epic: Model Metadata Attributes & Source Generator Infrastructure)

Depends on: #957 (attributes must exist first)

Task

Create a Roslyn incremental source generator in AiDotNet.Generators that validates all model classes have proper metadata attributes and documentation at compile time.

Validations to Implement

Required Attributes (Compile Error)

For every non-abstract class that inherits from a model base type or implements a model interface:

  • [ModelDomain] - at least one domain must be specified
  • [ModelCategory] - exactly one category
  • [ModelTask] - at least one task
  • [ModelComplexity] - exactly one complexity level
  • [ModelInput] - exactly one input/output type declaration

Emit diagnostic: AIDN001: Model class '{ClassName}' is missing required attribute '[{AttributeName}]'

XML Documentation (Compile Warning)

  • Missing <summary> tag: AIDN010: Model class '{ClassName}' is missing XML doc summary
  • Missing <remarks> with "For Beginners" content: AIDN011: Model class '{ClassName}' is missing beginner-friendly remarks
  • Missing <example> block: AIDN012: Model class '{ClassName}' is missing usage example
  • Public methods without <summary>: AIDN013: Public method '{MethodName}' on '{ClassName}' is missing XML doc
  • Constructor parameters without <param>: AIDN014: Parameter '{ParamName}' on '{ClassName}' constructor is missing doc

Semantic Validation (Compile Warning)

  • [ModelPaper] URL validation: AIDN020: ModelPaper URL '{Url}' is not well-formed (must start with https://)
  • Domain/Task consistency: AIDN021: Model '{ClassName}' has domain '{Domain}' but no related task

Model Base Types to Scan For

The generator should detect classes that inherit from or implement:

  • NeuralNetworkBase<T>
  • IFullModel<T, TInput, TOutput>
  • IModel<TInput, TOutput, TMetadata>
  • IClassifier<T>
  • ISyntheticTabularGenerator<T>
  • AgentBase<T>
  • SyntheticTabularGeneratorBase<T>
  • CausalModelBase<T>
  • GaussianProcessBase<T>
  • Other model base types discovered during implementation

Technical Requirements

  • Use IIncrementalGenerator (not ISourceGenerator) for performance
  • Use syntax-first filtering (check for class declarations with base types) before semantic analysis
  • Diagnostics should have proper severity (Error for missing attributes, Warning for missing docs)
  • Must work with both net10.0 and net471 targets
  • Should not significantly increase build time (< 2 seconds added)

Acceptance Criteria

  • Generator discovers all model classes via base type/interface detection
  • Missing required attributes produce compile errors
  • Missing documentation produces compile warnings
  • Paper URL validation works
  • Domain/Task consistency check works
  • Build time impact is < 2 seconds
  • Generator itself has unit tests

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions