Skip to content

feat: Emit format-based validation attributes for email and phone - #151

Open
nikcio wants to merge 1 commit into
mainfrom
feature/additional-string-formats
Open

feat: Emit format-based validation attributes for email and phone#151
nikcio wants to merge 1 commit into
mainfrom
feature/additional-string-formats

Conversation

@nikcio

@nikcio nikcio commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Changes

Emit for and for when is enabled. These are standard attributes used by ASP.NET Core model validation.

Example

User:
  type: object
  properties:
    email: { type: string, format: email }   -> [EmailAddress]
    phone: { type: string, format: phone }   -> [Phone]

Implementation

  • Add helper to map string formats to validation attributes
  • Update to detect format-based attributes so is emitted
  • Suppressed when is passed (existing option)
  • Other formats (nikcio-desktop, , , , ) remain plain — no standard validation attributes fit without adding dependencies

Testing

All 276 tests pass (266 existing + 5 new). New tests include compilation with .

Emit [EmailAddress] for format: email and [Phone] for format: phone
when EmitValidationAttributes is enabled. These are standard
System.ComponentModel.DataAnnotations attributes used by ASP.NET Core
model validation.

- Add GetFormatValidationAttribute helper to map formats to attributes
- Update HasValidationConstraints to detect format-based attributes
- Suppress with --no-validation-attributes flag (existing option)
- Add 5 tests: email, phone, opt-out, unknown format, compilation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant