-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from swagger-api/dotnet
fix csharp client
- Loading branch information
Showing
10 changed files
with
364 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/io/swagger/codegen/v3/generators/handlebars/csharp/CsharpHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.swagger.codegen.v3.generators.handlebars.csharp; | ||
|
||
public class CsharpHelper { | ||
|
||
public CharSequence backslash() { | ||
return "\\"; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
src/main/java/io/swagger/codegen/v3/generators/handlebars/lambda/CamelCaseLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package io.swagger.codegen.v3.generators.handlebars.lambda; | ||
|
||
import com.github.jknack.handlebars.Lambda; | ||
import io.swagger.codegen.v3.CodegenConfig; | ||
import io.swagger.codegen.v3.generators.DefaultCodegenConfig; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Converts text in a fragment to camelCase. | ||
* | ||
* Register: | ||
* <pre> | ||
* additionalProperties.put("camelcase", new CamelCaseLambda()); | ||
* </pre> | ||
* | ||
* Use: | ||
* <pre> | ||
* {{#camelcase}}{{name}}{{/camelcase}} | ||
* </pre> | ||
*/ | ||
public class CamelCaseLambda implements Lambda { | ||
|
||
private CodegenConfig generator = null; | ||
private Boolean escapeParam = false; | ||
|
||
public CamelCaseLambda() { | ||
|
||
} | ||
|
||
public CamelCaseLambda generator(final CodegenConfig generator) { | ||
this.generator = generator; | ||
return this; | ||
} | ||
|
||
public CamelCaseLambda escapeAsParamName(final Boolean escape) { | ||
this.escapeParam = escape; | ||
return this; | ||
} | ||
@Override | ||
public Object apply(Object o, com.github.jknack.handlebars.Template template) throws IOException { | ||
String executed = template.apply(o); | ||
String text = DefaultCodegenConfig.camelize(executed, true); | ||
if (generator != null) { | ||
text = generator.sanitizeName(text); | ||
if (generator.reservedWords().contains(text)) { | ||
// Escaping must be done *after* camelize, because generators may escape using characters removed by camelize function. | ||
text = generator.escapeReservedWord(text); | ||
} | ||
|
||
if (escapeParam) { | ||
// NOTE: many generators call escapeReservedWord in toParamName, but we can't assume that's always the case. | ||
// Here, we'll have to accept that we may be duplicating some work. | ||
text = generator.toParamName(text); | ||
} | ||
} | ||
return text; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
src/main/java/io/swagger/codegen/v3/generators/handlebars/lambda/IndentedLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package io.swagger.codegen.v3.generators.handlebars.lambda; | ||
|
||
import com.github.jknack.handlebars.Lambda; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* This naively prepends indention to all lines of a fragment. | ||
* <p> | ||
* Generator authors may add helpers for explicitly adding prefixed spaces which fragments won't be aware of. | ||
* <p> | ||
* Register: | ||
* <pre> | ||
* additionalProperties.put("indent4", new IndentedLambda(4)); | ||
* additionalProperties.put("indent8", new IndentedLambda(8)); | ||
* </pre> | ||
* <p> | ||
* Use: | ||
* <pre>{@code | ||
* {{#indent4}}{{>template}}{{/indent4}} | ||
* {{#indent8}}{{>other_template}}{{/indent8}} | ||
* }</pre> | ||
*/ | ||
public class IndentedLambda implements Lambda { | ||
private final int prefixSpaceCount; | ||
private int spaceCode; | ||
|
||
/** | ||
* Constructs a new instance of {@link io.swagger.codegen.mustache.IndentedLambda}, with an indent count of 4 spaces | ||
*/ | ||
public IndentedLambda() { | ||
this(4, " "); | ||
} | ||
|
||
/** | ||
* Constructs a new instance of {@link io.swagger.codegen.mustache.IndentedLambda}, with customized indent count and intention character | ||
* | ||
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment. | ||
* @param indentionCharacter String representation of the character used in the indent (e.g. " ", "\t", "."). | ||
*/ | ||
public IndentedLambda(int prefixSpaceCount, String indentionCharacter) { | ||
this(prefixSpaceCount, Character.codePointAt(indentionCharacter, 0)); | ||
} | ||
|
||
/** | ||
* Constructs a new instance of {@link io.swagger.codegen.mustache.IndentedLambda} | ||
* | ||
* @param prefixSpaceCount The number of indented characters to apply as a prefix to a fragment. | ||
*/ | ||
private IndentedLambda(int prefixSpaceCount, int indentionCodePoint) { | ||
if (prefixSpaceCount <= 0) { | ||
throw new IllegalArgumentException("prefixSpaceCount must be greater than 0"); | ||
} | ||
|
||
if (!Character.isValidCodePoint(indentionCodePoint)) { | ||
throw new IllegalArgumentException("indentionCodePoint is an invalid code point "); | ||
} | ||
|
||
this.prefixSpaceCount = prefixSpaceCount; | ||
this.spaceCode = indentionCodePoint; | ||
} | ||
|
||
@Override | ||
public Object apply(Object o, com.github.jknack.handlebars.Template template) throws IOException { | ||
String text = template.apply(o); | ||
if (text == null || text.length() == 0) { | ||
return text; | ||
} | ||
|
||
String prefixedIndention = StringUtils.repeat(new String(Character.toChars(spaceCode)), prefixSpaceCount); | ||
StringBuilder sb = new StringBuilder(); | ||
String[] lines = text.split(System.lineSeparator()); | ||
for (int i = 0; i < lines.length; i++) { | ||
String line = lines[i]; | ||
// Mustache will apply correct indentation to the first line of a template (to match declaration location). | ||
// So, we want to skip the first line. | ||
if (i > 0) { | ||
sb.append(prefixedIndention); | ||
} | ||
|
||
sb.append(line); | ||
|
||
// We've split on the system's line separator. We don't want to add an additional trailing line. | ||
if (i < lines.length - 1) { | ||
sb.append(System.lineSeparator()); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/io/swagger/codegen/v3/generators/handlebars/lambda/LowercaseLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.swagger.codegen.v3.generators.handlebars.lambda; | ||
|
||
import com.github.jknack.handlebars.Lambda; | ||
import io.swagger.codegen.v3.CodegenConfig; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Converts text in a fragment to lowercase. | ||
* | ||
* Register: | ||
* <pre> | ||
* additionalProperties.put("lowercase", new LowercaseLambda()); | ||
* </pre> | ||
* | ||
* Use: | ||
* <pre> | ||
* {{#lowercase}}{{httpMethod}}{{/lowercase}} | ||
* </pre> | ||
*/ | ||
public class LowercaseLambda implements Lambda { | ||
private CodegenConfig generator = null; | ||
|
||
public LowercaseLambda() { | ||
|
||
} | ||
|
||
public LowercaseLambda generator(final CodegenConfig generator) { | ||
this.generator = generator; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Object apply(Object o, com.github.jknack.handlebars.Template template) throws IOException { | ||
String text = template.apply(o); | ||
if (text == null || text.length() == 0) { | ||
return text; | ||
} | ||
text = text.toLowerCase(); | ||
if (generator != null && generator.reservedWords().contains(text)) { | ||
text = generator.escapeReservedWord(text); | ||
} | ||
|
||
return text; | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/io/swagger/codegen/v3/generators/handlebars/lambda/TitlecaseLambda.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.swagger.codegen.v3.generators.handlebars.lambda; | ||
|
||
import com.github.jknack.handlebars.Lambda; | ||
|
||
import java.io.IOException; | ||
|
||
/** | ||
* Converts text in a fragment to title case. | ||
* | ||
* Register: | ||
* <pre> | ||
* additionalProperties.put("titlecase", new TitlecaseLambda()); | ||
* </pre> | ||
* | ||
* Use: | ||
* <pre> | ||
* {{#titlecase}}{{classname}}{{/titlecase}} | ||
* </pre> | ||
*/ | ||
public class TitlecaseLambda implements Lambda { | ||
private String delimiter; | ||
|
||
/** | ||
* Constructs a new instance of {@link io.swagger.codegen.mustache.TitlecaseLambda}, which will convert all text | ||
* in a space delimited string to title-case. | ||
*/ | ||
public TitlecaseLambda() { | ||
this(" "); | ||
} | ||
|
||
/** | ||
* Constructs a new instance of {@link io.swagger.codegen.mustache.TitlecaseLambda}, splitting on the specified | ||
* delimiter and converting each word to title-case. | ||
* <p> | ||
* NOTE: passing {@code null} results in a title-casing the first word only. | ||
* | ||
* @param delimiter Provided to allow an override for the default space delimiter. | ||
*/ | ||
public TitlecaseLambda(String delimiter) { | ||
this.delimiter = delimiter; | ||
} | ||
|
||
private String titleCase(final String input) { | ||
return input.substring(0, 1).toUpperCase() + input.substring(1); | ||
} | ||
|
||
@Override | ||
public Object apply(Object o, com.github.jknack.handlebars.Template template) throws IOException { | ||
String text = template.apply(o); | ||
if (text == null || text.length() == 0) { | ||
return text; | ||
} | ||
if (delimiter == null) { | ||
return titleCase(text); | ||
} | ||
|
||
// Split accepts regex. \Q and \E wrap the delimiter to create a literal regex, | ||
// so things like "." and "|" aren't treated as their regex equivalents. | ||
StringBuffer sb = new StringBuffer(); | ||
String[] parts = text.split("\\Q" + delimiter + "\\E"); | ||
for (int i = 0; i < parts.length; i++) { | ||
String part = parts[i]; | ||
sb.append(titleCase(part)); | ||
if (i != parts.length - 1) { | ||
sb.append(delimiter); | ||
} | ||
} | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.