Module: pattern-support¶
pattern-support connects the standalone pattern-value module to the core generation engine. It is what turns "this string schema has a pattern" into both a valid example value (a string matching the regex) and a negative test case (a string that does not match).
Most users never touch this module: distribution-bundle registers it by default, so the CLI and Gradle plugin have pattern-aware behavior out of the box. Wire it manually only when embedding core directly.
What it contributes¶
| Contribution | Type | Effect |
|---|---|---|
Schema value provider id pattern | PatternValueProvider from pattern-value | Generates valid example values for string schemas with a pattern |
| Negative rule | InvalidPatternSchemaValidationRule (rule name "Invalid Pattern") | Generates a non-matching string per patterned schema — see the rules catalog |
| Settings extractor | PatternModuleSettingsExtractor (settings key patternGeneration) | Parses the testGenerationSettings.patternGeneration block into PatternGenerationOptions |
Depends on / used by¶
- Depends on:
core(module and rule SPIs) andpattern-value(the actual regex generation) - Used by:
distribution-bundle—DistributionDefaults.modules()registersPatternSupportModule,DistributionDefaults.extractors()registers the settings extractor, and the default provider order insertspatternbeforeplain-string
Installation¶
Only needed for direct embedding — CLI and Gradle plugin users get it transitively:
Key types¶
PatternSupportModule— aTestGenerationModulewith idpattern-support. TakesPatternGenerationOptionsas an optional constructor argument; onePatternValueGeneratoris shared by the value provider and the rule, so both honor the same options.PatternModuleSettingsExtractor— a KotlinobjectimplementingModuleSettingsExtractor. ItssettingsKeyispatternGeneration; a non-map value under that key fails fast with aConfigurationException.InvalidPatternSchemaValidationRule— aSimpleSchemaValidationRulethat applies to string schemas with a non-nullpattern. When the underlying library cannot produce a non-matching string (see pattern-value limitations), the rule logs and skips that schema instead of failing.
Configure pattern generation¶
Configuration is owned by Distribution settings — patternGeneration; the options themselves (defaultMinLength, spaceChars, anyPrintableChars) are documented in pattern-value. Example:
Wire the module when embedding core¶
The settings extractor runs during option resolution and stores the parsed options under the module settings key; the module is then constructed with those options:
import art.galushko.openapi.testgen.config.TestGenerationEngine
import art.galushko.openapi.testgen.config.TestGeneratorExecutionOptionsFactory
import art.galushko.openapi.testgen.config.TestGeneratorOverrides
import art.galushko.openapi.testgen.pattern.support.PatternModuleSettingsExtractor
import art.galushko.openapi.testgen.pattern.support.PatternSupportModule
import art.galushko.openapi.testgen.pattern.value.PatternGenerationOptions
import java.nio.file.Path
val options = TestGeneratorExecutionOptionsFactory.fromConfig(
config = null,
overrides = TestGeneratorOverrides(
specFile = "openapi.yaml",
outputDir = Path.of("build/generated"),
generatorId = "test-suite-writer",
testGenerationSettings = mapOf(
"patternGeneration" to mapOf("defaultMinLength" to 10),
),
),
moduleExtractors = listOf(PatternModuleSettingsExtractor),
)
val patternOptions = options.moduleSettings
.get<PatternGenerationOptions>(PatternModuleSettingsExtractor.SETTINGS_KEY)
?: PatternGenerationOptions()
val report = TestGenerationEngine.generateReport(
options,
modules = listOf(PatternSupportModule(patternOptions)),
)
This mirrors exactly what TestGenerationRunner.withDefaults() does in distribution-bundle.
Testing¶
API reference¶
- Dokka API reference:
docs/api/pattern-support/index.html
Related docs¶
- Modules: pattern-value — the underlying generator and its options
- Modules: Distribution-bundle — default wiring
- Reference: Distribution settings — patternGeneration
- Reference: Rules catalog — pattern module rules
- Reference: SPI — SchemaValueProvider