Skip to content

adding fluent api options to spring java codegen #7056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SpringCodegen extends AbstractJavaCodegen
public static final String SPRING_CLOUD_LIBRARY = "spring-cloud";
public static final String IMPLICIT_HEADERS = "implicitHeaders";
public static final String SWAGGER_DOCKET_CONFIG = "swaggerDocketConfig";
public static final String COLLECTION_FLUENT_PATTERN = "collectionFluentPattern";
public static final String SIMPLE_FLUENT_PATTERN = "simpleFluentPattern";

protected String title = "swagger-petstore";
protected String configPackage = "io.swagger.configuration";
Expand All @@ -45,6 +47,8 @@ public class SpringCodegen extends AbstractJavaCodegen
protected String responseWrapper = "";
protected boolean useTags = false;
protected boolean useBeanValidation = true;
protected boolean simpleFluentPattern = true;
protected boolean collectionFluentPattern = true;
protected boolean implicitHeaders = false;
protected boolean swaggerDocketConfig = false;
protected boolean useOptional = false;
Expand Down Expand Up @@ -76,6 +80,8 @@ public SpringCodegen() {
cliOptions.add(new CliOption(RESPONSE_WRAPPER, "wrap the responses in given type (Future,Callable,CompletableFuture,ListenableFuture,DeferredResult,HystrixCommand,RxObservable,RxSingle or fully qualified type)"));
cliOptions.add(CliOption.newBoolean(USE_TAGS, "use tags for creating interface and controller classnames"));
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(COLLECTION_FLUENT_PATTERN, "Use Fluent Pattern for collection item setters"));
cliOptions.add(CliOption.newBoolean(SIMPLE_FLUENT_PATTERN, "Use Fluent Pattern for setters"));
cliOptions.add(CliOption.newBoolean(IMPLICIT_HEADERS, "Use of @ApiImplicitParams for headers."));
cliOptions.add(CliOption.newBoolean(SWAGGER_DOCKET_CONFIG, "Generate Spring Swagger Docket configuration class."));
cliOptions.add(CliOption.newBoolean(USE_OPTIONAL,
Expand Down Expand Up @@ -181,14 +187,27 @@ public void processOpts() {
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
this.setUseBeanValidation(convertPropertyToBoolean(USE_BEANVALIDATION));
}

if (additionalProperties.containsKey(COLLECTION_FLUENT_PATTERN)) {
this.setCollectionFluentPattern(convertPropertyToBoolean(COLLECTION_FLUENT_PATTERN));
}
if (additionalProperties.containsKey(SIMPLE_FLUENT_PATTERN)) {
this.setSimpleFluentPattern(convertPropertyToBoolean(SIMPLE_FLUENT_PATTERN));
}
if (additionalProperties.containsKey(USE_OPTIONAL)) {
this.setUseOptional(convertPropertyToBoolean(USE_OPTIONAL));
}

if (useBeanValidation) {
writePropertyBack(USE_BEANVALIDATION, useBeanValidation);
}

if (!collectionFluentPattern) {
writePropertyBack(COLLECTION_FLUENT_PATTERN, collectionFluentPattern);
}

if (!simpleFluentPattern) {
writePropertyBack(SIMPLE_FLUENT_PATTERN, simpleFluentPattern);
}

if (additionalProperties.containsKey(IMPLICIT_HEADERS)) {
this.setImplicitHeaders(Boolean.valueOf(additionalProperties.get(IMPLICIT_HEADERS).toString()));
Expand Down Expand Up @@ -277,6 +296,12 @@ public void processOpts() {
additionalProperties.put("jdk8-no-delegate", true);
}

if (this.collectionFluentPattern) {
additionalProperties.put("collectionFluentPattern", "true");
}
if (this.simpleFluentPattern) {
additionalProperties.put("simpleFluentPattern", "true");
}

if (this.delegatePattern) {
additionalProperties.put("isDelegate", "true");
Expand Down Expand Up @@ -665,6 +690,14 @@ public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
}

public void setSimpleFluentPattern(boolean simpleFluentPattern) {
this.simpleFluentPattern = simpleFluentPattern;
}

public void setCollectionFluentPattern(boolean collectionFluentPattern) {
this.collectionFluentPattern = collectionFluentPattern;
}

@Override
public void setUseOptional(boolean useOptional) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,13 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali

{{/vars}}
{{#vars}}
{{#simpleFluentPattern}}
public {{classname}} {{name}}({{{datatypeWithEnum}}} {{name}}) {
this.{{name}} = {{name}};
return this;
}
{{/simpleFluentPattern}}
{{#collectionFluentPattern}}
{{#isListContainer}}

public {{classname}} add{{nameInCamelCase}}Item({{{items.datatypeWithEnum}}} {{name}}Item) {
Expand All @@ -67,6 +70,7 @@ public class {{classname}} {{#parent}}extends {{{parent}}}{{/parent}} {{#seriali
return this;
}
{{/isMapContainer}}
{{/collectionFluentPattern}}

/**
{{#description}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class SpringOptionsProvider extends JavaOptionsProvider {
public static final String IMPLICIT_HEADERS = "false";
public static final String SWAGGER_DOCKET_CONFIG = "false";
public static final String USE_OPTIONAL = "false";
public static final String COLLECTION_FLUENT_PATTERN = "true";
public static final String SIMPLE_FLUENT_PATTERN = "true";

@Override
public String getLanguage() {
Expand All @@ -46,6 +48,8 @@ public Map<String, String> createOptions() {
options.put(SpringCodegen.IMPLICIT_HEADERS, IMPLICIT_HEADERS);
options.put(SpringCodegen.SWAGGER_DOCKET_CONFIG, SWAGGER_DOCKET_CONFIG);
options.put(SpringCodegen.USE_OPTIONAL, USE_OPTIONAL);
options.put(SpringCodegen.SIMPLE_FLUENT_PATTERN, SIMPLE_FLUENT_PATTERN);
options.put(SpringCodegen.COLLECTION_FLUENT_PATTERN, COLLECTION_FLUENT_PATTERN);

return options;
}
Expand Down
Loading