Skip to content
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

[Java] option for the prefix of boolean getters #432

Merged
merged 8 commits into from
Jul 3, 2018
Merged
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
2 changes: 1 addition & 1 deletion bin/java-petstore-feign.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/feign -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign.json -o samples/client/petstore/java/feign -DhideGenerationTimestamp=true $@"
ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/feign -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-feign.json -o samples/client/petstore/java/feign -DhideGenerationTimestamp=true -DbooleanGetterPrefix=is $@"

echo "Removing files and folders under samples/client/petstore/java/feign/src/main"
rm -rf samples/client/petstore/java/feign/src/main
Expand Down
2 changes: 1 addition & 1 deletion bin/java-petstore-jersey2-java6.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate --artifact-id petstore-jersey2-java6 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-jersey2.json -o samples/client/petstore/java/jersey2-java6 -DhideGenerationTimestamp=true,supportJava6=true $@"
ags="generate --artifact-id petstore-jersey2-java6 -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-jersey2.json -o samples/client/petstore/java/jersey2-java6 -DhideGenerationTimestamp=true,supportJava6=true,booleanGetterPrefix=is $@"

echo "Removing files and folders under samples/client/petstore/java/jersey2-java6/src/main"
rm -rf samples/client/petstore/java/jersey2-java6/src/main
Expand Down
2 changes: 1 addition & 1 deletion bin/java-petstore-rest-assured.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/rest-assured -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured.json -o samples/client/petstore/java/rest-assured -DhideGenerationTimestamp=true $@"
ags="generate -t modules/openapi-generator/src/main/resources/Java/libraries/rest-assured -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g java -c bin/java-petstore-rest-assured.json -o samples/client/petstore/java/rest-assured -DhideGenerationTimestamp=true --additional-properties booleanGetterPrefix=is $@"

echo "Removing files and folders under samples/client/petstore/java/rest-assured/src/main"
rm -rf samples/client/petstore/java/rest-assured/src/main
Expand Down
2 changes: 1 addition & 1 deletion bin/spring-mvc-petstore-j8-localdatetime.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/JavaSpring -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g spring -c bin/spring-mvc-petstore-j8-localdatetime.json -o samples/server/petstore/spring-mvc-j8-localdatetime -DhideGenerationTimestamp=true --additional-properties serverPort=8002 $@"
ags="generate -t modules/openapi-generator/src/main/resources/JavaSpring -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g spring -c bin/spring-mvc-petstore-j8-localdatetime.json -o samples/server/petstore/spring-mvc-j8-localdatetime -DhideGenerationTimestamp=true -DbooleanGetterPrefix=get --additional-properties serverPort=8002 $@"

java $JAVA_OPTS -jar $executable $ags
2 changes: 1 addition & 1 deletion bin/spring-mvc-petstore-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ fi

# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="generate -t modules/openapi-generator/src/main/resources/JavaSpring -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g spring -c bin/spring-mvc-petstore-server.json -o samples/server/petstore/spring-mvc -DhideGenerationTimestamp=true,java8=false --additional-properties serverPort=8002 $@"
ags="generate -t modules/openapi-generator/src/main/resources/JavaSpring -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -g spring -c bin/spring-mvc-petstore-server.json -o samples/server/petstore/spring-mvc -DhideGenerationTimestamp=true,java8=false --additional-properties serverPort=8002 --additional-properties booleanGetterPrefix=get $@"

java $JAVA_OPTS -jar $executable $ags
32 changes: 32 additions & 0 deletions docs/migration-guide.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
== Migration guide between OpenAPI-Generator versions

This page summaries the important changes between major and minor version of OpenAPI-Generator.
It does not contain a detailed list of changes, for that refer to each individual release notes.

This page is written to help migration by indicating the most impacting changes.
Do not hesitate to contribute additional notes if you discover something during your migration and think that the information might help other users.

Another approach to find breaking changes is to look at issue and pull requests with following labels:

* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28with%20fallback%29[Breaking change (with fallback)]
* link:https://github.com/OpenAPITools/openapi-generator/labels/Breaking%20change%20%28without%20fallback%29[Breaking change (without fallback)]

=== From 3.0.x to 3.1.0

Version `3.1.0` is the first minor version of OpenAPI-Generator, in comparison to `3.0.3` it contains some breaking changes, but with the possibility to fallback to the old behavior.
The default value of some options might change.
Projects relying on generated code might need to be adapted.

==== Java

A new option is introduced with link:https://github.com/OpenAPITools/openapi-generator/pull/432[#432] to specify the prefix of boolean getters: `booleanGetterPrefix`.
Possible values:

* `is`: the value used in `3.0.x`.
* `get`: the new default value.

If you use the default value you will see your generated code changing from `isActive()` to `getActive()`.

=== Migrating from Swagger-Codegen

Please read the specific migration guide: link:migration-from-swagger-codegen.md[From Swagger-Codegen to OpenAPI-Generator]
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
public static final String WITH_XML = "withXml";
public static final String SUPPORT_JAVA6 = "supportJava6";
public static final String DISABLE_HTML_ESCAPING = "disableHtmlEscaping";
public static final String BOOLEAN_GETTER_PREFIX = "booleanGetterPrefix";
public static final String BOOLEAN_GETTER_PREFIX_DEFAULT = "get";

