forked from loafle/openapi-generator-original
Refactor copy lambda (#19983)
* comment out broken tests * refactored copy lambda * added tests
This commit is contained in:
parent
b51b18e3ca
commit
f98073d508
@ -33,6 +33,8 @@ import org.openapitools.codegen.model.ModelsMap;
|
|||||||
import org.openapitools.codegen.model.OperationMap;
|
import org.openapitools.codegen.model.OperationMap;
|
||||||
import org.openapitools.codegen.model.OperationsMap;
|
import org.openapitools.codegen.model.OperationsMap;
|
||||||
import org.openapitools.codegen.templating.mustache.*;
|
import org.openapitools.codegen.templating.mustache.*;
|
||||||
|
import org.openapitools.codegen.templating.mustache.CopyLambda.CopyContent;
|
||||||
|
import org.openapitools.codegen.templating.mustache.CopyLambda.WhiteSpaceStrategy;
|
||||||
import org.openapitools.codegen.utils.ModelUtils;
|
import org.openapitools.codegen.utils.ModelUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -427,7 +429,7 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ImmutableMap.Builder<String, Lambda> addMustacheLambdas() {
|
protected ImmutableMap.Builder<String, Lambda> addMustacheLambdas() {
|
||||||
CopyLambda copyLambda = new CopyLambda();
|
final CopyContent copyContent = new CopyContent();
|
||||||
|
|
||||||
return super.addMustacheLambdas()
|
return super.addMustacheLambdas()
|
||||||
.put("camelcase_sanitize_param", new CamelCaseAndSanitizeLambda().generator(this).escapeAsParamName(true))
|
.put("camelcase_sanitize_param", new CamelCaseAndSanitizeLambda().generator(this).escapeAsParamName(true))
|
||||||
@ -443,12 +445,13 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen {
|
|||||||
.put("first", new FirstLambda(" "))
|
.put("first", new FirstLambda(" "))
|
||||||
.put("firstDot", new FirstLambda("\\."))
|
.put("firstDot", new FirstLambda("\\."))
|
||||||
.put("indent1", new IndentedLambda(4, " ", false, true))
|
.put("indent1", new IndentedLambda(4, " ", false, true))
|
||||||
|
.put("indentAll1", new IndentedLambda(4, " ", true, true))
|
||||||
.put("indent3", new IndentedLambda(12, " ", false, true))
|
.put("indent3", new IndentedLambda(12, " ", false, true))
|
||||||
.put("indent4", new IndentedLambda(16, " ", false, true))
|
.put("indent4", new IndentedLambda(16, " ", false, true))
|
||||||
.put("copy", copyLambda)
|
.put("copy", new CopyLambda(copyContent, WhiteSpaceStrategy.None, WhiteSpaceStrategy.None))
|
||||||
.put("paste", new PasteLambda(copyLambda, true, true, true, false))
|
.put("copyText", new CopyLambda(copyContent, WhiteSpaceStrategy.Strip, WhiteSpaceStrategy.StripLineBreakIfPresent))
|
||||||
.put("pasteOnce", new PasteLambda(copyLambda, true, true, true, true))
|
.put("paste", new PasteLambda(copyContent, false))
|
||||||
.put("pasteLine", new PasteLambda(copyLambda, true, true, false, false))
|
.put("pasteOnce", new PasteLambda(copyContent, true))
|
||||||
.put("uniqueLines", new UniqueLambda("\n", false))
|
.put("uniqueLines", new UniqueLambda("\n", false))
|
||||||
.put("unique", new UniqueLambda("\n", true))
|
.put("unique", new UniqueLambda("\n", true))
|
||||||
.put("camel_case", new CamelCaseLambda())
|
.put("camel_case", new CamelCaseLambda())
|
||||||
|
@ -27,7 +27,7 @@ import com.samskivert.mustache.Template.Fragment;
|
|||||||
*
|
*
|
||||||
* Register:
|
* Register:
|
||||||
* <pre>
|
* <pre>
|
||||||
* additionalProperties.put("copy", new CopyLambda());
|
* additionalProperties.put("copy", new CopyLambda(new CopyContent()));
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* Use:
|
* Use:
|
||||||
@ -36,13 +36,55 @@ import com.samskivert.mustache.Template.Fragment;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class CopyLambda implements Mustache.Lambda {
|
public class CopyLambda implements Mustache.Lambda {
|
||||||
public String savedContent;
|
public static class CopyContent {
|
||||||
|
public String content;
|
||||||
|
}
|
||||||
|
|
||||||
public CopyLambda() {
|
public CopyContent copyContent;
|
||||||
|
private final WhiteSpaceStrategy leadingWhiteSpaceStrategy;
|
||||||
|
private final WhiteSpaceStrategy trailingWhiteSpaceStrategy;
|
||||||
|
|
||||||
|
public enum WhiteSpaceStrategy {
|
||||||
|
None,
|
||||||
|
AppendLineBreakIfMissing,
|
||||||
|
Strip,
|
||||||
|
StripLineBreakIfPresent
|
||||||
|
}
|
||||||
|
|
||||||
|
public CopyLambda(CopyContent content, WhiteSpaceStrategy leadingWhiteSpaceStrategy, WhiteSpaceStrategy trailingWhiteSpaceStrategy) {
|
||||||
|
this.copyContent = content;
|
||||||
|
this.leadingWhiteSpaceStrategy = leadingWhiteSpaceStrategy;
|
||||||
|
this.trailingWhiteSpaceStrategy = trailingWhiteSpaceStrategy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Fragment fragment, Writer writer) throws IOException {
|
public void execute(Fragment fragment, Writer writer) throws IOException {
|
||||||
savedContent = fragment.execute().stripTrailing();
|
String content = fragment.execute();
|
||||||
|
|
||||||
|
if (this.leadingWhiteSpaceStrategy == WhiteSpaceStrategy.AppendLineBreakIfMissing && !content.startsWith("\n")){
|
||||||
|
content = "\n" + content;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.leadingWhiteSpaceStrategy == WhiteSpaceStrategy.Strip) {
|
||||||
|
content = content.stripLeading();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.leadingWhiteSpaceStrategy == WhiteSpaceStrategy.StripLineBreakIfPresent && content.startsWith("\n")) {
|
||||||
|
content = content.substring(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.trailingWhiteSpaceStrategy == WhiteSpaceStrategy.AppendLineBreakIfMissing && !content.endsWith("\n")){
|
||||||
|
content = content + "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.trailingWhiteSpaceStrategy == WhiteSpaceStrategy.Strip){
|
||||||
|
content = content.stripTrailing();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.trailingWhiteSpaceStrategy == WhiteSpaceStrategy.StripLineBreakIfPresent && content.endsWith("\n")) {
|
||||||
|
content = content.substring(0, content.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.copyContent.content = content;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ package org.openapitools.codegen.templating.mustache;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.templating.mustache.CopyLambda.CopyContent;
|
||||||
|
|
||||||
import com.samskivert.mustache.Mustache;
|
import com.samskivert.mustache.Mustache;
|
||||||
import com.samskivert.mustache.Template.Fragment;
|
import com.samskivert.mustache.Template.Fragment;
|
||||||
|
|
||||||
@ -27,7 +29,7 @@ import com.samskivert.mustache.Template.Fragment;
|
|||||||
*
|
*
|
||||||
* Register:
|
* Register:
|
||||||
* <pre>
|
* <pre>
|
||||||
* additionalProperties.put("paste", new PasteLambda(copyLambda, true, true, true, false));
|
* additionalProperties.put("paste", new PasteLambda(copyContent, false));
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* Use:
|
* Use:
|
||||||
@ -36,41 +38,26 @@ import com.samskivert.mustache.Template.Fragment;
|
|||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public class PasteLambda implements Mustache.Lambda {
|
public class PasteLambda implements Mustache.Lambda {
|
||||||
private final CopyLambda copyLambda;
|
private final CopyContent copyContent;
|
||||||
private final Boolean stripLeading;
|
|
||||||
private final Boolean stripTrailing;
|
|
||||||
private final Boolean endWithLineBreak;
|
|
||||||
private final Boolean clear;
|
private final Boolean clear;
|
||||||
|
|
||||||
public PasteLambda(CopyLambda copyLambda, Boolean stripLeading, Boolean stripTrailing, Boolean endWithLineBreak, boolean clear) {
|
public PasteLambda(CopyContent copyContent, boolean clear) {
|
||||||
this.copyLambda = copyLambda;
|
this.copyContent = copyContent;
|
||||||
this.stripLeading = stripLeading;
|
|
||||||
this.stripTrailing = stripTrailing;
|
|
||||||
this.endWithLineBreak = endWithLineBreak;
|
|
||||||
this.clear = clear;
|
this.clear = clear;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Fragment fragment, Writer writer) throws IOException {
|
public void execute(Fragment fragment, Writer writer) throws IOException {
|
||||||
String content = this.copyLambda.savedContent;
|
String content = this.copyContent.content;
|
||||||
|
|
||||||
if (content == null) {
|
if (content == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.stripTrailing){
|
|
||||||
content = content.stripTrailing();
|
|
||||||
}
|
|
||||||
if (this.stripLeading) {
|
|
||||||
content = content.stripLeading();
|
|
||||||
}
|
|
||||||
if (this.endWithLineBreak && !content.endsWith("\n")){
|
|
||||||
content = content + "\n";
|
|
||||||
}
|
|
||||||
writer.write(content);
|
|
||||||
|
|
||||||
if (this.clear) {
|
if (this.clear) {
|
||||||
this.copyLambda.savedContent = null;
|
this.copyContent.content = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
writer.write(content);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,12 +342,12 @@
|
|||||||
public override void Write(Utf8JsonWriter writer, {{classname}} {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, JsonSerializerOptions jsonSerializerOptions)
|
public override void Write(Utf8JsonWriter writer, {{classname}} {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, JsonSerializerOptions jsonSerializerOptions)
|
||||||
{
|
{
|
||||||
{{#lambda.trimLineBreaks}}
|
{{#lambda.trimLineBreaks}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}
|
{{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#discriminator}}
|
{{#discriminator}}
|
||||||
{{#children}}
|
{{#children}}
|
||||||
if ({{#lambda.pasteLine}}{{/lambda.pasteLine}} is {{classname}} {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}){
|
if ({{#lambda.paste}}{{/lambda.paste}} is {{classname}} {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}){
|
||||||
JsonSerializer.Serialize<{{{name}}}>(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, jsonSerializerOptions);
|
JsonSerializer.Serialize<{{{name}}}>(writer, {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}, jsonSerializerOptions);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -449,9 +449,9 @@
|
|||||||
{{^isMap}}
|
{{^isMap}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
{{^isUuid}}
|
{{^isUuid}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}});
|
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}});
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
@ -460,44 +460,44 @@
|
|||||||
{{/isMap}}
|
{{/isMap}}
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
{{#isBoolean}}
|
{{#isBoolean}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteBoolean("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
|
writer.WriteBoolean("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
{{/isBoolean}}
|
{{/isBoolean}}
|
||||||
{{^isEnum}}
|
{{^isEnum}}
|
||||||
{{#isNumeric}}
|
{{#isNumeric}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
|
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
{{/isNumeric}}
|
{{/isNumeric}}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{#isDate}}
|
{{#isDate}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}.ToString({{name}}Format));
|
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}.ToString({{name}}Format));
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
{{/isDate}}
|
{{/isDate}}
|
||||||
{{#isDateTime}}
|
{{#isDateTime}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}.ToString({{name}}Format));
|
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}.ToString({{name}}Format));
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
{{/isDateTime}}
|
{{/isDateTime}}
|
||||||
{{#isEnum}}
|
{{#isEnum}}
|
||||||
{{#isNumeric}}
|
{{#isNumeric}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteNumber("{{baseName}}", {{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}));
|
writer.WriteNumber("{{baseName}}", {{#isInnerEnum}}{{classname}}.{{/isInnerEnum}}{{{datatypeWithEnum}}}ToJsonValue({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}}));
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
@ -519,9 +519,9 @@
|
|||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{/isInnerEnum}}
|
{{/isInnerEnum}}
|
||||||
{{^isInnerEnum}}
|
{{^isInnerEnum}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}
|
{{#lambda.camelcase_sanitize_param}}{{name}}{{/lambda.camelcase_sanitize_param}}
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#required}}
|
{{#required}}
|
||||||
{{#isNullable}}
|
{{#isNullable}}
|
||||||
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null)
|
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}} == null)
|
||||||
@ -533,7 +533,7 @@
|
|||||||
{{#enumVars}}
|
{{#enumVars}}
|
||||||
{{#-first}}
|
{{#-first}}
|
||||||
{{#isString}}
|
{{#isString}}
|
||||||
if ({{#lambda.pasteLine}}{{/lambda.pasteLine}}RawValue != null){{! we cant use name here because enumVar also has a name property, so use the paste lambda instead }}
|
if ({{#lambda.paste}}{{/lambda.paste}}RawValue != null){{! we cant use name here because enumVar also has a name property, so use the paste lambda instead }}
|
||||||
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{nameInPascalCase}}{{/lambda.camelcase_sanitize_param}}RawValue);
|
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{nameInPascalCase}}{{/lambda.camelcase_sanitize_param}}RawValue);
|
||||||
else
|
else
|
||||||
writer.WriteNull("{{baseName}}");
|
writer.WriteNull("{{baseName}}");
|
||||||
@ -552,10 +552,10 @@
|
|||||||
{{#enumVars}}
|
{{#enumVars}}
|
||||||
{{#-first}}
|
{{#-first}}
|
||||||
{{^isNumeric}}
|
{{^isNumeric}}
|
||||||
writer.WriteString("{{baseName}}", {{#lambda.pasteLine}}{{/lambda.pasteLine}}RawValue);
|
writer.WriteString("{{baseName}}", {{#lambda.paste}}{{/lambda.paste}}RawValue);
|
||||||
{{/isNumeric}}
|
{{/isNumeric}}
|
||||||
{{#isNumeric}}
|
{{#isNumeric}}
|
||||||
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{#lambda.pasteLine}}{{/lambda.pasteLine}}{{/lambda.camelcase_sanitize_param}}RawValue);
|
writer.WriteNumber("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{#lambda.paste}}{{/lambda.paste}}{{/lambda.camelcase_sanitize_param}}RawValue);
|
||||||
{{/isNumeric}}
|
{{/isNumeric}}
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
{{/enumVars}}
|
{{/enumVars}}
|
||||||
@ -568,16 +568,16 @@
|
|||||||
{{#isNullable}}
|
{{#isNullable}}
|
||||||
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option{{nrt!}}.Value != null)
|
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option{{nrt!}}.Value != null)
|
||||||
{
|
{
|
||||||
var {{#lambda.pasteLine}}{{/lambda.pasteLine}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value{{nrt!}}.Value);
|
var {{#lambda.paste}}{{/lambda.paste}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}Option.Value{{nrt!}}.Value);
|
||||||
writer.{{#lambda.first}}{{#allowableValues}}{{#enumVars}}{{^isNumeric}}WriteString {{/isNumeric}}{{#isNumeric}}WriteNumber {{/isNumeric}}{{/enumVars}}{{/allowableValues}}{{/lambda.first}}("{{baseName}}", {{#lambda.pasteLine}}{{/lambda.pasteLine}}RawValue);
|
writer.{{#lambda.first}}{{#allowableValues}}{{#enumVars}}{{^isNumeric}}WriteString {{/isNumeric}}{{#isNumeric}}WriteNumber {{/isNumeric}}{{/enumVars}}{{/allowableValues}}{{/lambda.first}}("{{baseName}}", {{#lambda.paste}}{{/lambda.paste}}RawValue);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
writer.WriteNull("{{baseName}}");
|
writer.WriteNull("{{baseName}}");
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{^isNullable}}
|
{{^isNullable}}
|
||||||
{
|
{
|
||||||
var {{#lambda.pasteLine}}{{/lambda.pasteLine}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{nrt!}}.Value);
|
var {{#lambda.paste}}{{/lambda.paste}}RawValue = {{{datatypeWithEnum}}}ValueConverter.ToJsonValue({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{nrt!}}.Value);
|
||||||
writer.{{#lambda.first}}{{#allowableValues}}{{#enumVars}}{{^isNumeric}}WriteString {{/isNumeric}}{{#isNumeric}}WriteNumber {{/isNumeric}}{{/enumVars}}{{/allowableValues}}{{/lambda.first}}("{{baseName}}", {{#lambda.pasteLine}}{{/lambda.pasteLine}}RawValue);
|
writer.{{#lambda.first}}{{#allowableValues}}{{#enumVars}}{{^isNumeric}}WriteString {{/isNumeric}}{{#isNumeric}}WriteNumber {{/isNumeric}}{{/enumVars}}{{/allowableValues}}{{/lambda.first}}("{{baseName}}", {{#lambda.paste}}{{/lambda.paste}}RawValue);
|
||||||
}
|
}
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
@ -586,9 +586,9 @@
|
|||||||
{{/isMap}}
|
{{/isMap}}
|
||||||
{{/isEnum}}
|
{{/isEnum}}
|
||||||
{{#isUuid}}
|
{{#isUuid}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copyText}}
|
||||||
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
|
writer.WriteString("{{baseName}}", {{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{#vendorExtensions.x-is-value-type}}{{nrt!}}.Value{{/vendorExtensions.x-is-value-type}}{{/required}}{{#required}}{{#isNullable}}.Value{{/isNullable}}{{/required}});
|
||||||
{{/lambda.copy}}
|
{{/lambda.copyText}}
|
||||||
{{#lambda.indent3}}
|
{{#lambda.indent3}}
|
||||||
{{>WriteProperty}}
|
{{>WriteProperty}}
|
||||||
{{/lambda.indent3}}
|
{{/lambda.indent3}}
|
||||||
|
@ -53,11 +53,15 @@ namespace {{packageName}}.{{clientPackage}}
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
{{#lambda.indent1}}{{#lambda.pasteLine}}{{/lambda.pasteLine}}{{/lambda.indent1}}
|
{{#lambda.indentAll1}}
|
||||||
|
{{#lambda.paste}}
|
||||||
|
{{/lambda.paste}}
|
||||||
|
{{/lambda.indentAll1}}
|
||||||
}
|
}
|
||||||
{{/hasApiKeyMethods}}
|
{{/hasApiKeyMethods}}
|
||||||
{{^hasApiKeyMethods}}
|
{{^hasApiKeyMethods}}
|
||||||
{{#lambda.pasteLine}}{{/lambda.pasteLine}}
|
{{#lambda.paste}}
|
||||||
|
{{/lambda.paste}}
|
||||||
{{/hasApiKeyMethods}}
|
{{/hasApiKeyMethods}}
|
||||||
|
|
||||||
foreach(Channel<TTokenBase> tokens in AvailableTokens.Values)
|
foreach(Channel<TTokenBase> tokens in AvailableTokens.Values)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// {{{name}}} ({{{dataType}}}) pattern
|
// {{{name}}} ({{{dataType}}}) pattern
|
||||||
Regex regex{{{name}}} = new Regex(@"{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
|
Regex regex{{{name}}} = new Regex(@"{{{vendorExtensions.x-regex}}}"{{#vendorExtensions.x-modifiers}}{{#-first}}, {{/-first}}RegexOptions.{{{.}}}{{^-last}} | {{/-last}}{{/vendorExtensions.x-modifiers}});
|
||||||
{{#lambda.copy}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null && {{/lambda.copy}}
|
{{#lambda.copy}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} != null && {{/lambda.copy}}
|
||||||
if ({{#lambda.first}}{{^required}}{{#lambda.pasteLine}}{{/lambda.pasteLine}} {{/required}}{{#isNullable}}{{#lambda.pasteLine}}{{/lambda.pasteLine}}{{/isNullable}}{{/lambda.first}}!regex{{{name}}}.Match(this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}}{{#isUuid}}.ToString(){{#lambda.first}}{{^required}}{{nrt!}} {{/required}}{{#isNullable}}! {{/isNullable}}{{/lambda.first}}{{/isUuid}}).Success)
|
if ({{#lambda.first}}{{^required}}{{#lambda.paste}}{{/lambda.paste}} {{/required}}{{#isNullable}}{{#lambda.paste}}{{/lambda.paste}}{{/isNullable}}{{/lambda.first}}!regex{{{name}}}.Match(this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}}{{#isUuid}}.ToString(){{#lambda.first}}{{^required}}{{nrt!}} {{/required}}{{#isNullable}}! {{/isNullable}}{{/lambda.first}}{{/isUuid}}).Success)
|
||||||
{
|
{
|
||||||
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of " + regex{{{name}}}, new [] { "{{{name}}}" });
|
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must match a pattern of " + regex{{{name}}}, new [] { "{{{name}}}" });
|
||||||
}
|
}
|
@ -1,9 +1,10 @@
|
|||||||
{{#isNullable}}
|
{{#isNullable}}
|
||||||
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}} != null)
|
if ({{#lambda.camelcase_sanitize_param}}{{classname}}{{/lambda.camelcase_sanitize_param}}.{{name}}{{^required}}Option.Value{{/required}} != null)
|
||||||
{{#lambda.pasteLine}}{{/lambda.pasteLine}}
|
{{#lambda.paste}}{{/lambda.paste}}
|
||||||
else
|
else
|
||||||
writer.WriteNull("{{baseName}}");
|
writer.WriteNull("{{baseName}}");
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{^isNullable}}
|
{{^isNullable}}
|
||||||
{{#lambda.pasteLine}}{{/lambda.pasteLine}}
|
{{#lambda.paste}}
|
||||||
|
{{/lambda.paste}}
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
@ -345,15 +345,17 @@
|
|||||||
{{/readOnlyVars}}
|
{{/readOnlyVars}}
|
||||||
{{#readOnlyVars}}
|
{{#readOnlyVars}}
|
||||||
{{#lambda.copy}}
|
{{#lambda.copy}}
|
||||||
|
|
||||||
if ({{name}} != null)
|
if ({{name}} != null)
|
||||||
hashCode = (hashCode * 59) + {{name}}.GetHashCode();
|
hashCode = (hashCode * 59) + {{name}}.GetHashCode();
|
||||||
|
|
||||||
{{/lambda.copy}}
|
{{/lambda.copy}}
|
||||||
{{#isNullable}}
|
{{#isNullable}}
|
||||||
{{#lambda.pasteOnce}}{{/lambda.pasteOnce}}
|
{{#lambda.pasteOnce}}
|
||||||
|
{{/lambda.pasteOnce}}
|
||||||
{{/isNullable}}
|
{{/isNullable}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
{{#lambda.pasteOnce}}{{/lambda.pasteOnce}}
|
{{#lambda.pasteOnce}}
|
||||||
|
{{/lambda.pasteOnce}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/readOnlyVars}}
|
{{/readOnlyVars}}
|
||||||
{{#isAdditionalPropertiesTrue}}
|
{{#isAdditionalPropertiesTrue}}
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package org.openapitools.codegen.templating.mustache;
|
||||||
|
|
||||||
|
import static org.mockito.AdditionalAnswers.returnsFirstArg;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.openapitools.codegen.templating.mustache.CopyLambda.CopyContent;
|
||||||
|
import org.openapitools.codegen.templating.mustache.CopyLambda.WhiteSpaceStrategy;
|
||||||
|
|
||||||
|
public class CopyPasteLambdaTest extends LambdaTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
CodegenConfig generator;
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setup() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void camelCaseTest() {
|
||||||
|
final CopyContent copyContent = new CopyContent();
|
||||||
|
Map<String, Object> ctx = context("copy", new CopyLambda(copyContent, WhiteSpaceStrategy.None, WhiteSpaceStrategy.None));
|
||||||
|
ctx.put("paste", new PasteLambda(copyContent, false));
|
||||||
|
test("foo", "{{#copy}}foo{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
|
||||||
|
// the first line break does not count
|
||||||
|
// it results in the tag being the only element on the line, so the line does not get printed
|
||||||
|
test("\nfoo\n", "{{#copy}}\n\nfoo\n{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void camelCaseTestAppend() {
|
||||||
|
final CopyContent copyContent = new CopyContent();
|
||||||
|
Map<String, Object> ctx = context("copy", new CopyLambda(copyContent, WhiteSpaceStrategy.AppendLineBreakIfMissing, WhiteSpaceStrategy.AppendLineBreakIfMissing));
|
||||||
|
ctx.put("paste", new PasteLambda(copyContent, false));
|
||||||
|
test("\nfoo\n", "{{#copy}}foo{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test("\nfoo\n", "{{#copy}}\n\nfoo\n{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void camelCaseTestStripLineBreakIfPresent() {
|
||||||
|
final CopyContent copyContent = new CopyContent();
|
||||||
|
Map<String, Object> ctx = context("copy", new CopyLambda(copyContent, WhiteSpaceStrategy.StripLineBreakIfPresent, WhiteSpaceStrategy.StripLineBreakIfPresent));
|
||||||
|
ctx.put("paste", new PasteLambda(copyContent, false));
|
||||||
|
test("foo", "{{#copy}}foo{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test("foo", "{{#copy}}\nfoo\n{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test(" \nfoo\n ", "{{#copy}}\n\n \nfoo\n {{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test(" foo ", "{{#copy}}\n\n foo \n{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void camelCaseTestStrip() {
|
||||||
|
final CopyContent copyContent = new CopyContent();
|
||||||
|
Map<String, Object> ctx = context("copy", new CopyLambda(copyContent, WhiteSpaceStrategy.Strip, WhiteSpaceStrategy.Strip));
|
||||||
|
ctx.put("paste", new PasteLambda(copyContent, false));
|
||||||
|
test("foo", "{{#copy}}foo{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test("foo", "{{#copy}}\n\nfoo\n{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test("foo", "{{#copy}} \nfoo\n {{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
test("foo", "{{#copy}}\n\n foo \n{{/copy}}{{#paste}}{{/paste}}", ctx);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user