lenientDatetimeFormat is enabled.
+ */
+ public static final String LENIENT_DATETIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
+
+ private String basePath = "http://petstore.swagger.io/v2";
+ private boolean lenientOnJson = false;
+ private boolean debugging = false;
+ private MapparseDatetime.
+ this.lenientDatetimeFormat = true;
+
+ // Set default User-Agent.
+ setUserAgent("Swagger-Codegen/1.0.0/java");
+
+ // Setup authentications (key: authentication name, value: authentication).
+ authentications = new HashMapdateFormat supports these ISO 8601 date formats:
+ * 2015-08-16
+ * 2015-8-16
+ * @param str String to be parsed
+ * @return Date
+ */
+ public Date parseDate(String str) {
+ if (str == null)
+ return null;
+ try {
+ return dateFormat.parse(str);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Parse the given datetime string into Date object.
+ * When lenientDatetimeFormat is enabled, the following ISO 8601 datetime formats are supported:
+ * 2015-08-16T08:20:05Z
+ * 2015-8-16T8:20:05Z
+ * 2015-08-16T08:20:05+00:00
+ * 2015-08-16T08:20:05+0000
+ * 2015-08-16T08:20:05.376Z
+ * 2015-08-16T08:20:05.376+00:00
+ * 2015-08-16T08:20:05.376+00
+ * Note: The 3-digit milli-seconds is optional. Time zone is required and can be in one of
+ * these formats:
+ * Z (same with +0000)
+ * +08:00 (same with +0800)
+ * -02 (same with -0200)
+ * -0200
+ * @see ISO 8601
+ * @param str Date time string to be parsed
+ * @return Date representation of the string
+ */
+ public Date parseDatetime(String str) {
+ if (str == null)
+ return null;
+
+ DateFormat format;
+ if (lenientDatetimeFormat) {
+ /*
+ * When lenientDatetimeFormat is enabled, normalize the date string
+ * into LENIENT_DATETIME_FORMAT to support various formats
+ * defined by ISO 8601.
+ */
+ // normalize time zone
+ // trailing "Z": 2015-08-16T08:20:05Z => 2015-08-16T08:20:05+0000
+ str = str.replaceAll("[zZ]\\z", "+0000");
+ // remove colon in time zone: 2015-08-16T08:20:05+00:00 => 2015-08-16T08:20:05+0000
+ str = str.replaceAll("([+-]\\d{2}):(\\d{2})\\z", "$1$2");
+ // expand time zone: 2015-08-16T08:20:05+00 => 2015-08-16T08:20:05+0000
+ str = str.replaceAll("([+-]\\d{2})\\z", "$100");
+ // add milliseconds when missing
+ // 2015-08-16T08:20:05+0000 => 2015-08-16T08:20:05.000+0000
+ str = str.replaceAll("(:\\d{1,2})([+-]\\d{4})\\z", "$1.000$2");
+ format = new SimpleDateFormat(LENIENT_DATETIME_FORMAT);
+ } else {
+ format = this.datetimeFormat;
+ }
+
+ try {
+ return format.parse(str);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /*
+ * Parse date or date time in string format into Date object.
+ *
+ * @param str Date time string to be parsed
+ * @return Date representation of the string
+ */
+ public Date parseDateOrDatetime(String str) {
+ if (str == null)
+ return null;
+ else if (str.length() <= dateLength)
+ return parseDate(str);
+ else
+ return parseDatetime(str);
+ }
+
+ /**
+ * Format the given Date object into string (Date format).
+ *
+ * @param date Date object
+ * @return Formatted date in string representation
+ */
+ public String formatDate(Date date) {
+ return dateFormat.format(date);
+ }
+
+ /**
+ * Format the given Date object into string (Datetime format).
+ *
+ * @param date Date object
+ * @return Formatted datetime in string representation
+ */
+ public String formatDatetime(Date date) {
+ return datetimeFormat.format(date);
+ }
+
+ /**
+ * Get authentications (key: authentication name, value: authentication).
+ *
+ * @return Map of authentication objects
+ */
+ public Mapnull, i.e. using
+ * the system's default tempopary folder.
+ *
+ * @see createTempFile
+ * @return Temporary folder path
+ */
+ public String getTempFolderPath() {
+ return tempFolderPath;
+ }
+
+ /**
+ * Set the tempoaray folder path (for downloading files)
+ *
+ * @param tempFolderPath Temporary folder path
+ * @return ApiClient
+ */
+ public ApiClient setTempFolderPath(String tempFolderPath) {
+ this.tempFolderPath = tempFolderPath;
+ return this;
+ }
+
+ /**
+ * Get connection timeout (in milliseconds).
+ *
+ * @return Timeout in milliseconds
+ */
+ public int getConnectTimeout() {
+ return httpClient.getConnectTimeout();
+ }
+
+ /**
+ * Sets the connect timeout (in milliseconds).
+ * A value of 0 means no timeout, otherwise values must be between 1 and
+ *
+ * @param connectionTimeout connection timeout in milliseconds
+ * @return Api client
+ */
+ public ApiClient setConnectTimeout(int connectionTimeout) {
+ httpClient.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
+ return this;
+ }
+
+ /**
+ * Format the given parameter object into string.
+ *
+ * @param param Parameter
+ * @return String representation of the parameter
+ */
+ public String parameterToString(Object param) {
+ if (param == null) {
+ return "";
+ } else if (param instanceof Date) {
+ return formatDatetime((Date) param);
+ } else if (param instanceof Collection) {
+ StringBuilder b = new StringBuilder();
+ for (Object o : (Collection)param) {
+ if (b.length() > 0) {
+ b.append(",");
+ }
+ b.append(String.valueOf(o));
+ }
+ return b.toString();
+ } else {
+ return String.valueOf(param);
+ }
+ }
+
+ /**
+ * Format to {@code Pair} objects.
+ *
+ * @param collectionFormat collection format (e.g. csv, tsv)
+ * @param name Name
+ * @param value Value
+ * @return A list of Pair objects
+ */
+ public List+ * Note: This might be replaced by utility method from commons-lang or guava someday + * if one of those libraries is added as dependency. + *
+ * + * @param array The array of strings + * @param separator The separator + * @return the resulting string + */ + public static String join(String[] array, String separator) { + int len = array.length; + if (len == 0) return ""; + + StringBuilder out = new StringBuilder(); + out.append(array[0]); + for (int i = 1; i < len; i++) { + out.append(separator).append(array[i]); + } + return out.toString(); + } +} diff --git a/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java new file mode 100644 index 000000000000..6d956441b6fb --- /dev/null +++ b/samples/client/petstore/java/okhttp-gson/src/main/java/io/swagger/client/api/FakeApi.java @@ -0,0 +1,452 @@ +/** + * Swagger Petstore + * This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +package io.swagger.client.api; + +import io.swagger.client.ApiCallback; +import io.swagger.client.ApiClient; +import io.swagger.client.ApiException; +import io.swagger.client.ApiResponse; +import io.swagger.client.Configuration; +import io.swagger.client.Pair; +import io.swagger.client.ProgressRequestBody; +import io.swagger.client.ProgressResponseBody; + +import com.google.gson.reflect.TypeToken; + +import java.io.IOException; + +import org.joda.time.LocalDate; +import org.joda.time.DateTime; +import java.math.BigDecimal; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class FakeApi { + private ApiClient apiClient; + + public FakeApi() { + this(Configuration.getDefaultApiClient()); + } + + public FakeApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + /* Build call for testCodeInjectEnd */ + private com.squareup.okhttp.Call testCodeInjectEndCall(String testCodeInjectEnd, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException { + Object localVarPostBody = null; + + + // create path and map variables + String localVarPath = "/fake".replaceAll("\\{format\\}","json"); + + List