Thanks for choosing CommandHelper!
-Now, to begin, you want to:
-Gotcha: You need to have WorldEdit installed! It's used by CommandHelper in a number of places. If you don't want to install the plugin, that's okay — just put WorldEdit.jar into your Bukkit root folder (outside of plugins/) and CommandHelper will still be able use it. Alternatively, download the version of CommandHelper that has WorldEdit bundled in.
-Be sure to:
-CommandHelper is entirely open source! You can download all of the plugin code to learn from it, modify it for your own self, or even contribute back!
- -The code is covered under the MIT License.
-Do you like CommandHelper? I spend a lot of time working on the plugin, and donations are appreciated. Check out the link on the right
-Maven information: ${groupId}/${artifactId}/${version}
-
+ * Note: If you make changes to the object mapper, remember to set it back via
+ * setObjectMapper in order to trigger HTTP client rebuilding.
+ *
+ * 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/mustacheTemplates/api.mustache b/mustacheTemplates/api.mustache new file mode 100644 index 0000000000..d208b6856f --- /dev/null +++ b/mustacheTemplates/api.mustache @@ -0,0 +1,117 @@ +{{>licenseInfo}} +package {{package}}; + +import com.sun.jersey.api.client.GenericType; + +import {{invokerPackage}}.ApiException; +import {{invokerPackage}}.ApiClient; +import {{invokerPackage}}.Configuration; +{{#hasModel}}import {{modelPackage}}.*;{{/hasModel}} + +import {{invokerPackage}}.Pair; + +{{#imports}}import {{import}}; +{{/imports}} +{{^fullJavaUtil}} +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +{{/fullJavaUtil}} +{{>generatedAnnotation}} +{{#operations}} +public class {{classname}} { + private ApiClient {{localVariablePrefix}}apiClient; + + public {{classname}}() { + this(Configuration.getDefaultApiClient()); + } + + public {{classname}}(ApiClient apiClient) { + this.{{localVariablePrefix}}apiClient = apiClient; + } + + public ApiClient getApiClient() { + return {{localVariablePrefix}}apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.{{localVariablePrefix}}apiClient = apiClient; + } + + {{#operation}} + {{#contents}} + /** + * {{summary}} + * {{notes}} + {{#parameters}} + * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}} + {{/parameters}} + {{#returnType}} + * @return {{returnType}} + {{/returnType}} + * @throws ApiException if fails to make API call + {{#isDeprecated}} + * @deprecated + {{/isDeprecated}} + {{#externalDocs}} + * {{description}} + * @see {{summary}} Documentation + {{/externalDocs}} + */ + {{#isDeprecated}} + @Deprecated + {{/isDeprecated}} + public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}{{operationId}}({{#parameters}}{{{dataType}}} {{paramName}}{{#has this 'more'}}, {{/has}}{{/parameters}}) throws ApiException { + Object {{localVariablePrefix}}localVarPostBody = {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}; + {{#parameters}}{{#required}} + // verify the required parameter '{{paramName}}' is set + if ({{paramName}} == null) { + throw new ApiException(400, "Missing the required parameter '{{paramName}}' when calling {{operationId}}"); + } + {{/required}}{{/parameters}} + // create path and map variables + String {{localVariablePrefix}}localVarPath = "{{{path}}}"{{#pathParams}} + .replaceAll("\\{" + "{{baseName}}" + "\\}", {{localVariablePrefix}}apiClient.escapeString({{{paramName}}}.toString())){{/pathParams}}; + + // query params + {{javaUtilPrefix}}ListEncodes a collection of query parameters according to the Swagger + * collection format.
+ * + *Of the various collection formats defined by Swagger ("csv", "tsv", + * etc), Feign only natively supports "multi". This utility generates the + * other format types so it will be properly processed by Feign.
+ * + *Note, as part of reformatting, it URL encodes the parameters as + * well.
+ * @param parameters The collection object to be formatted. This object will + * not be changed. + * @param collectionFormat The Swagger collection format (eg, "csv", "tsv", + * "pipes"). See the + * + * Swagger Spec for more details. + * @return An object that will be correctly formatted by Feign. + */ + public static Object encodeCollection(Collection> parameters, + String collectionFormat) { + if (parameters == null) { + return parameters; + } + List{{operationId}} method,
+ * but with the query parameters collected into a single Map parameter. This
+ * is convenient for services with optional query parameters, especially when
+ * used with the {@link {{operationIdCamelCase}}QueryParams} class that allows for
+ * building up this map in a fluent style.
+ {{#parameters}}
+ {{#isNot this 'query-param'}}
+ * @param {{paramName}} {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
+ {{/isNot}}
+ {{/parameters}}
+ * @param queryParams Map of query parameters as name-value pairs
+ * The following elements may be specified in the query map:
+ *{{operationId}} method in a fluent style.
+ */
+ public static class {{operationIdCamelCase}}QueryParams extends HashMapnull, i.e. using
+ * the system's default tempopary folder.
+ *
+ * @return Temp folder path
+ */
+ public String getTempFolderPath() {
+ return tempFolderPath;
+ }
+
+ /**
+ * Set temp folder path
+ * @param tempFolderPath Temp folder path
+ * @return API client
+ */
+ public ApiClient setTempFolderPath(String tempFolderPath) {
+ this.tempFolderPath = tempFolderPath;
+ return this;
+ }
+
+ /**
+ * Connect timeout (in milliseconds).
+ * @return Connection timeout
+ */
+ public int getConnectTimeout() {
+ return connectionTimeout;
+ }
+
+ /**
+ * Set the connect timeout (in milliseconds).
+ * A value of 0 means no timeout, otherwise values must be between 1 and
+ * {@link Integer#MAX_VALUE}.
+ * @param connectionTimeout Connection timeout in milliseconds
+ * @return API client
+ */
+ public ApiClient setConnectTimeout(int connectionTimeout) {
+ this.connectionTimeout = connectionTimeout;
+ httpClient.property(ClientProperties.CONNECT_TIMEOUT, connectionTimeout);
+ return this;
+ }
+
+ /**
+ * read timeout (in milliseconds).
+ * @return Read timeout
+ */
+ public int getReadTimeout() {
+ return readTimeout;
+ }
+
+ /**
+ * Set the read timeout (in milliseconds).
+ * A value of 0 means no timeout, otherwise values must be between 1 and
+ * {@link Integer#MAX_VALUE}.
+ * @param readTimeout Read timeout in milliseconds
+ * @return API client
+ */
+ public ApiClient setReadTimeout(int readTimeout) {
+ this.readTimeout = readTimeout;
+ httpClient.property(ClientProperties.READ_TIMEOUT, readTimeout);
+ return this;
+ }
+
+ /**
+ * Get the date format used to parse/format date parameters.
+ * @return Date format
+ */
+ public DateFormat getDateFormat() {
+ return dateFormat;
+ }
+
+ /**
+ * Set the date format used to parse/format date parameters.
+ * @param dateFormat Date format
+ * @return API client
+ */
+ public ApiClient setDateFormat(DateFormat dateFormat) {
+ this.dateFormat = dateFormat;
+ // also set the date format for model (de)serialization with Date properties
+ this.json.setDateFormat((DateFormat) dateFormat.clone());
+ return this;
+ }
+
+ /**
+ * Parse the given string into Date object.
+ * @param str String
+ * @return Date
+ */
+ public Date parseDate(String str) {
+ try {
+ return dateFormat.parse(str);
+ } catch (java.text.ParseException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Format the given Date object into string.
+ * @param date Date
+ * @return Date in string format
+ */
+ public String formatDate(Date date) {
+ return dateFormat.format(date);
+ }
+
+ /**
+ * Format the given parameter object into string.
+ * @param param Object
+ * @return Object in string format
+ */
+ public String parameterToString(Object param) {
+ if (param == null) {
+ return "";
+ } else if (param instanceof Date) {
+ return formatDate((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
+ * @param name Name
+ * @param value Value
+ * @return List of pairs
+ */
+ public List