Skip to content

Commit 7d67448

Browse files
author
andrewwilsonnew
committed
adding validation
1 parent 9663da7 commit 7d67448

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

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

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.openapitools.codegen.CodegenOperation;
66
import org.openapitools.codegen.CodegenType;
77
import org.openapitools.codegen.SupportingFile;
8+
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
89
import org.openapitools.codegen.meta.GeneratorMetadata;
910
import org.openapitools.codegen.meta.Stability;
1011
import org.openapitools.codegen.meta.features.DocumentationFeature;
@@ -28,17 +29,19 @@
2829

2930
import static org.openapitools.codegen.utils.StringUtils.camelize;
3031

31-
public class KotlinMiskServerCodegen extends AbstractKotlinCodegen {
32+
public class KotlinMiskServerCodegen extends AbstractKotlinCodegen implements BeanValidationFeatures {
33+
34+
private static final Logger LOGGER = LoggerFactory.getLogger(KotlinMiskServerCodegen.class);
35+
36+
private static final String ROOT_PACKAGE = "rootPackage";
37+
private static final String MODULE_CLASS_NAME = "moduleClassName";
38+
39+
private boolean useBeanValidation = true;
3240

3341
protected String rootPackage = "org.openapitools.server.api";
3442
protected String apiVersion = "1.0.0-SNAPSHOT";
35-
@Setter protected String moduleClassName = "OpenApiModule";
3643

37-
public static final String ROOT_PACKAGE = "rootPackage";
38-
public static final String PROJECT_NAME = "projectName";
39-
public static final String MODULE_CLASS_NAME = "moduleClassName";
40-
41-
final Logger LOGGER = LoggerFactory.getLogger(KotlinMiskServerCodegen.class);
44+
@Setter protected String moduleClassName = "OpenApiModule";
4245

4346
@Override
4447
public CodegenType getTag() {
@@ -58,6 +61,8 @@ public String getHelp() {
5861
public KotlinMiskServerCodegen() {
5962
super();
6063

64+
addSwitch(USE_BEANVALIDATION, "Use BeanValidation API annotations to validate data types", useBeanValidation);
65+
6166
modifyFeatureSet(features -> features
6267
.includeDocumentationFeatures(DocumentationFeature.Readme)
6368
.wireFormatFeatures(EnumSet.of(WireFormatFeature.PROTOBUF))
@@ -129,6 +134,11 @@ public void processOpts() {
129134
}
130135
additionalProperties.put(MODULE_CLASS_NAME, moduleClassName);
131136

137+
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
138+
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
139+
}
140+
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
141+
132142
String apiModuleFolder = (sourceFolder + File.separator + apiPackage).replace(".", File.separator);
133143
String moduleFileName = moduleClassName + ".kt";
134144
supportingFiles.add(new SupportingFile("miskModule.mustache", apiModuleFolder, moduleFileName));
@@ -160,8 +170,17 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
160170
return objs;
161171
}
162172

173+
@Override
174+
public void setUseBeanValidation(boolean useBeanValidation) {
175+
this.useBeanValidation = useBeanValidation;
176+
}
177+
178+
public boolean getUseBeanValidation() {
179+
return this.useBeanValidation;
180+
}
181+
163182
private String mapMediaType(String mediaType) {
164-
return MEDIA_MAPPING.getOrDefault(mediaType, "MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> " + mediaType + "*/ ");
183+
return MEDIA_MAPPING.getOrDefault(mediaType, "MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> " + mediaType + " */ ");
165184
}
166185

167186
private final static Map<String, String> MEDIA_MAPPING = getMappings();

samples/server/petstore/kotlin-misk/docs/PetApi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,6 @@ Name | Type | Description | Notes
395395

396396
### HTTP request headers
397397

398-
- **Content-Type**:
398+
- **Content-Type**: MediaTypes.APPLICATION_OCTETSTREAM /* unknown -> multipart/form-data */
399399
- **Accept**: MediaTypes.APPLICATION_JSON
400400

0 commit comments

Comments
 (0)