mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-18 08:49:10 +00:00
Fix regexp error on php-slim (#2604)
* Add tests to reproduce the issue * Use simple replacement instead of regexp * Add tests to reproduce the issue (apiPackage) * Use simple replacement instead of regexp (apiPackage) * Replace a slash with File.separator (addressing the issue on windows) * Tweak (windows) * Tweak (windows) * Use StringUtils#remove***() instead of regexp
This commit is contained in:
@@ -632,19 +632,19 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
public String apiFileFolder() {
|
||||
return outputFolder + "/" + apiPackage().replace('.', '/');
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + "/" + modelPackage().replace('.', '/');
|
||||
return outputFolder + File.separator + modelPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String apiTestFileFolder() {
|
||||
return outputFolder + "/" + testPackage().replace('.', '/');
|
||||
return outputFolder + File.separator + testPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String modelTestFileFolder() {
|
||||
return outputFolder + "/" + testPackage().replace('.', '/');
|
||||
return outputFolder + File.separator + testPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
public String apiDocFileFolder() {
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.slf4j.LoggerFactory;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.openapitools.codegen.utils.StringUtils.camelize;
|
||||
import static org.openapitools.codegen.utils.StringUtils.underscore;
|
||||
@@ -225,16 +226,18 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
public String toSrcPath(String packageName, String basePath) {
|
||||
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (basePath != null && basePath.length() > 0) {
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + '/'; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separator; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
}
|
||||
|
||||
return (basePath
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/"))
|
||||
// Trim prefix file separators from package path
|
||||
.replaceAll("^/", ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll("/$", "");
|
||||
// Trim prefix file separators from package path
|
||||
String packagePath = StringUtils.removeStart(
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement("/")),
|
||||
File.separator
|
||||
);
|
||||
|
||||
// Trim trailing file separators from the overall path
|
||||
return StringUtils.removeEnd(basePath + packagePath, File.separator);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.security.SecurityScheme;
|
||||
import io.swagger.v3.oas.models.servers.Server;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -94,18 +95,18 @@ public class PhpSlimServerCodegen extends AbstractPhpCodegen {
|
||||
|
||||
@Override
|
||||
public String apiFileFolder() {
|
||||
if (apiPackage.matches("^" + invokerPackage + "\\\\*(.+)")) {
|
||||
if (apiPackage.startsWith(invokerPackage + "\\")) {
|
||||
// need to strip out invokerPackage from path
|
||||
return (outputFolder + File.separator + toSrcPath(apiPackage.replaceFirst("^" + invokerPackage + "\\\\*(.+)", "$1"), srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(StringUtils.removeStart(apiPackage, invokerPackage + "\\"), srcBasePath));
|
||||
}
|
||||
return (outputFolder + File.separator + toSrcPath(apiPackage, srcBasePath));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String modelFileFolder() {
|
||||
if (modelPackage.matches("^" + invokerPackage + "\\\\*(.+)")) {
|
||||
if (modelPackage.startsWith(invokerPackage + "\\")) {
|
||||
// need to strip out invokerPackage from path
|
||||
return (outputFolder + File.separator + toSrcPath(modelPackage.replaceFirst("^" + invokerPackage + "\\\\*(.+)", "$1"), srcBasePath));
|
||||
return (outputFolder + File.separator + toSrcPath(StringUtils.removeStart(modelPackage, invokerPackage + "\\"), srcBasePath));
|
||||
}
|
||||
return (outputFolder + File.separator + toSrcPath(modelPackage, srcBasePath));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user