[csharp-netcore] Moved formats to separate file (#14894)

* add unsigned integer/long support to c# netcore client

* moved formats to separate file

* moved formats to cli options

* moved formats to cli options

* reverted unintended changes

* reverted unintended changes

---------

Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
devhl-labs
2023-03-12 03:05:35 -04:00
committed by GitHub
parent 140d941da2
commit 2b7007b653
13 changed files with 47 additions and 11 deletions
+2
View File
@@ -22,6 +22,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|apiName|Must be a valid C# class name. Only used in Generic Host library. Default: Api| |Api|
|caseInsensitiveResponseHeaders|Make API response's headers case-insensitive| |false|
|conditionalSerialization|Serialize only those properties which are initialized by user, accepted values are true or false, default value is false.| |false|
|dateFormat|The default DateTime format.| |yyyy'-'MM'-'dd|
|dateTimeFormat|The default DateTime format.| |yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK|
|disallowAdditionalPropertiesIfNotPresent|If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. If true (default), keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.|<dl><dt>**false**</dt><dd>The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.</dd><dt>**true**</dt><dd>Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.</dd></dl>|true|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|interfacePrefix|Prefix interfaces with a community standard or widely accepted prefix.| |I|
@@ -70,6 +70,10 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
protected String packageCompany = "OpenAPI";
protected String packageCopyright = "No Copyright";
protected String packageAuthors = "OpenAPI";
public static final String DATE_FORMAT = "dateFormat";
protected String dateFormat = "yyyy'-'MM'-'dd";
public static final String DATETIME_FORMAT = "dateTimeFormat";
protected String dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK";
protected String interfacePrefix = "I";
protected String enumNameSuffix = "Enum";
@@ -333,6 +337,20 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
additionalProperties.put(CodegenConstants.PACKAGE_PRODUCTNAME, packageProductName);
}
// {{dateFormat}}
if (additionalProperties.containsKey(DATE_FORMAT)) {
setDateFormat((String) additionalProperties.get(DATE_FORMAT));
} else {
additionalProperties.put(DATE_FORMAT, this.dateFormat);
}
// {{dateTimeFormat}}
if (additionalProperties.containsKey(DATETIME_FORMAT)) {
setDateTimeFormat((String) additionalProperties.get(DATETIME_FORMAT));
} else {
additionalProperties.put(DATETIME_FORMAT, this.dateTimeFormat);
}
// {{packageDescription}}
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_DESCRIPTION)) {
setPackageDescription((String) additionalProperties.get(CodegenConstants.PACKAGE_DESCRIPTION));
@@ -1269,6 +1287,14 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
this.packageProductName = packageProductName;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public void setDateTimeFormat(String dateTimeFormat) {
this.dateTimeFormat = dateTimeFormat;
}
public void setPackageDescription(String packageDescription) {
this.packageDescription = packageDescription;
}
@@ -219,6 +219,14 @@ public class CSharpNetCoreClientCodegen extends AbstractCSharpCodegen {
CodegenConstants.PACKAGE_TAGS_DESC,
this.packageTags);
addOption(DATE_FORMAT,
"The default DateTime format.",
this.dateFormat);
addOption(DATETIME_FORMAT,
"The default DateTime format.",
this.dateTimeFormat);
CliOption framework = new CliOption(
CodegenConstants.DOTNET_FRAMEWORK,
CodegenConstants.DOTNET_FRAMEWORK_DESC
@@ -8,14 +8,14 @@
/// <summary>
/// The format to use to serialize {{name}}
/// </summary>
public static string {{name}}Format { get; set; } = "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK";
public static string {{name}}Format { get; set; } = "{{{dateTimeFormat}}}";
{{/isDateTime}}
{{#isDate}}
/// <summary>
/// The format to use to serialize {{name}}
/// </summary>
public static string {{name}}Format { get; set; } = "yyyy-MM-dd";
public static string {{name}}Format { get; set; } = "{{{dateFormat}}}";
{{/isDate}}
{{/allVars}}
@@ -93,7 +93,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize DateOnlyProperty
/// </summary>
public static string DateOnlyPropertyFormat { get; set; } = "yyyy-MM-dd";
public static string DateOnlyPropertyFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// A Json reader.
@@ -368,7 +368,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize Date
/// </summary>
public static string DateFormat { get; set; } = "yyyy-MM-dd";
public static string DateFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// The format to use to serialize DateTime
@@ -189,7 +189,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize DateProp
/// </summary>
public static string DatePropFormat { get; set; } = "yyyy-MM-dd";
public static string DatePropFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// The format to use to serialize DatetimeProp
@@ -91,7 +91,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize DateOnlyProperty
/// </summary>
public static string DateOnlyPropertyFormat { get; set; } = "yyyy-MM-dd";
public static string DateOnlyPropertyFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// A Json reader.
@@ -366,7 +366,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize Date
/// </summary>
public static string DateFormat { get; set; } = "yyyy-MM-dd";
public static string DateFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// The format to use to serialize DateTime
@@ -187,7 +187,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize DateProp
/// </summary>
public static string DatePropFormat { get; set; } = "yyyy-MM-dd";
public static string DatePropFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// The format to use to serialize DatetimeProp
@@ -91,7 +91,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize DateOnlyProperty
/// </summary>
public static string DateOnlyPropertyFormat { get; set; } = "yyyy-MM-dd";
public static string DateOnlyPropertyFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// A Json reader.
@@ -366,7 +366,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize Date
/// </summary>
public static string DateFormat { get; set; } = "yyyy-MM-dd";
public static string DateFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// The format to use to serialize DateTime
@@ -187,7 +187,7 @@ namespace Org.OpenAPITools.Model
/// <summary>
/// The format to use to serialize DateProp
/// </summary>
public static string DatePropFormat { get; set; } = "yyyy-MM-dd";
public static string DatePropFormat { get; set; } = "yyyy'-'MM'-'dd";
/// <summary>
/// The format to use to serialize DatetimeProp