Skip to content

Commit

Permalink
Merge pull request #9551 from swagger-api/fix-generate-options
Browse files Browse the repository at this point in the history
ref #9540 - fix generate option 3.0.0
  • Loading branch information
frantuma committed Jul 9, 2019
2 parents fe1f048 + c2ed4d6 commit 74d9afe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,14 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String EXCLUDE_TESTS_DESC = "Specifies that no tests are to be generated.";

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

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

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

public static final String GENERATE_MODEL_TESTS = "generateModelTests";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,23 @@ private String getScheme() {
private void configureGeneratorProperties() {
// allows generating only models by specifying a CSV of models to generate, or empty for all
// NOTE: Boolean.TRUE is required below rather than `true` because of JVM boxing constraints and type inference.
generateApis = System.getProperty(CodegenConstants.APIS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.APIS, null);
generateModels = System.getProperty(CodegenConstants.MODELS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODELS, null);
generateSupportingFiles = System.getProperty(CodegenConstants.SUPPORTING_FILES) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.SUPPORTING_FILES, null);

if (System.getProperty(CodegenConstants.GENERATE_APIS) != null) {
generateApis = Boolean.valueOf(System.getProperty(CodegenConstants.GENERATE_APIS));
} else {
generateApis = System.getProperty(CodegenConstants.APIS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.APIS, null);
}
if (System.getProperty(CodegenConstants.GENERATE_MODELS) != null) {
generateModels = Boolean.valueOf(System.getProperty(CodegenConstants.GENERATE_MODELS));
} else {
generateModels = System.getProperty(CodegenConstants.MODELS) != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODELS, null);
}
String supportingFilesProperty = System.getProperty(CodegenConstants.SUPPORTING_FILES);
if (((supportingFilesProperty != null) && supportingFilesProperty.equalsIgnoreCase("false"))) {
generateSupportingFiles = false;
} else {
generateSupportingFiles = supportingFilesProperty != null ? Boolean.TRUE : getGeneratorPropertyDefaultSwitch(CodegenConstants.SUPPORTING_FILES, null);
}

if (generateApis == null && generateModels == null && generateSupportingFiles == null) {
// no specifics are set, generate everything
Expand Down Expand Up @@ -568,7 +582,10 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
}
Set<String> supportingFilesToGenerate = null;
String supportingFiles = System.getProperty(CodegenConstants.SUPPORTING_FILES);
if (supportingFiles != null && !supportingFiles.isEmpty()) {
boolean generateAll = false;
if (supportingFiles != null && supportingFiles.equalsIgnoreCase("true")) {
generateAll = true;
} else if (supportingFiles != null && !supportingFiles.isEmpty()) {
supportingFilesToGenerate = new HashSet<>(Arrays.asList(supportingFiles.split(",")));
}

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

boolean shouldGenerate = true;
if(supportingFilesToGenerate != null && !supportingFilesToGenerate.isEmpty()) {
if(!generateAll && supportingFilesToGenerate != null && !supportingFilesToGenerate.isEmpty()) {
shouldGenerate = supportingFilesToGenerate.contains(support.destinationFilename);
}
if (!shouldGenerate){
Expand Down

0 comments on commit 74d9afe

Please sign in to comment.