Skip to content

Commit b5e8c67

Browse files
committed
Merge remote-tracking branch 'origin/3.0.0' into patch-5
2 parents 03e6f30 + c0af9de commit b5e8c67

File tree

155 files changed

+111
-14680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+111
-14680
lines changed

modules/swagger-codegen-cli/src/main/java/io/swagger/codegen/SwaggerCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public static void main(String[] args) {
9191
String language = CLIHelper.detectlanguage(args);
9292
if (StringUtils.isNotBlank(language)) {
9393
CodegenConfig config = CodegenConfigLoader.forName(language);
94-
codegenArguments = config.getLanguageArguments();
94+
codegenArguments = config.readLanguageArguments();
9595
if (codegenArguments != null && !codegenArguments.isEmpty()) {
9696
for (CodegenArgument codegenArgument : codegenArguments) {
9797
String[] arguments = CLIHelper.getArguments(codegenArgument);

modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConfig.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,9 @@ public interface CodegenConfig {
216216

217217
void addHandlebarHelpers(Handlebars handlebars);
218218

219+
List<CodegenArgument> readLanguageArguments();
220+
219221
List<CodegenArgument> getLanguageArguments();
220222

221-
void processArgumentsValues(List<CodegenArgument> codegenArguments);
223+
void setLanguageArguments(List<CodegenArgument> codegenArguments);
222224
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
304304
public static final String HAS_REFERENCE_EXT_NAME = PREFIX_HAS + "reference";
305305
public static final String HAS_HEADERS_EXT_NAME = PREFIX_HAS + "headers";
306306

307+
public static final String MODEL_DOCS_OPTION = "--model-docs";
308+
public static final String API_DOCS_OPTION = "--api-docs";
309+
public static final String MODEL_TESTS_OPTION = "--model-tests";
310+
public static final String API_TESTS_OPTION = "--api-tests";
311+
307312
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3164,13 +3164,18 @@ public void addHandlebarHelpers(Handlebars handlebars) {
31643164
handlebars.registerHelper(HasNotHelper.NAME, new HasNotHelper());
31653165
}
31663166

3167+
@Override
3168+
public List<CodegenArgument> readLanguageArguments() {
3169+
return null;
3170+
}
3171+
31673172
@Override
31683173
public List<CodegenArgument> getLanguageArguments() {
31693174
return null;
31703175
}
31713176

31723177
@Override
3173-
public void processArgumentsValues(List<CodegenArgument> codegenArguments){
3178+
public void setLanguageArguments(List<CodegenArgument> codegenArguments){
31743179
}
31753180

31763181
/**

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

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.LinkedHashSet;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Optional;
2223
import java.util.Set;
2324
import java.util.TreeMap;
2425
import java.util.TreeSet;
@@ -174,10 +175,15 @@ private void configureGeneratorProperties() {
174175
}
175176
// model/api tests and documentation options rely on parent generate options (api or model) and no other options.
176177
// They default to true in all scenarios and can only be marked false explicitly
177-
generateModelTests = System.getProperty(CodegenConstants.MODEL_TESTS) != null ? Boolean.valueOf(System.getProperty(CodegenConstants.MODEL_TESTS)) : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODEL_TESTS, true);
178-
generateModelDocumentation = System.getProperty(CodegenConstants.MODEL_DOCS) != null ? Boolean.valueOf(System.getProperty(CodegenConstants.MODEL_DOCS)) : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODEL_DOCS, true);
179-
generateApiTests = System.getProperty(CodegenConstants.API_TESTS) != null ? Boolean.valueOf(System.getProperty(CodegenConstants.API_TESTS)) : getGeneratorPropertyDefaultSwitch(CodegenConstants.API_TESTS, true);
180-
generateApiDocumentation = System.getProperty(CodegenConstants.API_DOCS) != null ? Boolean.valueOf(System.getProperty(CodegenConstants.API_DOCS)) : getGeneratorPropertyDefaultSwitch(CodegenConstants.API_DOCS, true);
178+
final Boolean generateModelTestsOption = getCustomOptionBooleanValue(CodegenConstants.MODEL_TESTS_OPTION);
179+
final Boolean generateModelDocsOption = getCustomOptionBooleanValue(CodegenConstants.MODEL_DOCS_OPTION);
180+
final Boolean generateAPITestsOption = getCustomOptionBooleanValue(CodegenConstants.API_TESTS_OPTION);
181+
final Boolean generateAPIDocsOption = getCustomOptionBooleanValue(CodegenConstants.API_DOCS_OPTION);
182+
183+
generateModelTests = generateModelTestsOption != null ? generateModelTestsOption : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODEL_TESTS, true);
184+
generateModelDocumentation = generateModelDocsOption != null ? generateModelDocsOption : getGeneratorPropertyDefaultSwitch(CodegenConstants.MODEL_DOCS, true);
185+
generateApiTests = generateAPITestsOption != null ? generateAPITestsOption : getGeneratorPropertyDefaultSwitch(CodegenConstants.API_TESTS, true);
186+
generateApiDocumentation = generateAPIDocsOption != null ? generateAPIDocsOption : getGeneratorPropertyDefaultSwitch(CodegenConstants.API_DOCS, true);
181187

182188
// Additional properties added for tests to exclude references in project related files
183189
config.additionalProperties().put(CodegenConstants.GENERATE_API_TESTS, generateApiTests);
@@ -317,12 +323,12 @@ private void generateModels(List<File> files, List<Object> allModels) {
317323
String modelNames = System.getProperty("models");
318324
Set<String> modelsToGenerate = null;
319325
if(modelNames != null && !modelNames.isEmpty()) {
320-
modelsToGenerate = new HashSet<String>(Arrays.asList(modelNames.split(",")));
326+
modelsToGenerate = new HashSet<>(Arrays.asList(modelNames.split(",")));
321327
}
322328

323329
Set<String> modelKeys = schemas.keySet();
324330
if(modelsToGenerate != null && !modelsToGenerate.isEmpty()) {
325-
Set<String> updatedKeys = new HashSet<String>();
331+
Set<String> updatedKeys = new HashSet<>();
326332
for(String m : modelKeys) {
327333
if(modelsToGenerate.contains(m)) {
328334
updatedKeys.add(m);
@@ -332,7 +338,7 @@ private void generateModels(List<File> files, List<Object> allModels) {
332338
}
333339

334340
// store all processed models
335-
Map<String,Object> allProcessedModels = new TreeMap<String, Object>(new Comparator<String>() {
341+
Map<String,Object> allProcessedModels = new TreeMap<>(new Comparator<String>() {
336342
@Override
337343
public int compare(String o1, String o2) {
338344
return ObjectUtils.compare(config.toModelName(o1), config.toModelName(o2));
@@ -422,7 +428,7 @@ private void generateApis(List<File> files, List<Object> allOperations, List<Obj
422428
apisToGenerate = new HashSet<String>(Arrays.asList(apiNames.split(",")));
423429
}
424430
if(apisToGenerate != null && !apisToGenerate.isEmpty()) {
425-
Map<String, List<CodegenOperation>> updatedPaths = new TreeMap<String, List<CodegenOperation>>();
431+
Map<String, List<CodegenOperation>> updatedPaths = new TreeMap<>();
426432
for(String m : paths.keySet()) {
427433
if(apisToGenerate.contains(m)) {
428434
updatedPaths.put(m, paths.get(m));
@@ -463,7 +469,7 @@ public int compare(CodegenOperation one, CodegenOperation another) {
463469
}
464470
operation.put("sortParamsByRequiredFlag", sortParamsByRequiredFlag);
465471

466-
allOperations.add(new HashMap<String, Object>(operation));
472+
allOperations.add(new HashMap<>(operation));
467473
for (int i = 0; i < allOperations.size(); i++) {
468474
Map<String, Object> oo = (Map<String, Object>) allOperations.get(i);
469475
if (i < (allOperations.size() - 1)) {
@@ -536,7 +542,7 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
536542
Set<String> supportingFilesToGenerate = null;
537543
String supportingFiles = System.getProperty(CodegenConstants.SUPPORTING_FILES);
538544
if (supportingFiles != null && !supportingFiles.isEmpty()) {
539-
supportingFilesToGenerate = new HashSet<String>(Arrays.asList(supportingFiles.split(",")));
545+
supportingFilesToGenerate = new HashSet<>(Arrays.asList(supportingFiles.split(",")));
540546
}
541547

542548
for (SupportingFile support : config.supportingFiles()) {
@@ -658,11 +664,11 @@ private void generateSupportingFiles(List<File> files, Map<String, Object> bundl
658664

659665
private Map<String, Object> buildSupportFileBundle(List<Object> allOperations, List<Object> allModels) {
660666

661-
Map<String, Object> bundle = new HashMap<String, Object>();
667+
Map<String, Object> bundle = new HashMap<>();
662668
bundle.putAll(config.additionalProperties());
663669
bundle.put("apiPackage", config.apiPackage());
664670

665-
Map<String, Object> apis = new HashMap<String, Object>();
671+
Map<String, Object> apis = new HashMap<>();
666672
apis.put("apis", allOperations);
667673

668674
URL url = URLPathUtil.getServerURL(openAPI);
@@ -717,12 +723,12 @@ public List<File> generate() {
717723
configureGeneratorProperties();
718724
configureSwaggerInfo();
719725

720-
List<File> files = new ArrayList<File>();
726+
List<File> files = new ArrayList<>();
721727
// models
722-
List<Object> allModels = new ArrayList<Object>();
728+
List<Object> allModels = new ArrayList<>();
723729
generateModels(files, allModels);
724730
// apis
725-
List<Object> allOperations = new ArrayList<Object>();
731+
List<Object> allOperations = new ArrayList<>();
726732
generateApis(files, allOperations, allModels);
727733

728734
// supporting files
@@ -750,10 +756,10 @@ private static void processMimeTypes(List<String> mimeTypeList, Map<String, Obje
750756
if (mimeTypeList == null || mimeTypeList.isEmpty()){
751757
return;
752758
}
753-
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
759+
List<Map<String, String>> c = new ArrayList<>();
754760
int count = 0;
755761
for (String key : mimeTypeList) {
756-
Map<String, String> mediaType = new HashMap<String, String>();
762+
Map<String, String> mediaType = new HashMap<>();
757763
mediaType.put("mediaType", key);
758764
count += 1;
759765
if (count < mimeTypeList.size()) {
@@ -770,7 +776,7 @@ private static void processMimeTypes(List<String> mimeTypeList, Map<String, Obje
770776
}
771777

772778
public Map<String, List<CodegenOperation>> processPaths(Paths paths) {
773-
Map<String, List<CodegenOperation>> ops = new TreeMap<String, List<CodegenOperation>>();
779+
Map<String, List<CodegenOperation>> ops = new TreeMap<>();
774780
for (String resourcePath : paths.keySet()) {
775781
PathItem path = paths.get(resourcePath);
776782
processOperation(resourcePath, "get", path.getGet(), ops, path);
@@ -827,7 +833,7 @@ private void processOperation(String resourcePath, String httpMethod, Operation
827833
per the swagger 2.0 spec "A unique parameter is defined by a combination of a name and location"
828834
i'm assuming "location" == "in"
829835
*/
830-
Set<String> operationParameters = new HashSet<String>();
836+
Set<String> operationParameters = new HashSet<>();
831837
if (operation.getParameters() != null) {
832838
for (Parameter parameter : operation.getParameters()) {
833839
operationParameters.add(generateParameterId(parameter));
@@ -886,13 +892,13 @@ private static String generateParameterId(Parameter parameter) {
886892

887893

888894
private Map<String, Object> processOperations(CodegenConfig config, String tag, List<CodegenOperation> ops, List<Object> allModels) {
889-
Map<String, Object> operations = new HashMap<String, Object>();
890-
Map<String, Object> objs = new HashMap<String, Object>();
895+
Map<String, Object> operations = new HashMap<>();
896+
Map<String, Object> objs = new HashMap<>();
891897
objs.put("classname", config.toApiName(tag));
892898
objs.put("pathPrefix", config.toApiVarName(tag));
893899

894900
// check for operationId uniqueness
895-
Set<String> opIds = new HashSet<String>();
901+
Set<String> opIds = new HashSet<>();
896902
int counter = 0;
897903
for (CodegenOperation op : ops) {
898904
String opId = op.nickname;
@@ -908,14 +914,14 @@ private Map<String, Object> processOperations(CodegenConfig config, String tag,
908914
operations.put("package", config.apiPackage());
909915

910916

911-
Set<String> allImports = new TreeSet<String>();
917+
Set<String> allImports = new TreeSet<>();
912918
for (CodegenOperation op : ops) {
913919
allImports.addAll(op.imports);
914920
}
915921

916-
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
922+
List<Map<String, String>> imports = new ArrayList<>();
917923
for (String nextImport : allImports) {
918-
Map<String, String> im = new LinkedHashMap<String, String>();
924+
Map<String, String> im = new LinkedHashMap<>();
919925
String mapping = config.importMapping().get(nextImport);
920926
if (mapping == null) {
921927
mapping = config.toModelImport(nextImport);
@@ -962,7 +968,7 @@ private Map<String, Object> processModels(CodegenConfig config, Map<String, Sche
962968
allImports.addAll(cm.imports);
963969
}
964970
objs.put("models", models);
965-
Set<String> importSet = new TreeSet<String>();
971+
Set<String> importSet = new TreeSet<>();
966972
for (String nextImport : allImports) {
967973
String mapping = config.importMapping().get(nextImport);
968974
if (mapping == null) {
@@ -977,9 +983,9 @@ private Map<String, Object> processModels(CodegenConfig config, Map<String, Sche
977983
importSet.add(mapping);
978984
}
979985
}
980-
List<Map<String, String>> imports = new ArrayList<Map<String, String>>();
986+
List<Map<String, String>> imports = new ArrayList<>();
981987
for(String s: importSet) {
982-
Map<String, String> item = new HashMap<String, String>();
988+
Map<String, String> item = new HashMap<>();
983989
item.put("import", s);
984990
imports.add(item);
985991
}
@@ -1020,4 +1026,19 @@ private boolean isJavaCodegen(String name) {
10201026
return name.equalsIgnoreCase("java")
10211027
|| name.equalsIgnoreCase("inflector");
10221028
}
1029+
1030+
private Boolean getCustomOptionBooleanValue(String option) {
1031+
List<CodegenArgument> languageArguments = config.getLanguageArguments();
1032+
if (languageArguments == null || languageArguments.isEmpty()) {
1033+
return null;
1034+
}
1035+
Optional<CodegenArgument> optionalCodegenArgument = languageArguments.stream()
1036+
.filter(argument -> option.equalsIgnoreCase(argument.getOption()))
1037+
.findFirst();
1038+
1039+
if (!optionalCodegenArgument.isPresent()) {
1040+
return null;
1041+
}
1042+
return Boolean.valueOf(optionalCodegenArgument.get().getValue());
1043+
}
10231044
}

modules/swagger-codegen/src/main/java/io/swagger/codegen/config/CodegenConfigurator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ public ClientOptInput toClientOptInput() {
416416
config.languageSpecificPrimitives().addAll(languageSpecificPrimitives);
417417
config.reservedWordsMappings().putAll(reservedWordMappings);
418418

419-
config.processArgumentsValues(codegenArguments);
419+
config.setLanguageArguments(codegenArguments);
420420

421421
checkAndSetAdditionalProperty(apiPackage, CodegenConstants.API_PACKAGE);
422422
checkAndSetAdditionalProperty(modelPackage, CodegenConstants.MODEL_PACKAGE);
@@ -478,7 +478,7 @@ public ClientOptInput toClientOptInput(String content) {
478478
config.languageSpecificPrimitives().addAll(languageSpecificPrimitives);
479479
config.reservedWordsMappings().putAll(reservedWordMappings);
480480

481-
config.processArgumentsValues(codegenArguments);
481+
config.setLanguageArguments(codegenArguments);
482482

483483
checkAndSetAdditionalProperty(apiPackage, CodegenConstants.API_PACKAGE);
484484
checkAndSetAdditionalProperty(modelPackage, CodegenConstants.MODEL_PACKAGE);

pom.xml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -840,25 +840,25 @@
840840
<modules>
841841
<!-- <module>samples/server/petstore/erlang-server</module> note: make sample compilation work -->
842842
<!-- clients -->
843-
<module>samples/client/petstore/php/SwaggerClient-php</module>
844-
<module>samples/client/petstore/ruby</module>
845-
<module>samples/client/petstore/scala</module>
846-
<module>samples/client/petstore/akka-scala</module>
847-
<module>samples/client/petstore/javascript</module>
848-
<module>samples/client/petstore/python</module>
849-
<module>samples/client/petstore/python-tornado</module>
850-
<module>samples/client/petstore/typescript-fetch/builds/default</module>
851-
<module>samples/client/petstore/typescript-fetch/builds/es6-target</module>
852-
<module>samples/client/petstore/typescript-fetch/builds/with-npm-version</module>
853-
<module>samples/client/petstore/typescript-fetch/tests/default</module>
854-
<module>samples/client/petstore/typescript-node/npm</module>
843+
<!--<module>samples/client/petstore/php/SwaggerClient-php</module>-->
844+
<!--<module>samples/client/petstore/ruby</module>-->
845+
<!--<module>samples/client/petstore/scala</module>-->
846+
<!--<module>samples/client/petstore/akka-scala</module>-->
847+
<!--<module>samples/client/petstore/javascript</module>-->
848+
<!--<module>samples/client/petstore/python</module>-->
849+
<!--<module>samples/client/petstore/python-tornado</module>-->
850+
<!--<module>samples/client/petstore/typescript-fetch/builds/default</module>-->
851+
<!--<module>samples/client/petstore/typescript-fetch/builds/es6-target</module>-->
852+
<!--<module>samples/client/petstore/typescript-fetch/builds/with-npm-version</module>-->
853+
<!--<module>samples/client/petstore/typescript-fetch/tests/default</module>-->
854+
<!--<module>samples/client/petstore/typescript-node/npm</module>-->
855855
<!-- comment out due to github rate limit error
856856
<module>samples/client/petstore/typescript-angularjs</module>-->
857857
<!-- comment out due to error `npm run build`
858858
<module>samples/client/petstore/typescript-jquery/npm</module>-->
859859
<!--<module>samples/client/petstore/typescript-angular-v2/npm</module>-->
860-
<module>samples/client/petstore/typescript-angular-v4/npm</module>
861-
<module>samples/client/petstore/typescript-angular-v4.3/npm</module>
860+
<!--<module>samples/client/petstore/typescript-angular-v4/npm</module>-->
861+
<!--<module>samples/client/petstore/typescript-angular-v4.3/npm</module>-->
862862
<!--<module>samples/client/petstore/bash</module>-->
863863
</modules>
864864
</profile>

0 commit comments

Comments
 (0)