[csharp][generichost] Remove unnecessary json options (#16483)

* started source generator

* copy the options

* fixed visibility

* added new sample

* discarded changes to existing samples

* discarded changes to existing samples

* build new sample

* changed package name due to file path length limit

* reverted changes to manual tests

* fixed all new manual tests

* inject contexts into api

* only one JsonConstructor

* fixed spacing

* revert samples for easier merge master

* revert unnecessary change

* fixed formatting

* build samples

* reverting unintended commit

* fixing default value

* reverting unintended commit

* removed unnecessary json option
This commit is contained in:
devhl-labs 2023-09-03 04:19:23 -04:00 committed by GitHub
parent 6434c86afd
commit dad677f63d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 28 deletions

View File

@ -140,19 +140,21 @@ namespace {{packageName}}.{{clientPackage}}
/// <summary>
/// Deserializes the server's response
/// </summary>
public T{{nrt?}} AsModel(System.Text.Json.JsonSerializerOptions{{nrt?}} options = null)
public T{{nrt?}} AsModel()
{
{{#lambda.trimTrailingWithNewLine}}
{{>AsModel}}
{{/lambda.trimTrailingWithNewLine}}
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel({{^netStandard}}[NotNullWhen(true)] {{/netStandard}}out T{{nrt?}} model, System.Text.Json.JsonSerializerOptions{{nrt?}} options = null)
public bool TryToModel({{^netStandard}}[NotNullWhen(true)] {{/netStandard}}out T{{nrt?}} model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch

View File

@ -1,4 +1,4 @@
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);

View File

@ -146,22 +146,22 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Deserializes the server's response
/// </summary>
public T? AsModel(System.Text.Json.JsonSerializerOptions? options = null)
public T? AsModel()
{
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel([NotNullWhen(true)] out T? model, System.Text.Json.JsonSerializerOptions? options = null)
public bool TryToModel([NotNullWhen(true)] out T? model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch

View File

@ -144,22 +144,22 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Deserializes the server's response
/// </summary>
public T AsModel(System.Text.Json.JsonSerializerOptions options = null)
public T AsModel()
{
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel([NotNullWhen(true)] out T model, System.Text.Json.JsonSerializerOptions options = null)
public bool TryToModel([NotNullWhen(true)] out T model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch

View File

@ -146,22 +146,22 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Deserializes the server's response
/// </summary>
public T? AsModel(System.Text.Json.JsonSerializerOptions? options = null)
public T? AsModel()
{
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel([NotNullWhen(true)] out T? model, System.Text.Json.JsonSerializerOptions? options = null)
public bool TryToModel([NotNullWhen(true)] out T? model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch

View File

@ -146,22 +146,22 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Deserializes the server's response
/// </summary>
public T? AsModel(System.Text.Json.JsonSerializerOptions? options = null)
public T? AsModel()
{
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel([NotNullWhen(true)] out T? model, System.Text.Json.JsonSerializerOptions? options = null)
public bool TryToModel([NotNullWhen(true)] out T? model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch

View File

@ -146,22 +146,22 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Deserializes the server's response
/// </summary>
public T? AsModel(System.Text.Json.JsonSerializerOptions? options = null)
public T? AsModel()
{
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel([NotNullWhen(true)] out T? model, System.Text.Json.JsonSerializerOptions? options = null)
public bool TryToModel([NotNullWhen(true)] out T? model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch

View File

@ -144,22 +144,22 @@ namespace Org.OpenAPITools.Client
/// <summary>
/// Deserializes the server's response
/// </summary>
public T AsModel(System.Text.Json.JsonSerializerOptions options = null)
public T AsModel()
{
// This logic may be modified with the AsModel.mustache template
return IsSuccessStatusCode
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, options ?? _jsonSerializerOptions)
? System.Text.Json.JsonSerializer.Deserialize<T>(RawContent, _jsonSerializerOptions)
: default(T);
}
/// <summary>
/// Returns true when the model can be deserialized
/// </summary>
public bool TryToModel(out T model, System.Text.Json.JsonSerializerOptions options = null)
public bool TryToModel(out T model)
{
try
{
model = AsModel(options);
model = AsModel();
return model != null;
}
catch