Skip to content

Commit 9873953

Browse files
committed
2 parents 183af97 + 40e4970 commit 9873953

File tree

392 files changed

+36690
-17
lines changed

Some content is hidden

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

392 files changed

+36690
-17
lines changed

bin/security/csharp-petstore.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l csharp -o samples/client/petstore-security-test/csharp/SwaggerClient"
30+
31+
java $JAVA_OPTS -jar $executable $ags
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
SCRIPT="$0"
4+
5+
while [ -h "$SCRIPT" ] ; do
6+
ls=`ls -ld "$SCRIPT"`
7+
link=`expr "$ls" : '.*-> \(.*\)$'`
8+
if expr "$link" : '/.*' > /dev/null; then
9+
SCRIPT="$link"
10+
else
11+
SCRIPT=`dirname "$SCRIPT"`/"$link"
12+
fi
13+
done
14+
15+
if [ ! -d "${APP_DIR}" ]; then
16+
APP_DIR=`dirname "$SCRIPT"`/..
17+
APP_DIR=`cd "${APP_DIR}"; pwd`
18+
fi
19+
20+
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
21+
22+
if [ ! -f "$executable" ]
23+
then
24+
mvn clean package
25+
fi
26+
27+
# if you've executed sbt assembly previously it will use that instead.
28+
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
29+
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l javascript-closure-angular -o samples/client/petstore-security-test/javascript-closure-angular"
30+
31+
java $JAVA_OPTS -jar $executable $ags

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,4 +656,16 @@ public String toEnumName(CodegenProperty property) {
656656
public String testPackageName() {
657657
return this.packageName + ".Test";
658658
}
659+
660+
@Override
661+
public String escapeQuotationMark(String input) {
662+
// remove " to avoid code injection
663+
return input.replace("\"", "");
664+
}
665+
666+
@Override
667+
public String escapeUnsafeCharacters(String input) {
668+
return input.replace("*/", "");
669+
}
670+
659671
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ public String modelFileFolder() {
104104

105105
@Override
106106
public String toVarName(String name) {
107+
// sanitize name
108+
name = sanitizeName(name);
109+
107110
// replace - with _ e.g. created-at => created_at
108111
name = name.replaceAll("-", "_");
109112

@@ -224,4 +227,34 @@ public int compare(Map<String, String> o1, Map<String, String> o2) {
224227
return objs;
225228
}
226229

230+
@Override
231+
public String toOperationId(String operationId) {
232+
// throw exception if method name is empty
233+
if (StringUtils.isEmpty(operationId)) {
234+
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
235+
}
236+
237+
operationId = camelize(sanitizeName(operationId), true);
238+
239+
// method name cannot use reserved keyword, e.g. return
240+
if (isReservedWord(operationId)) {
241+
String newOperationId = camelize("call_" + operationId, true);
242+
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
243+
return newOperationId;
244+
}
245+
246+
return operationId;
247+
}
248+
249+
@Override
250+
public String escapeQuotationMark(String input) {
251+
// remove ', " to avoid code injection
252+
return input.replace("\"", "").replace("'", "");
253+
}
254+
255+
@Override
256+
public String escapeUnsafeCharacters(String input) {
257+
return input.replace("*/", "");
258+
}
259+
227260
}

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

modules/swagger-codegen/src/main/resources/aspnet5/controller.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace {{packageName}}.Controllers
1616
/// <summary>
1717
/// {{description}}
1818
/// </summary>{{#description}}{{#basePath}}
19-
[Route("{{basePath}}")]
19+
[Route("{{{basePath}}}")]
2020
{{/basePath}}[Description("{{description}}")]{{/description}}
2121
public class {{classname}}Controller : Controller
2222
{ {{#operation}}

modules/swagger-codegen/src/main/resources/csharp/ApiClient.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ namespace {{packageName}}.Client
4141

4242
/// <summary>
4343
/// Initializes a new instance of the <see cref="ApiClient" /> class
44-
/// with default configuration and base path ({{basePath}}).
44+
/// with default configuration and base path ({{{basePath}}}).
4545
/// </summary>
4646
public ApiClient()
4747
{
4848
Configuration = Configuration.Default;
49-
RestClient = new RestClient("{{basePath}}");
49+
RestClient = new RestClient("{{{basePath}}}");
5050
}
5151

5252
/// <summary>
5353
/// Initializes a new instance of the <see cref="ApiClient" /> class
54-
/// with default base path ({{basePath}}).
54+
/// with default base path ({{{basePath}}}).
5555
/// </summary>
5656
/// <param name="config">An instance of Configuration.</param>
5757
public ApiClient(Configuration config = null)
@@ -61,15 +61,15 @@ namespace {{packageName}}.Client
6161
else
6262
Configuration = config;
6363
64-
RestClient = new RestClient("{{basePath}}");
64+
RestClient = new RestClient("{{{basePath}}}");
6565
}
6666

6767
/// <summary>
6868
/// Initializes a new instance of the <see cref="ApiClient" /> class
6969
/// with default configuration.
7070
/// </summary>
7171
/// <param name="basePath">The base path.</param>
72-
public ApiClient(String basePath = "{{basePath}}")
72+
public ApiClient(String basePath = "{{{basePath}}}")
7373
{
7474
if (String.IsNullOrEmpty(basePath))
7575
throw new ArgumentException("basePath cannot be empty");

modules/swagger-codegen/src/main/resources/csharp/Configuration.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,16 @@ namespace {{packageName}}.Client
281281
/// </summary>
282282
public static String ToDebugReport()
283283
{
284-
String report = "C# SDK ({{packageName}}) Debug Report:\n";
284+
String report = "C# SDK ({{{packageName}}}) Debug Report:\n";
285285
{{^supportsUWP}}
286286
report += " OS: " + Environment.OSVersion + "\n";
287287
report += " .NET Framework Version: " + Assembly
288288
.GetExecutingAssembly()
289289
.GetReferencedAssemblies()
290290
.Where(x => x.Name == "System.Core").First().Version.ToString() + "\n";
291291
{{/supportsUWP}}
292-
report += " Version of the API: {{version}}\n";
293-
report += " SDK Package Version: {{packageVersion}}\n";
292+
report += " Version of the API: {{{version}}}\n";
293+
report += " SDK Package Version: {{{packageVersion}}}\n";
294294

295295
return report;
296296
}

modules/swagger-codegen/src/main/resources/csharp/README.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace Example
107107

108108
## Documentation for API Endpoints
109109

110-
All URIs are relative to *{{basePath}}*
110+
All URIs are relative to *{{{basePath}}}*
111111

112112
Class | Method | HTTP request | Description
113113
------------ | ------------- | ------------- | -------------

modules/swagger-codegen/src/main/resources/csharp/api_doc.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# {{packageName}}.Api.{{classname}}{{#description}}
22
{{description}}{{/description}}
33

4-
All URIs are relative to *{{basePath}}*
4+
All URIs are relative to *{{{basePath}}}*
55

66
Method | HTTP request | Description
77
------------- | ------------- | -------------

0 commit comments

Comments
 (0)