Skip to content

Commit

Permalink
feat(specs): update Insights API spec (#2376)
Browse files Browse the repository at this point in the history
Co-authored-by: shortcuts <vannicattec@gmail.com>
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
Co-authored-by: Morgan Leroi <morgan.leroi@gmail.com>
  • Loading branch information
4 people authored Jan 15, 2024
1 parent 5ca07a2 commit 7c5ba32
Show file tree
Hide file tree
Showing 30 changed files with 470 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ internal class HttpTransport
private readonly AlgoliaConfig _algoliaConfig;
private string _errorMessage;

private class VoidResult
{
}

/// <summary>
/// Instantiate the transport class with the given configuration and requester
/// </summary>
Expand Down Expand Up @@ -52,6 +56,19 @@ public async Task<TResult> ExecuteRequestAsync<TResult>(HttpMethod method, strin
await ExecuteRequestAsync<TResult, object>(method, uri, requestOptions, ct)
.ConfigureAwait(false);

/// <summary>
/// Execute the request, without response
/// </summary>
/// <param name="method">The HttpMethod <see cref="HttpMethod"/></param>
/// <param name="uri">The endpoint URI</param>
/// <param name="requestOptions">Add extra http header or query parameters to Algolia</param>
/// <param name="ct">Optional cancellation token</param>
public async Task ExecuteRequestAsync(HttpMethod method, string uri,
InternalRequestOptions requestOptions = null,
CancellationToken ct = default) =>
await ExecuteRequestAsync<VoidResult>(method, uri, requestOptions, ct)
.ConfigureAwait(false);

/// <summary>
/// Call api with retry strategy
/// </summary>
Expand Down Expand Up @@ -93,7 +110,8 @@ private async Task<TResult> ExecuteRequestAsync<TResult, TData>(HttpMethod metho
foreach (var host in _retryStrategy.GetTryableHost(callType))
{
request.Body = CreateRequestContent(requestOptions?.Data, request.CanCompress);
request.Uri = BuildUri(host.Url, uri, requestOptions?.CustomPathParameters, requestOptions?.PathParameters, requestOptions?.QueryParameters);
request.Uri = BuildUri(host.Url, uri, requestOptions?.CustomPathParameters, requestOptions?.PathParameters,
requestOptions?.QueryParameters);
var requestTimeout =
TimeSpan.FromTicks((requestOptions?.Timeout ?? GetTimeOut(callType)).Ticks * (host.RetryCount + 1));

Expand All @@ -111,6 +129,11 @@ private async Task<TResult> ExecuteRequestAsync<TResult, TData>(HttpMethod metho
switch (_retryStrategy.Decide(host, response))
{
case RetryOutcomeType.Success:
if (typeof(TResult) == typeof(VoidResult))
{
return new VoidResult() as TResult;
}

return await _serializer.Deserialize<TResult>(response.Body);
case RetryOutcomeType.Retry:
continue;
Expand Down Expand Up @@ -158,7 +181,8 @@ private IDictionary<string, string> GenerateHeaders(IDictionary<string, string>
/// <param name="pathParameters"></param>
/// <param name="optionalQueryParameters"></param>
/// <returns></returns>
private Uri BuildUri(string url, string baseUri, IDictionary<string, string> customPathParameters = null, IDictionary<string, string> pathParameters = null,
private Uri BuildUri(string url, string baseUri, IDictionary<string, string> customPathParameters = null,
IDictionary<string, string> pathParameters = null,
IDictionary<string, string> optionalQueryParameters = null)
{
var path = $"{baseUri}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public <T> T deserialize(InputStream stream, JavaType returnType) {
* @param innerType The parameterized type.
* @return A JavaType representation of the parameterized class.
*/
public JavaType getJavaType(@Nonnull Class<?> returnType, @Nonnull Class<?> innerType) {
public JavaType getJavaType(Class<?> returnType, @Nonnull Class<?> innerType) {
if (returnType == null) {
return null;
}

return mapper.getTypeFactory().constructParametricType(returnType, innerType);
}

Expand All @@ -73,7 +77,11 @@ public JavaType getJavaType(@Nonnull Class<?> returnType, @Nonnull Class<?> inne
* @param returnType The main class type.
* @return A JavaType representation of the parameterized class.
*/
public JavaType getJavaType(@Nonnull TypeReference<?> returnType) {
public JavaType getJavaType(TypeReference<?> returnType) {
if (returnType == null) {
return null;
}

return mapper.getTypeFactory().constructType(returnType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,20 @@ private IJsonSchemaValidationProperties findMatchingOneOf(Object param, CodegenM
// for object, check which has the most of property in common
int maxCount = 0;
CodegenModel bestOneOf = model.interfaceModels.get(0);
for (CodegenModel oneOf : model.interfaceModels) {
oneOfLoop:for (CodegenModel oneOf : model.interfaceModels) {
if (oneOf.vars.size() == 0) {
continue;
}

Map<String, Object> map = (Map<String, Object>) param;

// if a required property is not in param, it's not a match
for (CodegenProperty prop : oneOf.requiredVars) {
if (!map.containsKey(prop.baseName)) {
continue oneOfLoop;
}
}

int commonCount = 0;
for (String prop : map.keySet()) {
for (CodegenProperty propOneOf : oneOf.vars) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.*;
import org.openapitools.codegen.CodegenModel;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenResponse;
import org.openapitools.codegen.SupportingFile;

public class TestsRequest extends TestsGenerator {
Expand Down Expand Up @@ -143,6 +144,16 @@ public void run(Map<String, CodegenModel> models, Map<String, CodegenOperation>
test.put("requestOptions", requestOptions);
}

// Determines whether the endpoint is expected to return a response payload deserialized
// and therefore a variable to store it into.
test.put("hasResponsePayload", true);

for (CodegenResponse response : ope.responses) {
if (response.code.equals("204")) {
test.put("hasResponsePayload", false);
}
}

paramsType.enhanceParameters(req.parameters, test, ope);
tests.add(test);
} catch (CTSException e) {
Expand Down
14 changes: 8 additions & 6 deletions specs/insights/common/schemas/AddedToCartObjectIDs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ properties:
$ref: './EventAttributes.yml#/index'
objectIDs:
$ref: './EventAttributes.yml#/objectIDs'
objectData:
$ref: './EventAttributes.yml#/objectDataList'
currency:
$ref: './EventAttributes.yml#/currency'
userToken:
$ref: './EventAttributes.yml#/userToken'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
currency:
$ref: './EventAttributes.yml#/currency'
objectData:
$ref: './EventAttributes.yml#/objectDataList'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
value:
$ref: './EventAttributes.yml#/value'
required:
- eventName
- eventType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ properties:
$ref: './EventAttributes.yml#/queryID'
objectIDs:
$ref: './EventAttributes.yml#/objectIDs'
objectData:
$ref: './EventAttributes.yml#/objectDataAfterSearchList'
currency:
$ref: './EventAttributes.yml#/currency'
userToken:
$ref: './EventAttributes.yml#/userToken'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
currency:
$ref: './EventAttributes.yml#/currency'
objectData:
$ref: './EventAttributes.yml#/objectDataAfterSearchList'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
value:
$ref: './EventAttributes.yml#/value'
required:
- eventName
- eventType
Expand Down
4 changes: 2 additions & 2 deletions specs/insights/common/schemas/ClickedFilters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ properties:
$ref: './EventAttributes.yml#/filters'
userToken:
$ref: './EventAttributes.yml#/userToken'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
required:
- eventName
- eventType
Expand Down
2 changes: 2 additions & 0 deletions specs/insights/common/schemas/ClickedObjectIDs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ properties:
$ref: './EventAttributes.yml#/objectIDs'
userToken:
$ref: './EventAttributes.yml#/userToken'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
required:
Expand Down
4 changes: 2 additions & 2 deletions specs/insights/common/schemas/ClickedObjectIDsAfterSearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ properties:
$ref: './EventAttributes.yml#/queryID'
userToken:
$ref: './EventAttributes.yml#/userToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
required:
- eventName
- eventType
Expand Down
4 changes: 2 additions & 2 deletions specs/insights/common/schemas/ConvertedFilters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ properties:
$ref: './EventAttributes.yml#/filters'
userToken:
$ref: './EventAttributes.yml#/userToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
required:
- eventName
- eventType
Expand Down
4 changes: 2 additions & 2 deletions specs/insights/common/schemas/ConvertedObjectIDs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ properties:
$ref: './EventAttributes.yml#/objectIDs'
userToken:
$ref: './EventAttributes.yml#/userToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
required:
- eventName
- eventType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ properties:
$ref: './EventAttributes.yml#/queryID'
userToken:
$ref: './EventAttributes.yml#/userToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
authenticatedUserToken:
$ref: './EventAttributes.yml#/authenticatedUserToken'
timestamp:
$ref: './EventAttributes.yml#/timestamp'
required:
- eventName
- eventType
Expand Down
Loading

0 comments on commit 7c5ba32

Please sign in to comment.