Skip to content

Commit

Permalink
adds support for x-pattern-message in kotlin-spring generator (OpenAP…
Browse files Browse the repository at this point in the history
…ITools#19134)

* adds support for x-pattern-message for patterns in kotlin-spring generator as known in java spring generator

* updates doc kotlin-spring
  • Loading branch information
orolhawion authored Jul 18, 2024
1 parent 47abf82 commit ebf72a3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/generators/kotlin-spring.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
|useTags|Whether to use tags for creating interface and controller class names| |false|

## SUPPORTED VENDOR EXTENSIONS

| Extension name | Description | Applicable for | Default value |
| -------------- | ----------- | -------------- | ------------- |
|x-pattern-message|Add this property whenever you need to customize the invalidation error message for the regex pattern of a variable|FIELD, OPERATION_PARAMETER|null


## IMPORT MAPPING

| Type/Alias | Imports |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.openapitools.codegen.CodegenResponse;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.VendorExtension;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures;
import org.openapitools.codegen.languages.features.SwaggerUIFeatures;
Expand Down Expand Up @@ -982,4 +983,11 @@ public void setRequestMappingMode(RequestMappingMode requestMappingMode) {
this.requestMappingMode = requestMappingMode;
}

@Override
public List<VendorExtension> getSupportedVendorExtensions() {
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
extensions.add(VendorExtension.X_PATTERN_MESSAGE);
return extensions;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ format: email
@get:Email{{/isEmail}}{{!
pattern set
}}{{#pattern}}
@get:Pattern(regexp="{{{.}}}"){{/pattern}}{{!
@get:Pattern(regexp="{{{pattern}}}"{{#vendorExtensions.x-pattern-message}}, message="{{vendorExtensions.x-pattern-message}}"{{/vendorExtensions.x-pattern-message}}){{/pattern}}{{!
minLength && maxLength set
}}{{#minLength}}{{#maxLength}}
@get:Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{!
Expand Down

0 comments on commit ebf72a3

Please sign in to comment.