Added Pattern attribute support for string domain primitives.#43
Merged
Added Pattern attribute support for string domain primitives.#43
Conversation
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.
Contributor
There was a problem hiding this comment.
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.Patternand (b) optionally validate viaRegex.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. |
src/AltaSoft.DomainPrimitives.Generator/Helpers/MethodGeneratorHelper.cs
Outdated
Show resolved
Hide resolved
tests/AltaSoft.DomainPrimitives.Generator.Tests/PrimitivesWithPatternAttributeTests.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…rHelper.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.