Skip to content

Added Pattern attribute support for string domain primitives.#43

Merged
temonk merged 5 commits intomainfrom
bugfix/openapiAndRegexPatterns
Mar 4, 2026
Merged

Added Pattern attribute support for string domain primitives.#43
temonk merged 5 commits intomainfrom
bugfix/openapiAndRegexPatterns

Conversation

@temonk
Copy link
Contributor

@temonk temonk commented Mar 4, 2026

Generated OpenAPI schemas now include pattern, and optional runtime regex validation was implemented. Added related tests and error handling for pattern mismatches. Bumped version to 8.0.1.

Generated OpenAPI schemas now include pattern, and optional runtime regex validation was implemented. Added related tests and error handling for pattern mismatches. Bumped version to 8.0.1.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class PatternAttribute support for string domain primitives so the source generator can emit OpenAPI pattern constraints and (optionally) generate runtime regex validation.

Changes:

  • Introduce PatternAttribute + InvalidDomainValueException.InvalidPatternException(...) to support pattern constraints and errors.
  • Extend the source generator to (a) emit OpenApiSchema.Pattern and (b) optionally validate via Regex.IsMatch(...) in generated constructor/TryCreate.
  • Add/adjust generator tests + snapshots and bump package version to 8.0.1.

Reviewed changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/AltaSoft.DomainPrimitives.UnitTests/TransformableTests/PatternBasedStringTests.cs Adds runtime behavior tests for a pattern-validated string primitive.
tests/AltaSoft.DomainPrimitives.UnitTests/TransformableTests/PatternBasedString.cs Adds a test domain primitive decorated with [Pattern(..., true)].
tests/AltaSoft.DomainPrimitives.Generator.Tests/TestHelper.cs Refactors helper to expose Compile(...) and uses file-scoped namespace.
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransformerGeneratesTransformerCall#OpenApiHelper.g.verified.cs Updates snapshot to include string length constraints in generated OpenAPI schema.
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndXmlSummary#StringWithLengthAndPatternTypeConverter.g.verified.cs Adds snapshot for new pattern+length test case (type converter).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndXmlSummary#StringWithLengthAndPatternJsonConverter.g.verified.cs Adds snapshot for new pattern+length test case (json converter).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndXmlSummary#StringWithLengthAndPattern.g.verified.cs Adds snapshot for generated primitive code (pattern present in OpenAPI helper for this case).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndXmlSummary#OpenApiHelper.g.verified.cs Adds snapshot verifying Pattern is emitted into OpenAPI schema.
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPatternWithValidation#StringWithLengthAndPatternTypeConverter.g.verified.cs Adds snapshot for validate=true pattern case (type converter).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPatternWithValidation#StringWithLengthAndPatternJsonConverter.g.verified.cs Adds snapshot for validate=true pattern case (json converter).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPatternWithValidation#StringWithLengthAndPattern.g.verified.cs Adds snapshot verifying runtime Regex.IsMatch(...) validation is generated when enabled.
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPatternWithValidation#OpenApiHelper.g.verified.cs Adds snapshot verifying OpenAPI Pattern for validate=true case.
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPattern#StringWithLengthAndPatternTypeConverter.g.verified.cs Adds snapshot for validate=false pattern case (type converter).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPattern#StringWithLengthAndPatternJsonConverter.g.verified.cs Adds snapshot for validate=false pattern case (json converter).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPattern#StringWithLengthAndPattern.g.verified.cs Adds snapshot for validate=false pattern case (no runtime regex validation).
tests/AltaSoft.DomainPrimitives.Generator.Tests/Snapshots/DomainPrimitiveGeneratorTest.StringValue_WithTransStringLengthAndPattern#OpenApiHelper.g.verified.cs Adds snapshot verifying OpenAPI Pattern for validate=false case.
tests/AltaSoft.DomainPrimitives.Generator.Tests/PrimitivesWithPatternAttributeTests.cs Adds theory test intended to validate pattern handling across multiple regex strings.
tests/AltaSoft.DomainPrimitives.Generator.Tests/DomainPrimitiveGeneratorTest.cs Adds new generator tests for pattern + optional runtime validation.
src/AltaSoft.DomainPrimitives/PatternAttribute.cs Introduces the public PatternAttribute API.
src/AltaSoft.DomainPrimitives/InvalidDomainValueException.cs Adds InvalidPatternException(...) factory for pattern mismatch errors.
src/AltaSoft.DomainPrimitives.Generator/Models/GeneratorData.cs Adds Pattern and ValidatePattern fields to carry pattern metadata through generation.
src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs Emits OpenApiSchema.Pattern and generates TryCreate pattern validation when enabled.
src/AltaSoft.DomainPrimitives.Generator/Helpers/Constants.cs Adds PatternAttributeFullName constant for attribute detection.
src/AltaSoft.DomainPrimitives.Generator/Executor.cs Detects PatternAttribute, injects constructor validation, and adds regex using when needed.
Examples/AltaSoft.DomainPrimitives.Demo/Customer.cs Updates demo model to include a RegularExpression annotation on the .NET string property.
Directory.Build.props Bumps version from 8.0.0 to 8.0.1.

temonk and others added 3 commits March 4, 2026 16:02
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rHelper.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 26 out of 26 changed files in this pull request and generated 2 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@temonk temonk merged commit 1c06339 into main Mar 4, 2026
1 check passed
@temonk temonk deleted the bugfix/openapiAndRegexPatterns branch March 4, 2026 12:20
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.

2 participants