Skip to content

Commit ebf72a3

Browse files
authored
adds support for x-pattern-message in kotlin-spring generator (#19134)
* adds support for x-pattern-message for patterns in kotlin-spring generator as known in java spring generator * updates doc kotlin-spring
1 parent 47abf82 commit ebf72a3

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/generators/kotlin-spring.md

+7
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ These options may be applied as additional-properties (cli) or configOptions (pl
5757
|useSwaggerUI|Open the OpenApi specification in swagger-ui. Will also import and configure needed dependencies| |true|
5858
|useTags|Whether to use tags for creating interface and controller class names| |false|
5959

60+
## SUPPORTED VENDOR EXTENSIONS
61+
62+
| Extension name | Description | Applicable for | Default value |
63+
| -------------- | ----------- | -------------- | ------------- |
64+
|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
65+
66+
6067
## IMPORT MAPPING
6168

6269
| Type/Alias | Imports |

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/KotlinSpringServerCodegen.java

+8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.openapitools.codegen.CodegenResponse;
3333
import org.openapitools.codegen.CodegenType;
3434
import org.openapitools.codegen.SupportingFile;
35+
import org.openapitools.codegen.VendorExtension;
3536
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
3637
import org.openapitools.codegen.languages.features.DocumentationProviderFeatures;
3738
import org.openapitools.codegen.languages.features.SwaggerUIFeatures;
@@ -982,4 +983,11 @@ public void setRequestMappingMode(RequestMappingMode requestMappingMode) {
982983
this.requestMappingMode = requestMappingMode;
983984
}
984985

986+
@Override
987+
public List<VendorExtension> getSupportedVendorExtensions() {
988+
List<VendorExtension> extensions = super.getSupportedVendorExtensions();
989+
extensions.add(VendorExtension.X_PATTERN_MESSAGE);
990+
return extensions;
991+
}
992+
985993
}

modules/openapi-generator/src/main/resources/kotlin-spring/beanValidationModel.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ format: email
44
@get:Email{{/isEmail}}{{!
55
pattern set
66
}}{{#pattern}}
7-
@get:Pattern(regexp="{{{.}}}"){{/pattern}}{{!
7+
@get:Pattern(regexp="{{{pattern}}}"{{#vendorExtensions.x-pattern-message}}, message="{{vendorExtensions.x-pattern-message}}"{{/vendorExtensions.x-pattern-message}}){{/pattern}}{{!
88
minLength && maxLength set
99
}}{{#minLength}}{{#maxLength}}
1010
@get:Size(min={{minLength}},max={{maxLength}}){{/maxLength}}{{/minLength}}{{!

0 commit comments

Comments
 (0)