Initial commit

This commit is contained in:
AnastasiyaK97 2022-08-19 12:31:36 +03:00 committed by Anastasiya97
commit d483df57a3
25 changed files with 762 additions and 0 deletions

32
.gitignore vendored Normal file
View File

@ -0,0 +1,32 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### Mac OS ###
.DS_Store

19
.idea/misc.xml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="SwUserDefinedSpecifications">
<option name="specTypeByUrl">
<map />
</option>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

124
.idea/workspace.xml Normal file
View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="1b8bc19c-dc12-4992-baae-5fd4b658f2f6" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/pom.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/ru/touchin/codegen/TINetworkingCodegen.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/ru/touchin/codegen/TINetworkingCodegenConstants.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/META-INF/services/io.swagger.codegen.v3.CodegenConfig" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/APIDateFormat.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/EnumJsonAdapters.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/GeneratedDateAdapter.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/api.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/bodyParams.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/build.gradle.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/data_class.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/data_class_opt_var.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/data_class_req_var.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/headerParams.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/licenseInfo.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/manifest.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/model.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/pathParams.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/queryParams.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/securityParam.mustache" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/resources/handlebars/TINetworking/settings.gradle.mustache" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="HighlightingSettingsPerFile">
<setting file="jar://$MAVEN_REPOSITORY$/io/swagger/codegen/v3/swagger-codegen-generators/1.0.32/swagger-codegen-generators-1.0.32.jar!/io/swagger/codegen/v3/generators/DefaultCodegenConfig.class" root0="SKIP_INSPECTION" />
<setting file="jar://$MAVEN_REPOSITORY$/io/swagger/codegen/v3/swagger-codegen-generators/1.0.32/swagger-codegen-generators-1.0.32.jar!/io/swagger/codegen/v3/generators/kotlin/AbstractKotlinCodegen.class" root0="SKIP_INSPECTION" />
<setting file="jar://$MAVEN_REPOSITORY$/io/swagger/codegen/v3/swagger-codegen/3.0.34/swagger-codegen-3.0.34.jar!/io/swagger/codegen/v3/CodegenProperty.class" root0="SKIP_INSPECTION" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2DOjBE8CKnEok5BkY4v7TsJOihU" />
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;last_opened_file_path&quot;: &quot;D:/Instinct/TINetworkingCodegen/src/main/resources/handlebars/TINetworking&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;editor.preferences.fonts.default&quot;
}
}</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\Instinct\TINetworkingCodegen\src\main\resources\handlebars\TINetworking" />
</key>
<key name="MoveClassesOrPackagesDialog.RECENTS_KEY">
<recent name="ru.touchin.codegen" />
</key>
</component>
<component name="RunManager">
<configuration name="ru.touchin.codegen.TINetworkingCodegen" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="ru.touchin.codegen.TINetworkingCodegen" />
<module name="TINetworkingCodegen" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ru.touchin.codegen.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.ru.touchin.codegen.TINetworkingCodegen" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="1b8bc19c-dc12-4992-baae-5fd4b658f2f6" name="Changes" comment="" />
<created>1660576889911</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1660576889911</updated>
<workItem from="1660576891238" duration="54240000" />
<workItem from="1660814050249" duration="2328000" />
<workItem from="1660822481926" duration="1799000" />
<workItem from="1660829209106" duration="13023000" />
<workItem from="1660898774793" duration="1646000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />
<select />
</component>
</project>

130
pom.xml Normal file
View File

