Skip to content

Commit 74d9afe

Browse files
authored
Merge pull request #9551 from swagger-api/fix-generate-options
ref #9540 - fix generate option 3.0.0
2 parents fe1f048 + c2ed4d6 commit 74d9afe

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/CodegenConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,14 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
198198
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";
199199

200200
// Not user-configurable. System provided for use in templates.
201+
public static final String GENERATE_APIS = "generateApis";
201202
public static final String GENERATE_API_DOCS = "generateApiDocs";
202203

203204
public static final String GENERATE_API_TESTS = "generateApiTests";
204205
public static final String GENERATE_API_TESTS_DESC = "Specifies that api tests are to be generated.";
205206

206207
// Not user-configurable. System provided for use in templates.
208+
public static final String GENERATE_MODELS = "generateModels";
207209
public static final String GENERATE_MODEL_DOCS = "generateModelDocs";
208210

209211
public static final String GENERATE_MODEL_TESTS = "generateModelTests";

modules/swagger-codegen/src/main/java/io/swagger/codegen/v3/DefaultGenerator.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,23 @@ private String getScheme() {
136136
private void configureGeneratorProperties() {
137137
// allows generating only models by specifying a CSV of models to generate, or empty for all
138138
// NOTE: Boolean.TRUE is required below rather than `true` because of JVM boxing constraints and type inference.
139-
generateApis = System.getProperty(CodegenConstants.APIS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.APIS, null);
140-
generateModels = System.getProperty(CodegenConstants.MODELS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODELS, null);
141-
generateSupportingFiles = System.getProperty(CodegenConstants.SUPPORTING_FILES) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.SUPPORTING_FILES, null);
139+
140+
if (System.getProperty(CodegenConstants.GENERATE_APIS) != null) {
141+
generateApis = Boolean.valueOf(System.getProperty(CodegenConstants.GENERATE_APIS));
142+
} else {
143+
generateApis = System.getProperty(CodegenConstants.APIS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.APIS, null);
144+
}
145+
if (System.getProperty(CodegenConstants.GENERATE_MODELS) != null) {
146+
generateModels = Boolean.valueOf(System.getProperty(CodegenConstants.GENERATE_MODELS));
147+
} else {
148+
generateModels = System.getProperty(CodegenConstants.MODELS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODELS, null);
149+
}
150+
String supportingFilesProperty = System.getProperty(CodegenConstants.SUPPORTING_FILES);
151+
if (((supportingFilesProperty != null) && supportingFilesProperty.equalsIgnoreCase("false"))) {
152+
generateSupportingFiles = false;
153+
} else {
154+
generateSupportingFiles = supportingFilesProperty != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.SUPPORTING_FILES, null);
155+
}
142156

143157
if (generateApis == null && generateModels == null && generateSupportingFiles == null) {
144158
// no specifics are set, generate everything
@@ -568,7 +582,10 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
568582
}
569583
Set<String> supportingFilesToGenerate = null;
570584
String supportingFiles = System.getProperty(CodegenConstants.SUPPORTING_FILES);
571-
if (supportingFiles != null && !supportingFiles.isEmpty()) {
585+
boolean generateAll = false;
586+
if (supportingFiles != null && supportingFiles.equalsIgnoreCase("true")) {
587+
generateAll = true;
588+
} else if (supportingFiles != null && !supportingFiles.isEmpty()) {
572589
supportingFilesToGenerate = new HashSet<>(Arrays.asList(supportingFiles.split(",")));
573590
}
574591

@@ -595,7 +612,7 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
595612
}
596613

597614
boolean shouldGenerate = true;
598-
if(supportingFilesToGenerate != null && !supportingFilesToGenerate.isEmpty()) {
615+
if(!generateAll && supportingFilesToGenerate != null && !supportingFilesToGenerate.isEmpty()) {
599616
shouldGenerate = supportingFilesToGenerate.contains(support.destinationFilename);
600617
}
601618
if (!shouldGenerate){

0 commit comments

Comments
 (0)