protected String dateLibrary = "threetenbp";
protected boolean supportAsync = false;
Expand Down Expand Up @@ -96,6 +98,7 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
protected String modelDocPath = "docs/";
protected boolean supportJava6= false;
protected boolean disableHtmlEscaping = false;
protected String booleanGetterPrefix = BOOLEAN_GETTER_PREFIX_DEFAULT;

public AbstractJavaCodegen() {
super();
Expand Down Expand Up @@ -188,6 +191,7 @@ public AbstractJavaCodegen() {
cliOptions.add(java8Mode);

cliOptions.add(CliOption.newBoolean(DISABLE_HTML_ESCAPING, "Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)"));
cliOptions.add(CliOption.newString(BOOLEAN_GETTER_PREFIX, "Set booleanGetterPrefix (default value '" + BOOLEAN_GETTER_PREFIX_DEFAULT + "')"));
}

@Override
Expand All @@ -204,6 +208,11 @@ public void processOpts() {
}
additionalProperties.put(DISABLE_HTML_ESCAPING, disableHtmlEscaping);

if (additionalProperties.containsKey(BOOLEAN_GETTER_PREFIX)) {
this.setBooleanGetterPrefix(additionalProperties.get(BOOLEAN_GETTER_PREFIX).toString());
}
additionalProperties.put(BOOLEAN_GETTER_PREFIX, booleanGetterPrefix);

if (additionalProperties.containsKey(CodegenConstants.INVOKER_PACKAGE)) {
this.setInvokerPackage((String) additionalProperties.get(CodegenConstants.INVOKER_PACKAGE));
} else if (additionalProperties.containsKey(CodegenConstants.API_PACKAGE)) {
Expand Down Expand Up @@ -1233,6 +1242,10 @@ public void setDisableHtmlEscaping(boolean disabled) {
this.disableHtmlEscaping = disabled;
}

public void setBooleanGetterPrefix(String booleanGetterPrefix) {
this.booleanGetterPrefix = booleanGetterPrefix;
}

@Override
public String escapeQuotationMark(String input) {
// remove " to avoid code injection
Expand Down Expand Up @@ -1291,7 +1304,7 @@ public void writePropertyBack(String propertyKey, boolean value) {
* @return getter name based on naming convention
*/
public String toBooleanGetter(String name) {
return "is" + getterAndSetterCapitalize(name);
return booleanGetterPrefix + getterAndSetterCapitalize(name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void testInitialConfigValues() throws Exception {
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "invalidPackageName");
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools");
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "get");
}

@Test
Expand All @@ -105,6 +106,7 @@ public void testSettersForConfigValues() throws Exception {
codegen.setModelPackage("xyz.yyyyy.zzzzzzz.model");
codegen.setApiPackage("xyz.yyyyy.zzzzzzz.api");
codegen.setInvokerPackage("xyz.yyyyy.zzzzzzz.invoker");
codegen.setBooleanGetterPrefix("is");
codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
Expand All @@ -115,6 +117,7 @@ public void testSettersForConfigValues() throws Exception {
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.zzzzzzz.api");
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.zzzzzzz.invoker");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.zzzzzzz.invoker");
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "is");
}

@Test
Expand All @@ -124,6 +127,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "xyz.yyyyy.model.oooooo");
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.yyyyy.api.oooooo");
codegen.additionalProperties().put(CodegenConstants.INVOKER_PACKAGE, "xyz.yyyyy.invoker.oooooo");
codegen.additionalProperties().put(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX, "getBoolean");
codegen.processOpts();

Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
Expand All @@ -134,6 +138,7 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xyz.yyyyy.api.oooooo");
Assert.assertEquals(codegen.getInvokerPackage(), "xyz.yyyyy.invoker.oooooo");
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "xyz.yyyyy.invoker.oooooo");
Assert.assertEquals(codegen.additionalProperties().get(AbstractJavaCodegen.BOOLEAN_GETTER_PREFIX), "getBoolean");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,8 @@ public void modelWithWrappedXmlTest() {
@Test(description = "convert a boolean parameter")
public void booleanPropertyTest() {
final BooleanSchema property = new BooleanSchema();
final DefaultCodegen codegen = new JavaClientCodegen();
final JavaClientCodegen codegen = new JavaClientCodegen();
codegen.setBooleanGetterPrefix("is");
final CodegenProperty cp = codegen.fromProperty("property", property);

Assert.assertEquals(cp.baseName, "property");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Cat declawed(Boolean declawed) {
* @return declawed
**/
@ApiModelProperty(value = "")
public Boolean isDeclawed() {
public Boolean getDeclawed() {
return declawed;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public Order complete(Boolean complete) {
* @return complete
**/
@ApiModelProperty(value = "")
public Boolean isComplete() {
public Boolean getComplete() {
return complete;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public OuterComposite myBoolean(Boolean myBoolean) {
* @return myBoolean
**/
@ApiModelProperty(value = "")
public Boolean isMyBoolean() {
public Boolean getMyBoolean() {
return myBoolean;
}

Expand Down
Loading