Skip to content

Commit de6b3ce

Browse files
committed
fix slim windows path
1 parent acc2849 commit de6b3ce

File tree

351 files changed

+33537
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

351 files changed

+33537
-6
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/SlimFrameworkServerCodegen.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,28 @@
1414
import java.util.Arrays;
1515
import java.util.HashMap;
1616
import java.util.HashSet;
17+
import java.util.regex.Matcher;
1718

1819
public class SlimFrameworkServerCodegen extends DefaultCodegen implements CodegenConfig {
1920
protected String invokerPackage;
21+
protected String srcBasePath = "lib";
2022
protected String groupId = "io.swagger";
2123
protected String artifactId = "swagger-server";
2224
protected String artifactVersion = "1.0.0";
25+
protected String packagePath = ""; // empty packagePath (top folder)
26+
27+
2328
private String variableNamingConvention = "camelCase";
2429

2530
public SlimFrameworkServerCodegen() {
2631
super();
2732

2833
invokerPackage = camelize("SwaggerServer");
2934

30-
String packagePath = "SwaggerServer";
35+
//String packagePath = "SwaggerServer";
3136

32-
modelPackage = packagePath + "\\lib\\Models";
33-
apiPackage = packagePath + "\\lib";
37+
modelPackage = packagePath + "\\Models";
38+
apiPackage = packagePath;
3439
outputFolder = "generated-code" + File.separator + "slim";
3540
modelTemplateFiles.put("model.mustache", ".php");
3641

@@ -115,12 +120,12 @@ public String escapeReservedWord(String name) {
115120

116121
@Override
117122
public String apiFileFolder() {
118-
return (outputFolder + "/" + apiPackage()).replace('/', File.separatorChar);
123+
return (outputFolder + "/" + toPackagePath(apiPackage, srcBasePath));
119124
}
120125

121126
@Override
122127
public String modelFileFolder() {
123-
return (outputFolder + "/" + modelPackage()).replace('/', File.separatorChar);
128+
return (outputFolder + "/" + toPackagePath(modelPackage, srcBasePath));
124129
}
125130

126131
@Override
@@ -225,6 +230,39 @@ public String toModelFilename(String name) {
225230
return toModelName(name);
226231
}
227232

233+
public String toPackagePath(String packageName, String basePath) {
234+
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
235+
if (basePath != null && basePath.length() > 0) {
236+
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
237+
}
238+
239+
String regFirstPathSeparator;
240+
if ("/".equals(File.separator)) { // for mac, linux
241+
regFirstPathSeparator = "^/";
242+
} else { // for windows
243+
regFirstPathSeparator = "^\\\\";
244+
}
245+
246+
String regLastPathSeparator;
247+
if ("/".equals(File.separator)) { // for mac, linux
248+
regLastPathSeparator = "/$";
249+
} else { // for windows
250+
regLastPathSeparator = "\\\\$";
251+
}
252+
253+
return (getPackagePath() + File.separatorChar + basePath
254+
// Replace period, backslash, forward slash with file separator in package name
255+
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
256+
// Trim prefix file separators from package path
257+
.replaceAll(regFirstPathSeparator, ""))
258+
// Trim trailing file separators from the overall path
259+
.replaceAll(regLastPathSeparator+ "$", "");
260+
}
261+
262+
public String getPackagePath() {
263+
return packagePath;
264+
}
265+
228266
@Override
229267
public String escapeQuotationMark(String input) {
230268
// remove ' to avoid code injection
File renamed without changes.
File renamed without changes.
File renamed without changes.

samples/server/petstore-security-test/slim/composer.lock

Lines changed: 254 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* Return
44
*/
5-
namespace SwaggerServer\lib\Models;
5+
namespace \Models;
66

77
/*
88
* Return
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php @generated by Composer
4+
5+
require_once __DIR__ . '/composer' . '/autoload_real.php';
6+
7+
return ComposerAutoloaderInita7ca9e6d69dc1fe934d8e0e81434a295::getLoader();

0 commit comments

Comments
 (0)