Skip to content

Commit

Permalink
moved serializationLibrary Kotlin specific values to AbstractKotlinCo…
Browse files Browse the repository at this point in the history
…degen. I picked this layer instead of KotlinClient to make it available to the server in the future. In this commit, I've also updated kotlin.md to document serializationLibrary kotlin options. Testing: re-run mvn clean install and mvn verify
  • Loading branch information
parachutemind committed Aug 28, 2019
1 parent 505520e commit bfb8701
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/generators/kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ sidebar_label: kotlin
|parcelizeModels|toggle "@Parcelize" for generated models| |null|
|dateLibrary|Option. Date library to use|<dl><dt>**string**</dt><dd>String</dd><dt>**java8**</dt><dd>Java 8 native JSR310</dd><dt>**threetenbp**</dt><dd>Threetenbp</dd><dl>|java8|
|collectionType|Option. Collection type to use|<dl><dt>**array**</dt><dd>kotlin.Array</dd><dt>**list**</dt><dd>kotlin.collections.List</dd><dl>|array|
|serializationLibrary|Option. JSON serialization library to use|<dl><dt>**moshi**</dt><dd>https://github.com/square/moshi</dd><dt>**gson**</dt><dd>https://github.com/google/gson</dd><dl>|moshi|
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String ENUM_PROPERTY_NAMING = "enumPropertyNaming";
public static final String ENUM_PROPERTY_NAMING_DESC = "Naming convention for enum properties: 'camelCase', 'PascalCase', 'snake_case', 'UPPERCASE', and 'original'";

// Allow different language generators to offer an option of serialization library. Each language specific
// Codegen constants should define a description and provide proper input validation for the value of serializationLibrary
public static final String SERIALIZATION_LIBRARY = "serializationLibrary";
public static final String SERIALIZATION_LIBRARY_DESC = "What serialization library to use: 'moshi' (default), or 'gson'";
public static enum SERIALIZATION_LIBRARY_TYPE {moshi, gson}

public static final String MODEL_NAME_PREFIX = "modelNamePrefix";
public static final String MODEL_NAME_PREFIX_DESC = "Prefix that will be prepended to all model names.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
import static org.openapitools.codegen.utils.StringUtils.*;

public abstract class AbstractKotlinCodegen extends DefaultCodegen implements CodegenConfig {

public static final String SERIALIZATION_LIBRARY_DESC = "What serialization library to use: 'moshi' (default), or 'gson'";
public enum SERIALIZATION_LIBRARY_TYPE {moshi, gson}

private static final Logger LOGGER = LoggerFactory.getLogger(AbstractKotlinCodegen.class);

protected String artifactId;
Expand All @@ -51,7 +55,7 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
protected boolean parcelizeModels = false;

protected CodegenConstants.ENUM_PROPERTY_NAMING_TYPE enumPropertyNaming = CodegenConstants.ENUM_PROPERTY_NAMING_TYPE.camelCase;
protected CodegenConstants.SERIALIZATION_LIBRARY_TYPE serializationLibrary = CodegenConstants.SERIALIZATION_LIBRARY_TYPE.moshi;
protected SERIALIZATION_LIBRARY_TYPE serializationLibrary = SERIALIZATION_LIBRARY_TYPE.moshi;

public AbstractKotlinCodegen() {
super();
Expand Down Expand Up @@ -207,7 +211,7 @@ public AbstractKotlinCodegen() {
CliOption enumPropertyNamingOpt = new CliOption(CodegenConstants.ENUM_PROPERTY_NAMING, CodegenConstants.ENUM_PROPERTY_NAMING_DESC);
cliOptions.add(enumPropertyNamingOpt.defaultValue(enumPropertyNaming.name()));

CliOption serializationLibraryOpt = new CliOption(CodegenConstants.SERIALIZATION_LIBRARY, CodegenConstants.SERIALIZATION_LIBRARY_DESC);
CliOption serializationLibraryOpt = new CliOption(CodegenConstants.SERIALIZATION_LIBRARY, SERIALIZATION_LIBRARY_DESC);
cliOptions.add(serializationLibraryOpt.defaultValue(serializationLibrary.name()));

cliOptions.add(new CliOption(CodegenConstants.PARCELIZE_MODELS, CodegenConstants.PARCELIZE_MODELS_DESC));
Expand Down Expand Up @@ -249,7 +253,7 @@ public CodegenConstants.ENUM_PROPERTY_NAMING_TYPE getEnumPropertyNaming() {
return this.enumPropertyNaming;
}

public CodegenConstants.SERIALIZATION_LIBRARY_TYPE getSerializationLibrary() {
public SERIALIZATION_LIBRARY_TYPE getSerializationLibrary() {
return this.serializationLibrary;
}

Expand All @@ -273,14 +277,15 @@ public void setEnumPropertyNaming(final String enumPropertyNamingType) {
/**
* Sets the serialization engine for Kotlin
*
* @param enumSerializationLibrary The string representation of the serialization library as defined by {@link org.openapitools.codegen.CodegenConstants.SERIALIZATION_LIBRARY_TYPE}
* @param enumSerializationLibrary The string representation of the serialization library as defined by
* {@link org.openapitools.codegen.languages.AbstractKotlinCodegen.SERIALIZATION_LIBRARY_TYPE}
*/
public void setSerializationLibrary(final String enumSerializationLibrary) {
try {
this.serializationLibrary = CodegenConstants.SERIALIZATION_LIBRARY_TYPE.valueOf(enumSerializationLibrary);
this.serializationLibrary = SERIALIZATION_LIBRARY_TYPE.valueOf(enumSerializationLibrary);
} catch (IllegalArgumentException ex) {
StringBuilder sb = new StringBuilder(enumSerializationLibrary + " is an invalid enum property naming option. Please choose from:");
for (CodegenConstants.SERIALIZATION_LIBRARY_TYPE t : CodegenConstants.SERIALIZATION_LIBRARY_TYPE.values()) {
for (SERIALIZATION_LIBRARY_TYPE t : SERIALIZATION_LIBRARY_TYPE.values()) {
sb.append("\n ").append(t.name());
}
throw new RuntimeException(sb.toString());
Expand Down

0 comments on commit bfb8701

Please sign in to comment.