Skip to content

Commit

Permalink
Merge pull request #12 from TBCBank/bugfix/AddMediaTypeParametersInPo…
Browse files Browse the repository at this point in the history
…stJsonAsync

Fix ContentType bug
  • Loading branch information
lachinchaladze authored Aug 20, 2022
2 parents ac59b77 + 5ea5a92 commit efe7f05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
28 changes: 12 additions & 16 deletions src/TBC.OpenAPI.SDK.Core/HttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ public async Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TRespo



public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync<TRequestData, TResponseData>(path, data, null, null, mediaType, cancellationToken);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync<TResponseData>(path, content, null, null, mediaType, cancellationToken);

public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync<TRequestData, TResponseData>(path, data, query, null,mediaType, cancellationToken);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync<TResponseData>(path, content, query, null,mediaType, cancellationToken);

public async Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
public async Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
{
var httpClient = GetHttpClient();
var requestMessage = CreateRequestMessage(httpClient, HttpMethod.Post, path, query, headers);
var json = JsonSerializer.Serialize(data, _jsonSerializerOptions);
requestMessage.Content = new StringContent(json, Encoding.UTF8, mediaType);
requestMessage.Content = content;
return await SendRequestMessage<TResponseData>(httpClient, requestMessage, cancellationToken).ConfigureAwait(false);
}

Expand All @@ -94,20 +93,17 @@ public async Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TReq
}


public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync(path, content, null, null,mediaType, cancellationToken);

public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync(path, content, query, null, mediaType, cancellationToken);

public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync(path, data, null, null,mediaType, cancellationToken);

public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
=> PostJsonAsync(path, data, query, null, mediaType, cancellationToken);

public async Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
public async Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default)
{
var httpClient = GetHttpClient();
var requestMessage = CreateRequestMessage(httpClient, HttpMethod.Post, path, query, headers);
var json = JsonSerializer.Serialize(data, _jsonSerializerOptions);
requestMessage.Content = new StringContent(json, Encoding.UTF8, mediaType);
requestMessage.Content = content;
return await SendRequestMessage(httpClient, requestMessage, cancellationToken).ConfigureAwait(false);
}

Expand Down
12 changes: 6 additions & 6 deletions src/TBC.OpenAPI.SDK.Core/IHttpHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public interface IHttpHelper<TClient>
public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default);


public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TRequestData, TResponseData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponse<TResponseData>> PostJsonAsync<TResponseData>(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default);



Expand All @@ -30,9 +30,9 @@ public interface IHttpHelper<TClient>
public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, CancellationToken cancellationToken = default);


public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync<TRequestData>(string path, TRequestData data, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
public Task<ApiResponseBase> PostJsonAsync(string path, StringContent content, QueryParamCollection? query = null, HeaderParamCollection? headers = null, string mediaType = "application/json", CancellationToken cancellationToken = default);
#endregion

#region Put
Expand Down

0 comments on commit efe7f05

Please sign in to comment.