Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
import java.io.File;
import java.net.URL;
import java.util.*;
import java.util.regex.*;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.openapitools.codegen.utils.OnceLogger.once;
import static org.openapitools.codegen.utils.StringUtils.camelize;
import static org.openapitools.codegen.utils.StringUtils.underscore;

Expand Down Expand Up @@ -260,10 +260,10 @@ public void processOpts() {

if (StringUtils.isEmpty(System.getenv("RUST_POST_PROCESS_FILE"))) {
LOGGER.info("Environment variable RUST_POST_PROCESS_FILE not defined. rustfmt will be used" +
" by default. To choose a different tool, try" +
" 'export RUST_POST_PROCESS_FILE=\"/usr/local/bin/rustfmt\"' (Linux/Mac)");
" by default. To choose a different tool, try" +
" 'export RUST_POST_PROCESS_FILE=\"/usr/local/bin/rustfmt\"' (Linux/Mac)");
LOGGER.info("NOTE: To enable file post-processing, 'enablePostProcessFile' must be set to `true` " +
" (--enable-post-process-file for CLI).");
" (--enable-post-process-file for CLI).");
}

if (!Boolean.TRUE.equals(ModelUtils.isGenerateAliasAsModel())) {
Expand Down Expand Up @@ -311,7 +311,7 @@ public CodegenType getTag() {
}

/**
* Configures a friendly name for the generator. This will be used by the generator
* Configures a friendly name for the generator. This will be used by the generator
* to select the library with the -g flag.
*
* @return the friendly name for the generator
Expand All @@ -329,7 +329,7 @@ public String getName() {
*/
@Override
public String getHelp() {
return "Generates a Rust client/server library (beta) using the swagger-codegen project.";
return "Generates a Rust client/server library (beta) using the openapi-generator project.";
}

@Override
Expand Down Expand Up @@ -557,14 +557,14 @@ public String escapeUnsafeCharacters(String input) {

private boolean isMimetypeXml(String mimetype) {
return mimetype.toLowerCase(Locale.ROOT).startsWith(xmlMimeType) ||
mimetype.toLowerCase(Locale.ROOT).startsWith(problemXmlMimeType) ||
mimetype.toLowerCase(Locale.ROOT).startsWith(textXmlMimeType);
mimetype.toLowerCase(Locale.ROOT).startsWith(problemXmlMimeType) ||
mimetype.toLowerCase(Locale.ROOT).startsWith(textXmlMimeType);
}

private boolean isMimetypeJson(String mimetype) {
return mimetype.toLowerCase(Locale.ROOT).startsWith(jsonMimeType) ||
mimetype.toLowerCase(Locale.ROOT).startsWith(mergePatchJsonMimeType) ||
mimetype.toLowerCase(Locale.ROOT).startsWith(problemJsonMimeType);
mimetype.toLowerCase(Locale.ROOT).startsWith(mergePatchJsonMimeType) ||
mimetype.toLowerCase(Locale.ROOT).startsWith(problemJsonMimeType);
}

private boolean isMimetypeWwwFormUrlEncoded(String mimetype) {
Expand Down Expand Up @@ -592,11 +592,11 @@ private boolean isMimetypeUnknown(String mimetype) {
*/
boolean isMimetypePlain(String mimetype) {
boolean result = !(isMimetypeUnknown(mimetype) ||
isMimetypeXml(mimetype) ||
isMimetypeJson(mimetype) ||
isMimetypeWwwFormUrlEncoded(mimetype) ||
isMimetypeMultipartFormData(mimetype) ||
isMimetypeMultipartRelated(mimetype));
isMimetypeXml(mimetype) ||
isMimetypeJson(mimetype) ||
isMimetypeWwwFormUrlEncoded(mimetype) ||
isMimetypeMultipartFormData(mimetype) ||
isMimetypeMultipartRelated(mimetype));
return result;
}

Expand Down Expand Up @@ -635,9 +635,9 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
// The callback API is logically distinct from the main API, so
// it uses a separate path set map.
if (op.isCallbackRequest) {
pathSetMap = this.callbacksPathSetMap;
pathSetMap = this.callbacksPathSetMap;
} else {
pathSetMap = this.pathSetMap;
pathSetMap = this.pathSetMap;
}

while (pathSetMap.containsKey(pathId)) {
Expand Down Expand Up @@ -735,7 +735,7 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
op.vendorExtensions.put("x-operation-id", underscoredOperationId);
op.vendorExtensions.put("x-uppercase-operation-id", underscoredOperationId.toUpperCase(Locale.ROOT));
String vendorExtensionPath = op.path.replace("{", ":").replace("}", "");
op.vendorExtensions.put("x-path",vendorExtensionPath);
op.vendorExtensions.put("x-path", vendorExtensionPath);
op.vendorExtensions.put("x-path-id", pathId);
op.vendorExtensions.put("x-has-path-params", hasPathParams);
op.vendorExtensions.put("x-path-format-string", formatPath);
Expand All @@ -744,8 +744,8 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
op.vendorExtensions.put("x-http-method", vendorExtensionHttpMethod);

if (!op.vendorExtensions.containsKey("x-must-use-response")) {
// If there's more than one response, than by default the user must explicitly handle them
op.vendorExtensions.put("x-must-use-response", op.responses.size() > 1);
// If there's more than one response, than by default the user must explicitly handle them
op.vendorExtensions.put("x-must-use-response", op.responses.size() > 1);
}

for (CodegenParameter param : op.allParams) {
Expand Down Expand Up @@ -1300,23 +1300,23 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> bun
// If we have callbacks, add the callbacks module, otherwise remove it
boolean hasCallbacks = haveCallbacks(bundle);
bundle.put("hasCallbacks", hasCallbacks);
SupportingFile[] callbackFiles = new SupportingFile[] {
new SupportingFile("client-callbacks.mustache", "src/client", "callbacks.rs"),
new SupportingFile("server-callbacks.mustache", "src/server", "callbacks.rs"),
new SupportingFile("example-client-server.mustache", "examples/client", "server.rs")
SupportingFile[] callbackFiles = new SupportingFile[]{
new SupportingFile("client-callbacks.mustache", "src/client", "callbacks.rs"),
new SupportingFile("server-callbacks.mustache", "src/server", "callbacks.rs"),
new SupportingFile("example-client-server.mustache", "examples/client", "server.rs")
};
for (SupportingFile callbackFile : callbackFiles) {
if (hasCallbacks) {
supportingFiles.add(callbackFile);
} else {
supportingFiles.remove(callbackFile);
}
if (hasCallbacks) {
supportingFiles.add(callbackFile);
} else {
supportingFiles.remove(callbackFile);
}
}

if (hasCallbacks) {
Map<String, Object> callbackData = new HashMap();
addPathSetMapToBundle(callbacksPathSetMap, callbackData);
bundle.put("callbacks", callbackData);
Map<String, Object> callbackData = new HashMap();
addPathSetMapToBundle(callbacksPathSetMap, callbackData);
bundle.put("callbacks", callbackData);
}

return super.postProcessSupportingFileData(bundle);
Expand All @@ -1326,7 +1326,7 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> bun
* Add a built path set map to the provided bundle
*
* @param pathSetMap A previously built path set map
* @param bundle Bundle for the supporting files to add the data to.
* @param bundle Bundle for the supporting files to add the data to.
*/
private static void addPathSetMapToBundle(Map<String, Map<String, String>> pathSetMap, Map<String, Object> bundle) {
// We previously built a mapping from path to path ID and regular
Expand Down Expand Up @@ -1544,9 +1544,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
// the user than the alternative.
LOGGER.warn("Ignoring additionalProperties (see https://github.com/OpenAPITools/openapi-generator/issues/318) alongside defined properties");
cm.dataType = null;
}
else
{
} else {
cm.dataType = "std::collections::HashMap<String, " + cm.additionalPropertiesType + ">";
}
} else if (cm.dataType != null) {
Expand Down Expand Up @@ -1635,7 +1633,7 @@ public void postProcessFile(File file, String fileType) {
// only process files with .rs extension
if ("rs".equals(FilenameUtils.getExtension(file.toString()))) {
try {
Process p = Runtime.getRuntime().exec(new String[] {commandPrefix, file.toString()});
Process p = Runtime.getRuntime().exec(new String[]{commandPrefix, file.toString()});
int exitValue = p.waitFor();
if (exitValue != 0) {
LOGGER.error("Error running the command ({} {}). Exit code: {}", commandPrefix, file.toString(), exitValue);
Expand Down