@ -0,0 +1,130 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.swagger</groupId>
<artifactId>TINetworking-swagger-codegen</artifactId>
<packaging>jar</packaging>
<name>TINetworking-swagger-codegen</name>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<version>2.2.0</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemProperties>
<property>
<name>loggerPath</name>
<value>conf/log4j.properties</value>
</property>
</systemProperties>
<argLine>-Xms512m -Xmx1500m</argLine>
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
</plugin>
<!-- attach test jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>${build-helper-maven-plugin}</version>
<executions>
<execution>
<id>add_sources</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add_test_sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen</artifactId>
<version>${swagger-codegen-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>${swagger-codegen-generators-version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<swagger-codegen-version>3.0.34</swagger-codegen-version>
<swagger-codegen-generators-version>1.0.32</swagger-codegen-generators-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.13.1</junit-version>
<build-helper-maven-plugin>3.0.0</build-helper-maven-plugin>
</properties>
</project>

View File

@ -0,0 +1,238 @@
package ru.touchin.codegen;
import com.github.jknack.handlebars.Handlebars;
import com.github.jknack.handlebars.helper.ConditionalHelpers;
import io.swagger.codegen.v3.*;
import io.swagger.codegen.v3.generators.handlebars.BaseItemsHelper;
import io.swagger.codegen.v3.generators.handlebars.ExtensionHelper;
import io.swagger.codegen.v3.generators.kotlin.AbstractKotlinCodegen;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.*;
public class TINetworkingCodegen extends AbstractKotlinCodegen {
public static final String DATE_LIBRARY = "dateLibrary";
public static final String PROJECT_NAME = "projectName";
private static Logger LOGGER = LoggerFactory.getLogger(TINetworkingCodegen.class);
protected String dateLibrary = DateLibrary.JODA_TIME.value;
protected String projectName = "SwaggerAPI";
private Map<String, String> allCustomDateFormats = new HashMap<>();
private Set<String> allEnumAdapters = new HashSet<>();
private Set<String> allEnumAdaptersImports = new HashSet<>();
public enum DateLibrary {
STRING("string"),
JAVA8("java8"),
JODA_TIME("jodaTime");
public final String value;
DateLibrary(String value) {
this.value = value;
}
}
public TINetworkingCodegen() {
super();
this.typeMapping.put("array", "kotlin.collections.List");
this.typeMapping.put("list", "kotlin.collections.List");
artifactId = "kotlin-client";
groupId = "ru.touchin";
outputFolder = "generated-code" + File.separator + "kotlin-client";
modelTemplateFiles.put("model.mustache", ".kt");
apiTemplateFiles.put("api.mustache", ".kt");
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");
Map<String, String> dateOptions = new HashMap<>();
dateOptions.put(DateLibrary.STRING.value, "String");
dateOptions.put(DateLibrary.JAVA8.value, "Java 8 native JSR310");
dateOptions.put(DateLibrary.JODA_TIME.value, "JodaTime");
dateLibrary.setEnum(dateOptions);
cliOptions.add(dateLibrary);
cliOptions.add(new CliOption(PROJECT_NAME, "Project name in Xcode"));
}
@Override
public void addHandlebarHelpers(Handlebars handlebars) {
super.addHandlebarHelpers(handlebars);
handlebars.registerHelpers(ConditionalHelpers.class);
}
@Override
public String getDefaultTemplateDir() {
return "TINetworking";
}
public CodegenType getTag() {
return CodegenType.CLIENT;
}
public String getName() {
return "TINetworking";
}
public String getHelp() {
return "Generates a TINetworking kotlin client library.";
}
public void setDateLibrary(String library) {
this.dateLibrary = library;
}
@Override
public List<SupportingFile> supportingFiles() {
List<SupportingFile> supportingFiles = super.supportingFiles();
supportingFiles.add(new SupportingFile("APIDateFormat.mustache",
sourceFolder,
"APIDateFormat.kt"));
supportingFiles.add(new SupportingFile("GeneratedDateAdapter.mustache",
sourceFolder,
"GeneratedDateAdapter.kt"));
supportingFiles.add(new SupportingFile("EnumJsonAdapters.mustache",
sourceFolder,
"EnumJsonAdapters.kt"));
return supportingFiles;
}
@Override
public void processOpts() {
setupProjectName();
super.processOpts();
if (additionalProperties.containsKey(DATE_LIBRARY)) {
setDateLibrary(additionalProperties.get(DATE_LIBRARY).toString());
}
if (DateLibrary.JODA_TIME.value.equals(dateLibrary)) {
additionalProperties.put(DateLibrary.JODA_TIME.value, true);
typeMapping.put("date", "DateTime");
typeMapping.put("date-time", "DateTime");
typeMapping.put("time", "DateTime");
typeMapping.put("DateTime", "DateTime");
importMapping.put("DateTime", "org.joda.time.DateTime");
defaultIncludes.add("org.joda.time.DateTime");
} else if (DateLibrary.STRING.value.equals(dateLibrary)) {
typeMapping.put("date-time", "kotlin.String");
typeMapping.put("date", "kotlin.String");
typeMapping.put("Date", "kotlin.String");
typeMapping.put("DateTime", "kotlin.String");
} else if (DateLibrary.JAVA8.value.equals(dateLibrary)) {
additionalProperties.put(DateLibrary.JAVA8.value, true);
}
supportingFiles.add(new SupportingFile("manifest.mustache", "src/main", "AndroidManifest.xml"));
supportingFiles.add(new SupportingFile("build.gradle.mustache", "", "build.gradle.kts"));
supportingFiles.add(new SupportingFile("settings.gradle.mustache", "", "settings.gradle"));
}
private void setupProjectName() {
if (additionalProperties.containsKey(PROJECT_NAME)) {
this.projectName = (String) additionalProperties.get(PROJECT_NAME);
} else {
additionalProperties.put(PROJECT_NAME, projectName);
}
packageName = groupId + "." + projectName;
modelPackage = packageName + "." + "models";
apiPackage = packageName + "." + "apis";
}
@Override
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
Map<String, Object> supportingFileData = super.postProcessSupportingFileData(objs);
supportingFileData.put("apiDateFormats", allCustomDateFormats);
supportingFileData.put("enumAdapters", allEnumAdapters);
supportingFileData.put("enumAdaptersImports", allEnumAdaptersImports);
return supportingFileData;
}
@Override
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
super.postProcessModelProperty(model, property);
updateEnumAdapters(model, property);
updateVendorExtensionsForProperty(property);
if (property.getIsListContainer()) {
updateVendorExtensionsForProperty(property.items);
}
if (property.getIsObject() && isReservedWord(property.getDatatype())) {
property.datatype = escapeReservedTypeDeclaration(property.getDatatype());
property.datatypeWithEnum = property.datatype;
}
}
private void updateEnumAdapters(CodegenModel model, CodegenProperty property) {
boolean isEnum = ExtensionHelper.getBooleanValue(property, "x-is-enum");
if (isEnum) {
String enumAdapterName = model.name + "." + property.enumName + ".JsonAdapter";
String importName = modelPackage + "." + model.name;
allEnumAdapters.add(enumAdapterName);
allEnumAdaptersImports.add(importName);
}
}
@Override
public String toParamName(String name) {
return super.toParamName(name).replaceAll("[^A-Za-z0-9_]", "");
}
@Override
protected void updateDataTypeWithEnumForArray(CodegenProperty property) {
CodegenProperty baseItem = BaseItemsHelper.getBaseItemsProperty(property);
if (baseItem != null) {
property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, this.toEnumName(baseItem));
property.datatype = baseItem.baseType;
property.enumName = this.toEnumName(property);
if (property.defaultValue != null) {
property.defaultValue = property.defaultValue.replace(baseItem.baseType, this.toEnumName(baseItem));
}
}
}
@Override
public String toEnumName(CodegenProperty property) {
return StringUtils.capitalize(property.name);
}
private String escapeReservedTypeDeclaration(String name) {
return "Model" + name;
}
private void updateVendorExtensionsForProperty(CodegenProperty property) {
Map<String, Object> vendorExtensions = property.getVendorExtensions();
if (isISO8601DateProperty(property)) {
vendorExtensions.put(TINetworkingCodegenConstants.IS_ISO8601_DATE, true);
} else if (isCustomDateFormatProperty(property)) {
String customDateFormat = (String) vendorExtensions.get(TINetworkingCodegenConstants.DATE_FORMAT);
String dateFormatName = customDateFormat.replace(".", "_")
.replaceAll("[^A-Za-z0-9_]", "");
vendorExtensions.put(TINetworkingCodegenConstants.DATE_FORMAT_NAME, dateFormatName);
allCustomDateFormats.put(dateFormatName, customDateFormat);
}
}
private boolean isISO8601DateProperty(CodegenProperty property) {
return property.getIsDate()
|| property.getIsDateTime()
&& !isCustomDateFormatProperty(property);
}
private boolean isCustomDateFormatProperty(CodegenProperty property) {
return property.getVendorExtensions().containsKey(TINetworkingCodegenConstants.DATE_FORMAT);
}
}

