Skip to content

Commit

Permalink
Merge java8 doc for spring (#3122)
Browse files Browse the repository at this point in the history
fix #3117
  • Loading branch information
Zomzog authored and wing328 committed Jun 21, 2019
1 parent 1540ae7 commit e3fe12e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
3 changes: 1 addition & 2 deletions docs/generators/spring.md
Expand Up @@ -35,7 +35,7 @@ sidebar_label: spring
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false|
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
|dateLibrary|Option. Date library to use|<dl><dt>**joda**</dt><dd>Joda (for legacy app only)</dd><dt>**legacy**</dt><dd>Legacy java.util.Date (if you really have a good reason not to use threetenbp</dd><dt>**java8-localdatetime**</dt><dd>Java 8 using LocalDateTime (for legacy app only)</dd><dt>**java8**</dt><dd>Java 8 native JSR310 (preferred for jdk 1.8+) - note: this also sets &quot;java8&quot; to true</dd><dt>**threetenbp**</dt><dd>Backport of JSR310 (preferred for jdk &lt; 1.8)</dd><dl>|threetenbp|
|java8|Option. Use Java8 classes instead of third party equivalents|<dl><dt>**true**</dt><dd>Use Java 8 classes such as Base64</dd><dt>**false**</dt><dd>Various third party libraries as needed</dd><dl>|false|
|java8|Option. Use Java8 classes instead of third party equivalents|<dl><dt>**true**</dt><dd>Use Java 8 classes such as Base64. Use java8 default interface when a responseWrapper is used</dd><dt>**false**</dt><dd>Various third party libraries as needed</dd><dl>|false|
|disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false|
|booleanGetterPrefix|Set booleanGetterPrefix| |get|
|parentGroupId|parent groupId in generated pom N.B. parentGroupId, parentArtifactId and parentVersion must all be specified for any of them to take effect| |null|
Expand All @@ -48,7 +48,6 @@ sidebar_label: spring
|interfaceOnly|Whether to generate only API interface stubs without the server files.| |false|
|delegatePattern|Whether to generate the server files using the delegate pattern| |false|
|singleContentTypes|Whether to select only one produces/consumes content-type by operation.| |false|
|java8|use java8 default interface| |true|
|async|use async Callable controllers| |false|
|reactive|wrap responses in Mono/Flux Reactor types (spring-boot only)| |false|
|responseWrapper|wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)| |null|
Expand Down
Expand Up @@ -175,7 +175,7 @@ public AbstractJavaCodegen() {
dateLibrary.setEnum(dateOptions);
cliOptions.add(dateLibrary);

CliOption java8Mode = new CliOption(JAVA8_MODE, "Option. Use Java8 classes instead of third party equivalents").defaultValue(String.valueOf(this.java8Mode));
CliOption java8Mode = CliOption.newBoolean(JAVA8_MODE, "Option. Use Java8 classes instead of third party equivalents", this.java8Mode);
Map<String, String> java8ModeOptions = new HashMap<>();
java8ModeOptions.put("true", "Use Java 8 classes such as Base64");
java8ModeOptions.put("false", "Various third party libraries as needed");
Expand Down
Expand Up @@ -21,7 +21,6 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
Expand Down Expand Up @@ -117,7 +116,7 @@ public SpringCodegen() {
cliOptions.add(CliOption.newBoolean(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly));
cliOptions.add(CliOption.newBoolean(DELEGATE_PATTERN, "Whether to generate the server files using the delegate pattern", delegatePattern));
cliOptions.add(CliOption.newBoolean(SINGLE_CONTENT_TYPES, "Whether to select only one produces/consumes content-type by operation.", singleContentTypes));
cliOptions.add(CliOption.newBoolean(JAVA_8, "use java8 default interface", java8));
updateJava8CliOptions();
cliOptions.add(CliOption.newBoolean(ASYNC, "use async Callable controllers", async));
cliOptions.add(CliOption.newBoolean(REACTIVE, "wrap responses in Mono/Flux Reactor types (spring-boot only)", reactive));
cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)"));
Expand All @@ -142,6 +141,13 @@ public SpringCodegen() {

}

private void updateJava8CliOptions() {
CliOption option = cliOptions.stream().filter(o -> JAVA_8.equals(o.getOpt())).findFirst()
.orElseThrow(() -> new RuntimeException("Missing java8 option"));
Map<String, String> java8ModeOptions = option.getEnum();
java8ModeOptions.put("true", "Use Java 8 classes such as Base64. Use java8 default interface when a responseWrapper is used");
}

@Override
public CodegenType getTag() {
return CodegenType.SERVER;
Expand Down
Expand Up @@ -22,6 +22,7 @@
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
import io.swagger.v3.parser.core.models.ParseOptions;
import org.openapitools.codegen.CliOption;
import org.openapitools.codegen.ClientOptInput;
import org.openapitools.codegen.ClientOpts;
import org.openapitools.codegen.CodegenConstants;
Expand All @@ -35,11 +36,12 @@
import java.io.IOException;
import java.nio.file.Files;

import static java.util.stream.Collectors.groupingBy;
import static org.openapitools.codegen.languages.SpringCodegen.RESPONSE_WRAPPER;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;

import static org.openapitools.codegen.languages.SpringCodegen.RESPONSE_WRAPPER;

public class SpringCodegenTest {

@Test
Expand Down Expand Up @@ -168,4 +170,13 @@ private void checkFileNotContains(MockDefaultGenerator generator, String path, S
for (String line : lines)
assertFalse(file.contains(line));
}

@Test
public void clientOptsUnicity() {
SpringCodegen codegen = new SpringCodegen();
codegen.cliOptions()
.stream()
.collect(groupingBy(CliOption::getOpt))
.forEach((k,v) -> assertEquals(v.size(), 1, k + " is described multiple times"));
}
}

0 comments on commit e3fe12e

Please sign in to comment.