forked from loafle/openapi-generator-original
minor formatting change (#7503)
This commit is contained in:
parent
7b1563326a
commit
5dffbabc74
@ -40,10 +40,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.*;
|
|
||||||
import java.util.Map.Entry;
|
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.camelize;
|
||||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||||
|
|
||||||
@ -260,10 +260,10 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
if (StringUtils.isEmpty(System.getenv("RUST_POST_PROCESS_FILE"))) {
|
if (StringUtils.isEmpty(System.getenv("RUST_POST_PROCESS_FILE"))) {
|
||||||
LOGGER.info("Environment variable RUST_POST_PROCESS_FILE not defined. rustfmt will be used" +
|
LOGGER.info("Environment variable RUST_POST_PROCESS_FILE not defined. rustfmt will be used" +
|
||||||
" by default. To choose a different tool, try" +
|
" by default. To choose a different tool, try" +
|
||||||
" 'export RUST_POST_PROCESS_FILE=\"/usr/local/bin/rustfmt\"' (Linux/Mac)");
|
" '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` " +
|
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())) {
|
if (!Boolean.TRUE.equals(ModelUtils.isGenerateAliasAsModel())) {
|
||||||
@ -311,7 +311,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
* to select the library with the -g flag.
|
||||||
*
|
*
|
||||||
* @return the friendly name for the generator
|
* @return the friendly name for the generator
|
||||||
@ -329,7 +329,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String getHelp() {
|
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
|
@Override
|
||||||
@ -557,14 +557,14 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
private boolean isMimetypeXml(String mimetype) {
|
private boolean isMimetypeXml(String mimetype) {
|
||||||
return mimetype.toLowerCase(Locale.ROOT).startsWith(xmlMimeType) ||
|
return mimetype.toLowerCase(Locale.ROOT).startsWith(xmlMimeType) ||
|
||||||
mimetype.toLowerCase(Locale.ROOT).startsWith(problemXmlMimeType) ||
|
mimetype.toLowerCase(Locale.ROOT).startsWith(problemXmlMimeType) ||
|
||||||
mimetype.toLowerCase(Locale.ROOT).startsWith(textXmlMimeType);
|
mimetype.toLowerCase(Locale.ROOT).startsWith(textXmlMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMimetypeJson(String mimetype) {
|
private boolean isMimetypeJson(String mimetype) {
|
||||||
return mimetype.toLowerCase(Locale.ROOT).startsWith(jsonMimeType) ||
|
return mimetype.toLowerCase(Locale.ROOT).startsWith(jsonMimeType) ||
|
||||||
mimetype.toLowerCase(Locale.ROOT).startsWith(mergePatchJsonMimeType) ||
|
mimetype.toLowerCase(Locale.ROOT).startsWith(mergePatchJsonMimeType) ||
|
||||||
mimetype.toLowerCase(Locale.ROOT).startsWith(problemJsonMimeType);
|
mimetype.toLowerCase(Locale.ROOT).startsWith(problemJsonMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isMimetypeWwwFormUrlEncoded(String mimetype) {
|
private boolean isMimetypeWwwFormUrlEncoded(String mimetype) {
|
||||||
@ -592,11 +592,11 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
*/
|
*/
|
||||||
boolean isMimetypePlain(String mimetype) {
|
boolean isMimetypePlain(String mimetype) {
|
||||||
boolean result = !(isMimetypeUnknown(mimetype) ||
|
boolean result = !(isMimetypeUnknown(mimetype) ||
|
||||||
isMimetypeXml(mimetype) ||
|
isMimetypeXml(mimetype) ||
|
||||||
isMimetypeJson(mimetype) ||
|
isMimetypeJson(mimetype) ||
|
||||||
isMimetypeWwwFormUrlEncoded(mimetype) ||
|
isMimetypeWwwFormUrlEncoded(mimetype) ||
|
||||||
isMimetypeMultipartFormData(mimetype) ||
|
isMimetypeMultipartFormData(mimetype) ||
|
||||||
isMimetypeMultipartRelated(mimetype));
|
isMimetypeMultipartRelated(mimetype));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -635,9 +635,9 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// The callback API is logically distinct from the main API, so
|
// The callback API is logically distinct from the main API, so
|
||||||
// it uses a separate path set map.
|
// it uses a separate path set map.
|
||||||
if (op.isCallbackRequest) {
|
if (op.isCallbackRequest) {
|
||||||
pathSetMap = this.callbacksPathSetMap;
|
pathSetMap = this.callbacksPathSetMap;
|
||||||
} else {
|
} else {
|
||||||
pathSetMap = this.pathSetMap;
|
pathSetMap = this.pathSetMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (pathSetMap.containsKey(pathId)) {
|
while (pathSetMap.containsKey(pathId)) {
|
||||||
@ -735,7 +735,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
op.vendorExtensions.put("x-operation-id", underscoredOperationId);
|
op.vendorExtensions.put("x-operation-id", underscoredOperationId);
|
||||||
op.vendorExtensions.put("x-uppercase-operation-id", underscoredOperationId.toUpperCase(Locale.ROOT));
|
op.vendorExtensions.put("x-uppercase-operation-id", underscoredOperationId.toUpperCase(Locale.ROOT));
|
||||||
String vendorExtensionPath = op.path.replace("{", ":").replace("}", "");
|
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-path-id", pathId);
|
||||||
op.vendorExtensions.put("x-has-path-params", hasPathParams);
|
op.vendorExtensions.put("x-has-path-params", hasPathParams);
|
||||||
op.vendorExtensions.put("x-path-format-string", formatPath);
|
op.vendorExtensions.put("x-path-format-string", formatPath);
|
||||||
@ -744,8 +744,8 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
op.vendorExtensions.put("x-http-method", vendorExtensionHttpMethod);
|
op.vendorExtensions.put("x-http-method", vendorExtensionHttpMethod);
|
||||||
|
|
||||||
if (!op.vendorExtensions.containsKey("x-must-use-response")) {
|
if (!op.vendorExtensions.containsKey("x-must-use-response")) {
|
||||||
// If there's more than one response, than by default the user must explicitly handle them
|
// 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);
|
op.vendorExtensions.put("x-must-use-response", op.responses.size() > 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (CodegenParameter param : op.allParams) {
|
for (CodegenParameter param : op.allParams) {
|
||||||
@ -1300,23 +1300,23 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// If we have callbacks, add the callbacks module, otherwise remove it
|
// If we have callbacks, add the callbacks module, otherwise remove it
|
||||||
boolean hasCallbacks = haveCallbacks(bundle);
|
boolean hasCallbacks = haveCallbacks(bundle);
|
||||||
bundle.put("hasCallbacks", hasCallbacks);
|
bundle.put("hasCallbacks", hasCallbacks);
|
||||||
SupportingFile[] callbackFiles = new SupportingFile[] {
|
SupportingFile[] callbackFiles = new SupportingFile[]{
|
||||||
new SupportingFile("client-callbacks.mustache", "src/client", "callbacks.rs"),
|
new SupportingFile("client-callbacks.mustache", "src/client", "callbacks.rs"),
|
||||||
new SupportingFile("server-callbacks.mustache", "src/server", "callbacks.rs"),
|
new SupportingFile("server-callbacks.mustache", "src/server", "callbacks.rs"),
|
||||||
new SupportingFile("example-client-server.mustache", "examples/client", "server.rs")
|
new SupportingFile("example-client-server.mustache", "examples/client", "server.rs")
|
||||||
};
|
};
|
||||||
for (SupportingFile callbackFile : callbackFiles) {
|
for (SupportingFile callbackFile : callbackFiles) {
|
||||||
if (hasCallbacks) {
|
if (hasCallbacks) {
|
||||||
supportingFiles.add(callbackFile);
|
supportingFiles.add(callbackFile);
|
||||||
} else {
|
} else {
|
||||||
supportingFiles.remove(callbackFile);
|
supportingFiles.remove(callbackFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasCallbacks) {
|
if (hasCallbacks) {
|
||||||
Map<String, Object> callbackData = new HashMap();
|
Map<String, Object> callbackData = new HashMap();
|
||||||
addPathSetMapToBundle(callbacksPathSetMap, callbackData);
|
addPathSetMapToBundle(callbacksPathSetMap, callbackData);
|
||||||
bundle.put("callbacks", callbackData);
|
bundle.put("callbacks", callbackData);
|
||||||
}
|
}
|
||||||
|
|
||||||
return super.postProcessSupportingFileData(bundle);
|
return super.postProcessSupportingFileData(bundle);
|
||||||
@ -1326,7 +1326,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
* Add a built path set map to the provided bundle
|
* Add a built path set map to the provided bundle
|
||||||
*
|
*
|
||||||
* @param pathSetMap A previously built path set map
|
* @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) {
|
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
|
// We previously built a mapping from path to path ID and regular
|
||||||
@ -1544,9 +1544,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// the user than the alternative.
|
// the user than the alternative.
|
||||||
LOGGER.warn("Ignoring additionalProperties (see https://github.com/OpenAPITools/openapi-generator/issues/318) alongside defined properties");
|
LOGGER.warn("Ignoring additionalProperties (see https://github.com/OpenAPITools/openapi-generator/issues/318) alongside defined properties");
|
||||||
cm.dataType = null;
|
cm.dataType = null;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
cm.dataType = "std::collections::HashMap<String, " + cm.additionalPropertiesType + ">";
|
cm.dataType = "std::collections::HashMap<String, " + cm.additionalPropertiesType + ">";
|
||||||
}
|
}
|
||||||
} else if (cm.dataType != null) {
|
} else if (cm.dataType != null) {
|
||||||
@ -1635,7 +1633,7 @@ public class RustServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// only process files with .rs extension
|
// only process files with .rs extension
|
||||||
if ("rs".equals(FilenameUtils.getExtension(file.toString()))) {
|
if ("rs".equals(FilenameUtils.getExtension(file.toString()))) {
|
||||||
try {
|
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();
|
int exitValue = p.waitFor();
|
||||||
if (exitValue != 0) {
|
if (exitValue != 0) {
|
||||||
LOGGER.error("Error running the command ({} {}). Exit code: {}", commandPrefix, file.toString(), exitValue);
|
LOGGER.error("Error running the command ({} {}). Exit code: {}", commandPrefix, file.toString(), exitValue);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user