Skip to content

Commit

Permalink
update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Nov 16, 2023
2 parents bae20c1 + b510aff commit 485fa01
Show file tree
Hide file tree
Showing 995 changed files with 27,680 additions and 48,992 deletions.
436 changes: 188 additions & 248 deletions modules/openapi-generator/src/main/resources/csharp/ApiClient.mustache

Large diffs are not rendered by default.

533 changes: 164 additions & 369 deletions modules/openapi-generator/src/main/resources/csharp/api.mustache

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
/// </summary>
public {{classname}}()
{
this.IsNullable = true;
this.SchemaType= "anyOf";
IsNullable = true;
SchemaType= "anyOf";
}

{{/isNullable}}
Expand All @@ -33,9 +33,9 @@
/// <param name="actualInstance">An instance of {{dataType}}.</param>
public {{classname}}({{{dataType}}} actualInstance)
{
this.IsNullable = {{#model.isNullable}}true{{/model.isNullable}}{{^model.isNullable}}false{{/model.isNullable}};
this.SchemaType= "anyOf";
this.ActualInstance = actualInstance{{^model.isNullable}}{{^isPrimitiveType}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isPrimitiveType}}{{#isPrimitiveType}}{{#isArray}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isArray}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isFreeFormObject}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isFreeFormObject}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isString}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isString}}{{/isPrimitiveType}}{{/model.isNullable}};
IsNullable = {{#model.isNullable}}true{{/model.isNullable}}{{^model.isNullable}}false{{/model.isNullable}};
SchemaType= "anyOf";
ActualInstance = actualInstance{{^model.isNullable}}{{^isPrimitiveType}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isPrimitiveType}}{{#isPrimitiveType}}{{#isArray}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isArray}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isFreeFormObject}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isFreeFormObject}}{{/isPrimitiveType}}{{#isPrimitiveType}}{{#isString}} ?? throw new ArgumentException("Invalid instance found. Must not be null."){{/isString}}{{/isPrimitiveType}}{{/model.isNullable}};
}

{{/isNull}}
Expand All @@ -58,7 +58,7 @@
{{#anyOf}}
{{^-first}}else {{/-first}}if (value.GetType() == typeof({{{.}}}))
{
this._actualInstance = value;
_actualInstance = value;
}
{{/anyOf}}
else
Expand All @@ -78,7 +78,7 @@
/// <returns>An instance of {{dataType}}</returns>
public {{{dataType}}} Get{{#lambda.titlecase}}{{baseType}}{{/lambda.titlecase}}{{#isArray}}{{#lambda.titlecase}}{{{dataFormat}}}{{/lambda.titlecase}}{{/isArray}}()
{
return ({{{dataType}}})this.ActualInstance;
return ({{{dataType}}})ActualInstance;
}
{{/isNull}}
{{/vendorExtensions.x-duplicated-data-type}}
Expand All @@ -92,7 +92,7 @@
{
var sb = new StringBuilder();
sb.Append("class {{classname}} {\n");
sb.Append(" ActualInstance: ").Append(this.ActualInstance).Append("\n");
sb.Append(" ActualInstance: ").Append(ActualInstance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}
Expand All @@ -103,7 +103,7 @@
/// <returns>JSON string presentation of the object</returns>
public override string ToJson()
{
return JsonConvert.SerializeObject(this.ActualInstance, {{classname}}.SerializerSettings);
return JsonConvert.SerializeObject(ActualInstance, {{classname}}.SerializerSettings);
}

/// <summary>
Expand Down Expand Up @@ -150,7 +150,7 @@
return OpenAPIClientUtils.compareLogic.Compare(this, input as {{classname}}).AreEqual;
{{/useCompareNetObjects}}
{{^useCompareNetObjects}}
return this.Equals(input as {{classname}});
return Equals(input as {{classname}});
{{/useCompareNetObjects}}
}

Expand All @@ -168,7 +168,7 @@
if (input == null)
return false;

return this.ActualInstance.Equals(input.ActualInstance);
return ActualInstance.Equals(input.ActualInstance);
{{/useCompareNetObjects}}
}

Expand All @@ -181,8 +181,8 @@
unchecked // Overflow is fine, just wrap
{
int hashCode = 41;
if (this.ActualInstance != null)
hashCode = hashCode * 59 + this.ActualInstance.GetHashCode();
if (ActualInstance != null)
hashCode = hashCode * 59 + ActualInstance.GetHashCode();
return hashCode;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
{{#isAdditionalPropertiesTrue}}
protected {{classname}}()
{
this.AdditionalProperties = new Dictionary<string, object>();
AdditionalProperties = new Dictionary<string, object>();
}
{{/isAdditionalPropertiesTrue}}
{{/hasOnlyReadOnly}}
Expand All @@ -147,10 +147,10 @@
{
throw new ArgumentNullException("{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} is a required property for {{classname}} and cannot be null");
}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/vendorExtensions.x-csharp-value-type}}
{{#vendorExtensions.x-csharp-value-type}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/vendorExtensions.x-csharp-value-type}}
{{/conditionalSerialization}}
{{#conditionalSerialization}}
Expand All @@ -160,10 +160,10 @@
{
throw new ArgumentNullException("{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} is a required property for {{classname}} and cannot be null");
}
this._{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
_{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/vendorExtensions.x-csharp-value-type}}
{{#vendorExtensions.x-csharp-value-type}}
this._{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
_{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/vendorExtensions.x-csharp-value-type}}
{{/conditionalSerialization}}
{{/required}}
Expand All @@ -178,22 +178,22 @@
{{^conditionalSerialization}}
{{^vendorExtensions.x-csharp-value-type}}
// use default value if no "{{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}}" provided
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? {{#isString}}@{{/isString}}{{{defaultValue}}};
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}} ?? {{#isString}}@{{/isString}}{{{defaultValue}}};
{{/vendorExtensions.x-csharp-value-type}}
{{#vendorExtensions.x-csharp-value-type}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/vendorExtensions.x-csharp-value-type}}
{{/conditionalSerialization}}
{{/defaultValue}}
{{^defaultValue}}
{{^conditionalSerialization}}
this.{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
{{/conditionalSerialization}}
{{#conditionalSerialization}}
this._{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
if (this.{{name}} != null)
_{{name}} = {{#lambda.camelcase_param}}{{name}}{{/lambda.camelcase_param}};
if ({{name}} != null)
{
this._flag{{name}} = true;
_flag{{name}} = true;
}
{{/conditionalSerialization}}
{{/defaultValue}}
Expand All @@ -202,7 +202,7 @@
{{/isInherited}}
{{/vars}}
{{#isAdditionalPropertiesTrue}}
this.AdditionalProperties = new Dictionary<string, object>();
AdditionalProperties = new Dictionary<string, object>();
{{/isAdditionalPropertiesTrue}}
}

Expand Down Expand Up @@ -325,7 +325,7 @@
/// <returns>JSON string presentation of the object</returns>
public {{#parent}}{{^isArray}}{{^isMap}}override {{/isMap}}{{/isArray}}{{/parent}}{{^parent}}virtual {{/parent}}string ToJson()
{
return Newtonsoft.Json.JsonConvert.SerializeObject(this, Newtonsoft.Json.Formatting.Indented);
return JsonConvert.SerializeObject(this, Formatting.Indented);
}
{{#equatable}}

Expand All @@ -340,7 +340,7 @@
return OpenAPIClientUtils.compareLogic.Compare(this, input as {{classname}}).AreEqual;
{{/useCompareNetObjects}}
{{^useCompareNetObjects}}
return this.Equals(input as {{classname}});
return Equals(input as {{classname}});
{{/useCompareNetObjects}}
}

Expand All @@ -361,23 +361,28 @@
}
return {{#vars}}{{#parent}}base.Equals(input) && {{/parent}}{{^isContainer}}
(
this.{{name}} == input.{{name}} ||
{{name}} == input.{{name}} ||
{{^vendorExtensions.x-is-value-type}}
(this.{{name}} != null &&
this.{{name}}.Equals(input.{{name}}))
{{#isNullable}}
({{name}} != null &&
{{name}}.Equals(input.{{name}}))
{{/isNullable}}
{{^isNullable}}
{{name}}.Equals(input.{{name}})
{{/isNullable}}
{{/vendorExtensions.x-is-value-type}}
{{#vendorExtensions.x-is-value-type}}
this.{{name}}.Equals(input.{{name}})
{{name}}.Equals(input.{{name}})
{{/vendorExtensions.x-is-value-type}}
){{^-last}} && {{/-last}}{{/isContainer}}{{#isContainer}}
(
this.{{name}} == input.{{name}} ||
{{^vendorExtensions.x-is-value-type}}this.{{name}} != null &&
{{name}} == input.{{name}} ||
{{^vendorExtensions.x-is-value-type}}{{name}} != null &&
input.{{name}} != null &&
{{/vendorExtensions.x-is-value-type}}this.{{name}}.SequenceEqual(input.{{name}})
{{/vendorExtensions.x-is-value-type}}{{name}}.SequenceEqual(input.{{name}})
){{^-last}} && {{/-last}}{{/isContainer}}{{/vars}}{{^vars}}{{#parent}}base.Equals(input){{/parent}}{{^parent}}false{{/parent}}{{/vars}}{{^isAdditionalPropertiesTrue}};{{/isAdditionalPropertiesTrue}}
{{#isAdditionalPropertiesTrue}}
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
&& (AdditionalProperties.Count == input.AdditionalProperties.Count && !AdditionalProperties.Except(input.AdditionalProperties).Any());
{{/isAdditionalPropertiesTrue}}
{{/useCompareNetObjects}}
}
Expand All @@ -398,19 +403,24 @@
{{/parent}}
{{#vars}}
{{^vendorExtensions.x-is-value-type}}
if (this.{{name}} != null)
{{#isNullable}}
if ({{name}} != null)
{
hashCode = (hashCode * 59) + this.{{name}}.GetHashCode();
hashCode = (hashCode * 59) + {{name}}.GetHashCode();
}
{{/isNullable}}
{{^isNullable}}
hashCode = (hashCode * 59) + {{name}}.GetHashCode();
{{/isNullable}}
{{/vendorExtensions.x-is-value-type}}
{{#vendorExtensions.x-is-value-type}}
hashCode = (hashCode * 59) + this.{{name}}.GetHashCode();
hashCode = (hashCode * 59) + {{name}}.GetHashCode();
{{/vendorExtensions.x-is-value-type}}
{{/vars}}
{{#isAdditionalPropertiesTrue}}
if (this.AdditionalProperties != null)
if (AdditionalProperties != null)
{
hashCode = (hashCode * 59) + this.AdditionalProperties.GetHashCode();
hashCode = (hashCode * 59) + AdditionalProperties.GetHashCode();
}
{{/isAdditionalPropertiesTrue}}
return hashCode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,17 @@

{{^useGenericHost}}
<ItemGroup>
{{^net60OrLater}}
<None Remove="System.Web" />
{{/net60OrLater}}
{{#net48}}
<None Remove="System.Net.Http" />
{{/net48}}
</ItemGroup>
<ItemGroup>
{{^net60OrLater}}
<Reference Include="System.Web" />
{{/net60OrLater}}
{{#net48}}
<Reference Include="System.Net.Http" />
{{/net48}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
Expand All @@ -14,7 +14,7 @@
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
protected IEnumerable<ValidationResult> BaseValidate(ValidationContext validationContext)
{
{{/discriminator}}
{{^discriminator}}
Expand All @@ -24,7 +24,7 @@
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
return this.BaseValidate(validationContext);
}
Expand All @@ -34,7 +34,7 @@
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
protected IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> BaseValidate(ValidationContext validationContext)
protected IEnumerable<ValidationResult> BaseValidate(ValidationContext validationContext)
{
{{/parent}}
{{^parent}}
Expand All @@ -43,7 +43,7 @@
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
IEnumerable<System.ComponentModel.DataAnnotations.ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
IEnumerable<ValidationResult> IValidatableObject.Validate(ValidationContext validationContext)
{
{{/parent}}
{{/discriminator}}
Expand All @@ -64,31 +64,31 @@
// {{{name}}} ({{{dataType}}}) maxLength
if (this.{{{name}}} != null && this.{{{name}}}.Length > {{maxLength}})
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be less than {{maxLength}}.", new [] { "{{{name}}}" });
yield return new ValidationResult("Invalid value for {{{name}}}, length must be less than {{maxLength}}.", new [] { "{{{name}}}" });
}

{{/maxLength}}
{{#minLength}}
// {{{name}}} ({{{dataType}}}) minLength
if (this.{{{name}}} != null && this.{{{name}}}.Length < {{minLength}})
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, length must be greater than {{minLength}}.", new [] { "{{{name}}}" });
yield return new ValidationResult("Invalid value for {{{name}}}, length must be greater than {{minLength}}.", new [] { "{{{name}}}" });
}

{{/minLength}}
{{#maximum}}
// {{{name}}} ({{{dataType}}}) maximum
if ({{#useGenericHost}}{{^required}}this.{{{name}}}Option.IsSet && {{/required}}{{/useGenericHost}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} > ({{{dataType}}}){{maximum}})
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" });
yield return new ValidationResult("Invalid value for {{{name}}}, must be a value less than or equal to {{maximum}}.", new [] { "{{{name}}}" });
}

{{/maximum}}
{{#minimum}}
// {{{name}}} ({{{dataType}}}) minimum
if ({{#useGenericHost}}{{^required}}this.{{{name}}}Option.IsSet && {{/required}}{{/useGenericHost}}this.{{{name}}}{{#useGenericHost}}{{^required}}Option.Value{{/required}}{{/useGenericHost}} < ({{{dataType}}}){{minimum}})
{
yield return new System.ComponentModel.DataAnnotations.ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" });
yield return new ValidationResult("Invalid value for {{{name}}}, must be a value greater than or equal to {{minimum}}.", new [] { "{{{name}}}" });
}

{{/minimum}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ public void deepObject() throws IOException {
"inputOptions[a]", "inputOptions[b]", "inputOptions[c]");
String content = new String(Files.readAllBytes(Paths.get(outputPath + "/src/Org.OpenAPITools/Api/DefaultApi.cs")), StandardCharsets.UTF_8);
int counter = StringUtils.countMatches(content,"inputOptions[a]");
assertEquals(2, counter);
assertEquals(1, counter);
}
}
Loading

0 comments on commit 485fa01

Please sign in to comment.