diff --git a/docs/generators/csharp.md b/docs/generators/csharp.md
index 5fe0e39be19..c3b17808dc7 100644
--- a/docs/generators/csharp.md
+++ b/docs/generators/csharp.md
@@ -25,6 +25,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|dateFormat|The default Date format (only `generichost` library supports this option).| |yyyy'-'MM'-'dd|
|dateTimeFormat|The default DateTime format (only `generichost` library supports this option).| |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.|
- **false**
- The 'additionalProperties' implementation is compliant with the OAS and JSON schema specifications.
- **true**
- Keep the old (incorrect) behaviour that 'additionalProperties' is set to false by default.
|true|
+|equatable|Overrides Equals and GetHashCode methods.| |true|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|interfacePrefix|Prefix interfaces with a community standard or widely accepted prefix.| |I|
|library|HTTP library template (sub-template) to use|- **generichost**
- HttpClient with Generic Host dependency injection (https://docs.microsoft.com/en-us/dotnet/core/extensions/generic-host) (Experimental. Subject to breaking changes without notice.)
- **httpclient**
- HttpClient (https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclient) (Experimental. Subject to breaking changes without notice.)
- **unityWebRequest**
- UnityWebRequest (...) (Experimental. Subject to breaking changes without notice.)
- **restsharp**
- RestSharp (https://github.com/restsharp/RestSharp)
|restsharp|
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
index b5cd594ced6..edc2ef10c09 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java
@@ -320,6 +320,9 @@ public class CodegenConstants {
public static final String VALIDATABLE = "validatable";
public static final String VALIDATABLE_DESC = "Generates self-validatable models.";
+ public static final String EQUATABLE = "equatable";
+ public static final String EQUATABLE_DESC = "Overrides Equals and GetHashCode methods.";
+
public static final String IGNORE_FILE_OVERRIDE = "ignoreFileOverride";
public static final String IGNORE_FILE_OVERRIDE_DESC = "Specifies an override location for the .openapi-generator-ignore file. Most useful on initial generation.";
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
index c7246cd34ac..bf63970c99f 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCSharpCodegen.java
@@ -416,7 +416,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
.put("joinWithComma", new JoinWithCommaLambda())
.put("trimLineBreaks", new TrimLineBreaksLambda())
.put("trimTrailingWhiteSpace", new TrimTrailingWhiteSpaceLambda())
- .put("first", new FirstLambda())
+ .put("first", new FirstLambda(" "))
+ .put("firstDot", new FirstLambda("\\."))
.put("indent3", new IndentedLambda(12, " "))
.put("indent4", new IndentedLambda(16, " "));
}
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java
index becec19fa72..645af9b5a06 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CSharpClientCodegen.java
@@ -114,6 +114,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
protected boolean supportsFileParameters = Boolean.TRUE;
protected boolean validatable = Boolean.TRUE;
+ protected boolean equatable = Boolean.TRUE;
protected Map regexModifiers;
// By default, generated code is considered public
protected boolean nonPublicApi = Boolean.FALSE;
@@ -318,6 +319,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
CodegenConstants.CASE_INSENSITIVE_RESPONSE_HEADERS_DESC,
this.caseInsensitiveResponseHeaders);
+ addSwitch(CodegenConstants.EQUATABLE,
+ CodegenConstants.EQUATABLE_DESC,
+ this.equatable);
+
regexModifiers = new HashMap<>();
regexModifiers.put('i', "IgnoreCase");
regexModifiers.put('m', "Multiline");
@@ -820,6 +825,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
syncBooleanProperty(additionalProperties, "netStandard", this::setNetStandard, this.netStandard);
+ syncBooleanProperty(additionalProperties, CodegenConstants.EQUATABLE, this::setEquatable, this.equatable);
syncBooleanProperty(additionalProperties, CodegenConstants.VALIDATABLE, this::setValidatable, this.validatable);
syncBooleanProperty(additionalProperties, CodegenConstants.SUPPORTS_ASYNC, this::setSupportsAsync, this.supportsAsync);
syncBooleanProperty(additionalProperties, SUPPORTS_RETRY, this::setSupportsRetry, this.supportsRetry);
@@ -1183,6 +1189,10 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
this.validatable = validatable;
}
+ public void setEquatable(boolean equatable) {
+ this.equatable = equatable;
+ }
+
public void setCaseInsensitiveResponseHeaders(final Boolean caseInsensitiveResponseHeaders) {
this.caseInsensitiveResponseHeaders = caseInsensitiveResponseHeaders;
}
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/FirstLambda.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/FirstLambda.java
index 38b72b738b9..00f2cc15302 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/FirstLambda.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/templating/mustache/FirstLambda.java
@@ -37,13 +37,19 @@ import java.util.Arrays;
*
*/
public class FirstLambda implements Mustache.Lambda {
- public FirstLambda() {
+ private final String delimiter;
+ public FirstLambda(String delimiter) {
+ this.delimiter = delimiter;
}
@Override
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
- String[] parts = fragment.execute().trim().split(" ");
+
+ String a = fragment.execute();
+
+
+ String[] parts = fragment.execute().split(this.delimiter);
writer.write(Arrays.stream(parts).findFirst().orElse(""));
}
diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsIEquatable.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsIEquatable.mustache
index 25f679727af..dd576dd0f1e 100644
--- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsIEquatable.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsIEquatable.mustache
@@ -1,3 +1 @@
-{{#readOnlyVars}}
-{{#-first}}
-{{#parent}}, {{/parent}}{{^parent}} : {{/parent}}IEquatable<{{classname}}{{nrt?}}>{{/-first}}{{/readOnlyVars}}
\ No newline at end of file
+{{#equatable}}{{#readOnlyVars}}{{#-first}}IEquatable<{{classname}}{{nrt?}}> {{/-first}}{{/readOnlyVars}}{{/equatable}}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsValidatable.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsValidatable.mustache
index 546971159ec..7c3f0e02ab1 100644
--- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsValidatable.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/ImplementsValidatable.mustache
@@ -1,4 +1 @@
-{{#validatable}}
-{{^parent}}
-{{^readOnlyVars}}
- : {{/readOnlyVars}}{{/parent}}{{#parent}}{{^readOnlyVars}}, {{/readOnlyVars}}{{/parent}}{{^parent}}{{#readOnlyVars}}{{#-first}}, {{/-first}}{{/readOnlyVars}}{{/parent}}IValidatableObject{{/validatable}}
\ No newline at end of file
+{{#validatable}}IValidatableObject {{/validatable}}
\ No newline at end of file
diff --git a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache
index 412e6f2e70c..54dbd8991e4 100644
--- a/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/modelGeneric.mustache
@@ -1,7 +1,7 @@
///
/// {{description}}{{^description}}{{classname}}{{/description}}
///
- {{>visibility}} partial class {{classname}}{{#parent}} : {{{.}}}{{/parent}}{{>ImplementsIEquatable}}{{>ImplementsValidatable}}
+ {{>visibility}} partial class {{classname}}{{#lambda.firstDot}}{{#parent}} : .{{/parent}}{{#validatable}} : .{{/validatable}}{{#equatable}} : .{{/equatable}}{{/lambda.firstDot}}{{#lambda.joinWithComma}}{{#parent}}{{{.}}} {{/parent}}{{>ImplementsIEquatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
{
{{#composedSchemas.oneOf}}
{{^vendorExtensions.x-duplicated-data-type}}
@@ -200,6 +200,7 @@
sb.Append("}\n");
return sb.ToString();
}
+ {{#equatable}}
{{#readOnlyVars}}
{{#-first}}
@@ -294,6 +295,7 @@
}
{{/-first}}
{{/readOnlyVars}}
+ {{/equatable}}
{{#validatable}}
{{^parentModel}}
diff --git a/modules/openapi-generator/src/main/resources/csharp/modelAnyOf.mustache b/modules/openapi-generator/src/main/resources/csharp/modelAnyOf.mustache
index f1dfc7d9db1..c206bc65604 100644
--- a/modules/openapi-generator/src/main/resources/csharp/modelAnyOf.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/modelAnyOf.mustache
@@ -10,7 +10,7 @@
{{/vendorExtensions.x-com-visible}}
[JsonConverter(typeof({{classname}}JsonConverter))]
[DataContract(Name = "{{{name}}}")]
- {{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#parent}}{{{.}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}
+ {{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#lambda.joinWithComma}}{{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
{
{{#isNullable}}
///
@@ -137,6 +137,7 @@
// no match found, throw an exception
throw new InvalidDataException("The JSON string `" + jsonString + "` cannot be deserialized into any schema defined.");
}
+ {{#equatable}}
///
/// Returns true if objects are equal
@@ -185,6 +186,7 @@
return hashCode;
}
}
+ {{/equatable}}
{{#validatable}}
///
diff --git a/modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache b/modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache
index 4ad255aef4c..f01d6a4627f 100644
--- a/modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/modelGeneric.mustache
@@ -16,7 +16,7 @@
{{/mappedModels}}
{{/discriminator}}
{{/useUnityWebRequest}}
- {{>visibility}} partial class {{classname}} : {{#parent}}{{{.}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}
+ {{>visibility}} partial class {{classname}}{{#lambda.firstDot}}{{#parent}} : .{{/parent}}{{#validatable}} : .{{/validatable}}{{#equatable}} : .{{/equatable}}{{/lambda.firstDot}}{{#lambda.joinWithComma}}{{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
{
{{#vars}}
{{#items.isEnum}}
@@ -327,6 +327,7 @@
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
}
+ {{#equatable}}
///
/// Returns true if objects are equal
@@ -415,6 +416,7 @@
return hashCode;
}
}
+ {{/equatable}}
{{#validatable}}
{{>validatable}}
diff --git a/modules/openapi-generator/src/main/resources/csharp/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/csharp/modelOneOf.mustache
index 69a5d79d9fd..7330acae959 100644
--- a/modules/openapi-generator/src/main/resources/csharp/modelOneOf.mustache
+++ b/modules/openapi-generator/src/main/resources/csharp/modelOneOf.mustache
@@ -10,7 +10,7 @@
{{/vendorExtensions.x-com-visible}}
[JsonConverter(typeof({{classname}}JsonConverter))]
[DataContract(Name = "{{{name}}}")]
- {{>visibility}} partial class {{classname}} : AbstractOpenAPISchema, {{#parent}}{{{.}}}, {{/parent}}IEquatable<{{classname}}>{{#validatable}}, IValidatableObject{{/validatable}}
+ {{>visibility}} partial class {{classname}} : {{#lambda.joinWithComma}}AbstractOpenAPISchema {{#parent}}{{{.}}} {{/parent}}{{#equatable}}IEquatable<{{classname}}> {{/equatable}}{{#validatable}}IValidatableObject {{/validatable}}{{/lambda.joinWithComma}}
{
{{#isNullable}}
///
@@ -183,6 +183,7 @@
return new{{classname}};
}
+ {{#equatable}}
///
/// Returns true if objects are equal
///
@@ -230,8 +231,9 @@
return hashCode;
}
}
-
+ {{/equatable}}
{{#validatable}}
+
///
/// To validate all properties of the instance
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Fruit.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Fruit.cs
index f117d123d06..8c90eafe0fb 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Fruit.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Fruit.cs
@@ -233,7 +233,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/FruitReq.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/FruitReq.cs
index 3fdaa210c2e..45f3458fa59 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/FruitReq.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/FruitReq.cs
@@ -242,7 +242,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Mammal.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Mammal.cs
index 07489337fb2..c5143ad5bb4 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Mammal.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Mammal.cs
@@ -279,7 +279,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/NullableShape.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/NullableShape.cs
index 5a83dcdc26d..4b5ab729ae2 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/NullableShape.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/NullableShape.cs
@@ -242,7 +242,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/OneOfString.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/OneOfString.cs
index 448a9902c56..da2235d809c 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/OneOfString.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/OneOfString.cs
@@ -187,7 +187,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Pig.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Pig.cs
index 8cbe04cce1c..ef0d346a8fe 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Pig.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Pig.cs
@@ -233,7 +233,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/PolymorphicProperty.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/PolymorphicProperty.cs
index 4797a5bec81..e0e286c1c02 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/PolymorphicProperty.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/PolymorphicProperty.cs
@@ -325,7 +325,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Quadrilateral.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Quadrilateral.cs
index d4739223613..c967be2130e 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Quadrilateral.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Quadrilateral.cs
@@ -233,7 +233,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Shape.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Shape.cs
index 41ddeffca3a..612de1da9db 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Shape.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Shape.cs
@@ -233,7 +233,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/ShapeOrNull.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/ShapeOrNull.cs
index 2f906a61f94..4b364faf969 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/ShapeOrNull.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/ShapeOrNull.cs
@@ -242,7 +242,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///
diff --git a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Triangle.cs b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Triangle.cs
index b0c5afe68a0..e655ba43874 100644
--- a/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Triangle.cs
+++ b/samples/client/petstore/csharp/OpenAPIClient-unityWebRequest/src/Org.OpenAPITools/Model/Triangle.cs
@@ -279,7 +279,6 @@ namespace Org.OpenAPITools.Model
return hashCode;
}
}
-
}
///