Skip to content

Commit

Permalink
samples update
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanAldrich committed Dec 4, 2024
1 parent 336d470 commit 88158f7
Show file tree
Hide file tree
Showing 183 changed files with 8,367 additions and 1,420 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Model;
using System;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
using System.Threading;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
#if !NET6_0_OR_GREATER
using System.Web;
#endif
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ public static string ParameterToString(object obj, IReadableConfiguration config
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15T13:45:30.0000000
return dateTimeOffset.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
#if NET6_0_OR_GREATER
if (obj is DateOnly dateOnly)
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15
return dateOnly.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
#endif
if (obj is bool boolean)
return boolean ? "true" : "false";
if (obj is ICollection collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
using System.Threading;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
#if !NET6_0_OR_GREATER
using System.Web;
#endif
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using RestSharp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public static string ParameterToString(object obj, IReadableConfiguration config
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15T13:45:30.0000000
return dateTimeOffset.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
#if NET6_0_OR_GREATER
if (obj is DateOnly dateOnly)
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15
return dateOnly.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
#endif
if (obj is bool boolean)
return boolean ? "true" : "false";
if (obj is ICollection collection) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,25 @@ public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Thr
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));

httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;

#if NET6_0_OR_GREATER
httpRequestMessageLocalVar.Method = HttpMethod.Get;
#else
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
#endif

DateTime requestedAtLocalVar = DateTime.UtcNow;

using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
#if NET6_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ILogger<GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<GetApiKeysIdApiResponse>();

GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
GetApiKeysIdApiResponse apiResponseLocalVar = new GetApiKeysIdApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);

AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,25 @@ public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Thr
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));

httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;

#if NET6_0_OR_GREATER
httpRequestMessageLocalVar.Method = HttpMethod.Get;
#else
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
#endif

DateTime requestedAtLocalVar = DateTime.UtcNow;

using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
#if NET6_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ILogger<APIKEYSApi.GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<APIKEYSApi.GetApiKeysIdApiResponse>();

APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new GetApiKeysIdApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);

Check failure on line 243 in samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/APIKeys0Api.cs

View workflow job for this annotation

GitHub Actions / Build .Net projects (samples/client/petstore/csharp/generichost/latest/Tags)

The type or namespace name 'GetApiKeysIdApiResponse' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 243 in samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/APIKeys0Api.cs

View workflow job for this annotation

GitHub Actions / Build .Net projects (samples/client/petstore/csharp/generichost/latest/Tags)

The type or namespace name 'GetApiKeysIdApiResponse' could not be found (are you missing a using directive or an assembly reference?)

AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,25 @@ public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Thr
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));

httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;

#if NET6_0_OR_GREATER
httpRequestMessageLocalVar.Method = HttpMethod.Get;
#else
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
#endif

DateTime requestedAtLocalVar = DateTime.UtcNow;

using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
#if NET6_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ILogger<APIKEYSApi.GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<APIKEYSApi.GetApiKeysIdApiResponse>();

APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new GetApiKeysIdApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);

Check failure on line 243 in samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/ApiKeys1Api.cs

View workflow job for this annotation

GitHub Actions / Build .Net projects (samples/client/petstore/csharp/generichost/latest/Tags)

The type or namespace name 'GetApiKeysIdApiResponse' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 243 in samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/ApiKeys1Api.cs

View workflow job for this annotation

GitHub Actions / Build .Net projects (samples/client/petstore/csharp/generichost/latest/Tags)

The type or namespace name 'GetApiKeysIdApiResponse' could not be found (are you missing a using directive or an assembly reference?)

AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ public static string ApiKeyHeaderToString(ApiKeyHeader value)
/// <param name="options"></param>
/// <param name="result"></param>
/// <returns></returns>
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? result)
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
out T
#if NET6_0_OR_GREATER
?
#endif
result)
{
try
{
Expand All @@ -95,7 +103,15 @@ public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
/// <param name="options"></param>
/// <param name="result"></param>
/// <returns></returns>
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? result)
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options,
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
out T
#if NET6_0_OR_GREATER
?
#endif
result)
{
try
{
Expand Down Expand Up @@ -142,8 +158,10 @@ public static string SanitizeFilename(string filename)
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15T13:45:30.0000000
return dateTimeOffset.ToString(format);
#if NET6_0_OR_GREATER
if (obj is DateOnly dateOnly)
return dateOnly.ToString(format);
#endif
if (obj is bool boolean)
return boolean
? "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public HostConfiguration(IServiceCollection services)
_jsonOptions.Converters.Add(new DateTimeNullableJsonConverter());
_jsonOptions.Converters.Add(new DateOnlyJsonConverter());
_jsonOptions.Converters.Add(new DateOnlyNullableJsonConverter());
JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new(_jsonOptions);
JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new JsonSerializerOptionsProvider(_jsonOptions);
_services.AddSingleton(jsonSerializerOptionsProvider);
_services.AddSingleton<IApiFactory, ApiFactory>();
_services.AddSingleton<APIKEYSApiEvents>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,21 @@ public async Task<IListApiResponse> ListAsync(string personId, System.Threading.

if (acceptLocalVar != null)
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
#if NET6_0_OR_GREATER
httpRequestMessageLocalVar.Method = HttpMethod.Get;
#else
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
#endif

DateTime requestedAtLocalVar = DateTime.UtcNow;

using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false);
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
#if NET6_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ILogger<ListApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<ListApiResponse>();

Expand Down Expand Up @@ -318,15 +326,24 @@ public Org.OpenAPITools.Model.Person Ok()
// This logic may be modified with the AsModel.mustache template
return IsOk
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Person>(RawContent, _jsonSerializerOptions)
: default;
:
#if NET6_0_OR_GREATER
null
#else
default
#endif;
}

/// <summary>
/// Returns true if the response is 200 Ok and the deserialized response is not null
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public bool TryOk(out Org.OpenAPITools.Model.Person result)
public bool TryOk(
#if NET6_0_OR_GREATER
[NotNullWhen(true)]
#endif
out Org.OpenAPITools.Model.Person result)
{
result = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public interface IOk<TType> : IApiResponse
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
bool TryOk(out TType result);
bool TryOk(
#if NET6_0_OR_GREATER
[NotNullWhen(true)]
#endif
out TType result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ static ClientUtils()
/// <param name="options"></param>
/// <param name="result"></param>
/// <returns></returns>
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options, out T result)
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
out T result)
{
try
{
Expand All @@ -82,7 +86,11 @@ public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
/// <param name="options"></param>
/// <param name="result"></param>
/// <returns></returns>
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options, out T result)
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options,
#if NET6_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
out T result)
{
try
{
Expand Down Expand Up @@ -129,6 +137,10 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
// For example: 2009-06-15T13:45:30.0000000
return dateTimeOffset.ToString(format);
#if NET6_0_OR_GREATER
if (obj is DateOnly dateOnly)
return dateOnly.ToString(format);
#endif
if (obj is bool boolean)
return boolean
? "true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,21 @@ public async Task<IRootGetApiResponse> RootGetAsync(System.Threading.Cancellatio

if (acceptLocalVar != null)
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
#if NET6_0_OR_GREATER
httpRequestMessageLocalVar.Method = HttpMethod.Get;
#else
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
#endif

DateTime requestedAtLocalVar = DateTime.UtcNow;

using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
{
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false);
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
#if NET6_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ILogger<RootGetApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<RootGetApiResponse>();

Expand Down Expand Up @@ -292,15 +300,24 @@ public Org.OpenAPITools.Model.Fruit Ok()
// This logic may be modified with the AsModel.mustache template
return IsOk
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Fruit>(RawContent, _jsonSerializerOptions)
: default;
:
#if NET6_0_OR_GREATER
null
#else
default
#endif;
}

/// <summary>
/// Returns true if the response is 200 Ok and the deserialized response is not null
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
public bool TryOk(out Org.OpenAPITools.Model.Fruit result)
public bool TryOk(
#if NET6_0_OR_GREATER
[NotNullWhen(true)]
#endif
out Org.OpenAPITools.Model.Fruit result)
{
result = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public interface IOk<TType> : IApiResponse
/// </summary>
/// <param name="result"></param>
/// <returns></returns>
bool TryOk(out TType result);
bool TryOk(
#if NET6_0_OR_GREATER
[NotNullWhen(true)]
#endif
out TType result);
}
}
Loading

0 comments on commit 88158f7

Please sign in to comment.