View File

@ -0,0 +1,7 @@
package ru.touchin.codegen;
public class TINetworkingCodegenConstants {
public static final String DATE_FORMAT = "x-custom-date-format";
public static final String DATE_FORMAT_NAME = "x-codegen-date-format-name";
public static final String IS_ISO8601_DATE = "x-codegen-is-iso8601-date";
}

View File

@ -0,0 +1 @@
ru.touchin.codegen.TINetworkingCodegen

View File

@ -0,0 +1,36 @@
{{>licenseInfo}}
package {{packageName}}
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
/**
* Util object for handling some cases with DateTime e.g. parsing string to DateTime object
*/
object DateFormatUtils {
enum class APIDateFormat(val formatValue: String) {
DATE_TIME_FORMAT("yyyy-MM-dd'T'HH:mm:ss.SSSZZ"),
DATE_FORMAT("yyyy-MM-dd"),
TIME_FORMAT("HH:mm:ssZ"),
{{#each apiDateFormats as |value key|}}
{{key}}("{{{value}}}")
{{/each}}
}
/**
* @return the result of parsed string value
* @param value is string value of date time in right format
* @param format is date time format for parsing string value.
* Default value is [Format.DATE_TIME_FORMAT]
* @param defaultValue is value returned in case of exception
*/
fun fromString(
value: String,
format: APIDateFormat = APIDateFormat.DATE_TIME_FORMAT,
defaultValue: DateTime? = null
): DateTime? = runCatching { value.parse(format.formatValue) }.getOrDefault(defaultValue)
private fun String.parse(format: String) = DateTimeFormat.forPattern(format).parseDateTime(this)
}

View File

@ -0,0 +1,13 @@
{{>licenseInfo}}
package {{packageName}}
import com.squareup.moshi.Moshi
{{#each enumAdaptersImports}}
import {{.}}
{{/each}}
fun Moshi.Builder.addGeneratedEnumJsonAdapters(): Moshi.Builder = this
.add(GeneratedDateAdapter())
{{#each enumAdapters}}
.add({{.}}())
{{/each}}

View File

@ -0,0 +1,32 @@
{{>licenseInfo}}
package {{packageName}}
import com.squareup.moshi.FromJson
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonReader
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.ToJson
import org.joda.time.DateTime
import {{packageName}}.DateFormatUtils.APIDateFormat
class GeneratedDateAdapter : JsonAdapter<DateTime>() {
@FromJson
override fun fromJson(reader: JsonReader): DateTime? {
val dateAsString = reader.nextString()
val date = DateFormatUtils.fromString(value = dateAsString, format = APIDateFormat.DATE_TIME_FORMAT)
?: DateFormatUtils.fromString(value = dateAsString, format = APIDateFormat.DATE_FORMAT)
?: DateFormatUtils.fromString(value = dateAsString, format = APIDateFormat.TIME_FORMAT)
{{#each apiDateFormats as |value key|}}
?: DateFormatUtils.fromString(value = dateAsString, format = APIDateFormat.{{key}})
{{/each}}
return date
}
@ToJson
override fun toJson(writer: JsonWriter, value: DateTime?) {
if (value != null) {
writer.value(value.toString())
}
}
}

View File

@ -0,0 +1,35 @@
{{>licenseInfo}}
package {{apiPackage}}
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.PUT
{{#imports}}import {{import}}
{{/imports}}
{{#jodaTime}}
import org.joda.time.DateTime
{{/jodaTime}}
{{#operations}}
interface {{classname}} {
{{#operation}}
{{#contents}}
/**
* {{summary}}
* {{notes}}
{{#parameters}} * @param {{paramName}} {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/parameters}} * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
*/{{#returnType}}
{{/returnType}}
@{{httpMethod}}("{{{path}}}")
suspend fun {{operationId}}({{#parameters}}
{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{#hasMore}},{{/hasMore}}{{/parameters}}{{#if authMethods}}{{#if parameters}},
{{/if}}{{/if}}{{#authMethods}}{{>securityParam}}{{#hasMore}},{{/hasMore}}{{/authMethods}}
): {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Unit{{/returnType}}
{{/contents}}
{{/operation}}
}
{{/operations}}

View File

@ -0,0 +1 @@
{{#is this 'body-param'}}@retrofit2.http.Body {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{/is}}

View File

@ -0,0 +1,10 @@
plugins {
id(Plugins.ANDROID_LIB_PLUGIN_WITH_DEFAULT_CONFIG)
}
dependencies {
retrofit()
coroutines()
moshi()
joda()
}

View File

@ -0,0 +1,36 @@
/**
* {{{description}}}
{{#allVars}}
* @param {{name}} {{{description}}}
{{/allVars}}
*/
@JsonClass(generateAdapter = true)
{{#hasVars}}data {{/hasVars}}class {{classname}} (
{{#allVars}}
{{#required}}{{>data_class_req_var}}{{^@last}},{{/@last}}{{/required}}{{^required}}{{>data_class_opt_var}}{{^@last}},{{/@last}}{{/required}}
{{/allVars}}
) {
{{#allVars}}
{{#isEnum}}
/**
* {{{description}}}
* Values: {{#allowableValues}}{{#enumVars}}{{&name}}{{^@last}},{{/@last}}{{/enumVars}}{{/allowableValues}}
*/
enum class {{nameInCamelCase}}(val value: {{datatype}}{{#isNullable}}?{{/isNullable}}) {
{{#allowableValues}}{{#enumVars}}
{{&name}}({{#value}}{{{value}}}{{/value}}{{^value}}null{{/value}}){{^@last}},{{/@last}}{{#@last}};{{/@last}}
{{/enumVars}}{{/allowableValues}}
class JsonAdapter {
@ToJson
fun toJson(value: {{nameInCamelCase}}?): String? = value?.value
@FromJson
fun fromJson(value: String): {{nameInCamelCase}}? = values()
.find { type -> type.value == value }
}
}
{{/isEnum}}
{{/allVars}}
}

View File

@ -0,0 +1 @@
val {{{name}}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}? = {{#defaultvalue}}{{defaultvalue}}{{/defaultvalue}}{{^defaultvalue}}null{{/defaultvalue}}

View File

@ -0,0 +1 @@
val {{{name}}}: {{#is this 'enum'}}{{datatypeWithEnum}}{{/is}}{{#isNot this 'enum'}}{{{datatype}}}{{/isNot}}

View File

@ -0,0 +1 @@
{{#is this 'header-param'}}@retrofit2.http.Header("{{baseName}}") {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{/is}}

View File

@ -0,0 +1,9 @@
/**
* {{{appName}}}
* {{{appDescription}}}
*
* {{#version}}OpenAPI spec version: {{{version}}}{{/version}}
*
* NOTE: This class is auto generated by the swagger code generator program.
* Do not edit the class manually.
*/

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="{{packageName}}" xmlns:android="http://schemas.android.com/apk/res/android">
</manifest>

View File

@ -0,0 +1,23 @@
{{>licenseInfo}}
package {{modelPackage}}
import com.squareup.moshi.JsonClass
import com.squareup.moshi.ToJson
import com.squareup.moshi.FromJson
{{#imports}}import {{import}}
{{/imports}}
{{#jodaTime}}
import org.joda.time.DateTime
{{/jodaTime}}
{{#models}}
{{#model}}
{{#is this 'alias'}}
typealias {{classname}} = {{dataType}}
{{/is}}
{{#isNot this 'alias'}}
{{#is this 'enum'}}{{>enum_class}}{{/is}}
{{#isNot this 'enum'}}{{>data_class}}{{/isNot}}
{{/isNot}}
{{/model}}
{{/models}}

View File

@ -0,0 +1 @@
{{#is this 'path-param'}}@retrofit2.http.Path("{{baseName}}") {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{/is}}

View File

@ -0,0 +1 @@
{{#is this 'query-param'}}@retrofit2.http.Query("{{baseName}}") {{paramName}}: {{{dataType}}}{{^required}}? = null{{/required}}{{/is}}

View File

@ -0,0 +1 @@
{{#isApiKey}}{{#isKeyInHeader}}@Header("{{keyParamName}}") token: String{{/isKeyInHeader}}{{/isApiKey}}

View File

@ -0,0 +1 @@
rootProject.name = '{{artifactId}}'