Skip to content

Commit 340b7bd

Browse files
authored
fix(specs): correct type for taskID APIC-478 (#504)
1 parent 27f5e4a commit 340b7bd

File tree

23 files changed

+97
-68
lines changed

23 files changed

+97
-68
lines changed

generators/src/main/java/com/algolia/codegen/cts/ParametersWithDataType.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -401,11 +401,15 @@ private void handlePrimitive(
401401
Map<String, Object> testOutput,
402402
IJsonSchemaValidationProperties spec
403403
) throws CTSException {
404-
inferDataType(param, null, testOutput);
405-
if (
406-
spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType
407-
) {
408-
testOutput.put("isAnyType", true);
404+
if (isPrimitiveType(spec)) {
405+
transferPrimitiveData(spec, testOutput);
406+
} else {
407+
inferDataType(param, null, testOutput);
408+
if (
409+
spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType
410+
) {
411+
testOutput.put("isAnyType", true);
412+
}
409413
}
410414
testOutput.put("value", param);
411415
}
@@ -439,6 +443,16 @@ private boolean isEnum(IJsonSchemaValidationProperties param) {
439443
return false;
440444
}
441445

446+
private boolean isPrimitiveType(IJsonSchemaValidationProperties param) {
447+
if (param instanceof CodegenParameter) {
448+
return ((CodegenParameter) param).isPrimitiveType;
449+
}
450+
if (param instanceof CodegenProperty) {
451+
return ((CodegenProperty) param).isPrimitiveType;
452+
}
453+
return false;
454+
}
455+
442456
private String inferDataType(
443457
Object param,
444458
CodegenParameter spec,
@@ -472,6 +486,31 @@ private String inferDataType(
472486
}
473487
}
474488

489+
private void transferPrimitiveData(
490+
IJsonSchemaValidationProperties spec,
491+
Map<String, Object> output
492+
) throws CTSException {
493+
switch (getTypeName(spec)) {
494+
case "String":
495+
output.put("isString", true);
496+
break;
497+
case "Integer":
498+
output.put("isInteger", true);
499+
break;
500+
case "Long":
501+
output.put("isLong", true);
502+
break;
503+
case "Double":
504+
output.put("isDouble", true);
505+
break;
506+
case "Boolean":
507+
output.put("isBoolean", true);
508+
break;
509+
default:
510+
throw new CTSException("Unknown primitive: " + getTypeName(spec));
511+
}
512+
}
513+
475514
private IJsonSchemaValidationProperties findMatchingOneOf(
476515
Object param,
477516
CodegenModel model

specs/abtesting/common/schemas/ABTestResponse.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ABTestResponse:
77
abTestID:
88
$ref: '../parameters.yml#/abTestID'
99
taskID:
10-
$ref: '../../../common/parameters.yml#/taskID'
10+
$ref: '../../../common/responses/common.yml#/taskID'
1111
required:
1212
- abTestID
1313
- index

specs/analytics/paths/status/getStatus.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ get:
1919
- updatedAt
2020
properties:
2121
updatedAt:
22-
$ref: '../../../common/parameters.yml#/updatedAt'
22+
$ref: '../../../common/responses/common.yml#/updatedAt'
2323
'400':
2424
$ref: '../../../common/responses/BadRequest.yml'
2525
'402':

specs/common/parameters.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,6 @@ Limit:
9494
default: 10
9595

9696
# misc
97-
taskID:
98-
type: integer
99-
description: taskID of the task to wait for.
100-
10197
objectID:
10298
type: string
10399
description: Unique identifier of the object.
@@ -106,37 +102,6 @@ id:
106102
type: string
107103
description: objectID of the inserted object.
108104

109-
objectIDs:
110-
type: array
111-
items:
112-
type: string
113-
description: List of objectID.
114-
115-
queryID:
116-
type: string
117-
pattern: '^[a-f0-9]{32}$'
118-
example: 43b15df305339e827f0ac0bdc5ebcaa7
119-
120-
abTestID:
121-
type: integer
122-
description: If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.
123-
124-
abTestVariantID:
125-
type: integer
126-
description: If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used.
127-
128-
createdAt:
129-
type: string
130-
description: Date of creation (ISO-8601 format).
131-
132-
updatedAt:
133-
type: string
134-
description: Date of last update (ISO-8601 format).
135-
136-
deletedAt:
137-
type: string
138-
description: Date of deletion (ISO-8601 format).
139-
140105
indexName:
141106
type: string
142107
example: products

specs/common/responses/CreatedAt.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ content:
1010
- createdAt
1111
properties:
1212
createdAt:
13-
$ref: '../parameters.yml#/createdAt'
13+
$ref: '../responses/common.yml#/createdAt'

specs/common/responses/DeletedAt.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ content:
1111
- deletedAt
1212
properties:
1313
taskID:
14-
$ref: '../parameters.yml#/taskID'
14+
$ref: '../responses/common.yml#/taskID'
1515
deletedAt:
16-
$ref: '../parameters.yml#/deletedAt'
16+
$ref: '../responses/common.yml#/deletedAt'

specs/common/responses/UpdatedAt.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ content:
1111
- updatedAt
1212
properties:
1313
taskID:
14-
$ref: '../parameters.yml#/taskID'
14+
$ref: '../responses/common.yml#/taskID'
1515
updatedAt:
16-
$ref: '../parameters.yml#/updatedAt'
16+
$ref: '../responses/common.yml#/updatedAt'

specs/common/responses/UpdatedAtWithObjectId.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ content:
88
type: object
99
properties:
1010
taskID:
11-
$ref: '../parameters.yml#/taskID'
11+
$ref: '../responses/common.yml#/taskID'
1212
updatedAt:
13-
$ref: '../parameters.yml#/updatedAt'
13+
$ref: '../responses/common.yml#/updatedAt'
1414
objectID:
1515
$ref: '../parameters.yml#/objectID'

specs/common/responses/common.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
taskID:
2+
type: integer
3+
format: int64
4+
description: taskID of the task to wait for.
5+
6+
objectIDs:
7+
type: array
8+
items:
9+
type: string
10+
description: List of objectID.
11+
12+
createdAt:
13+
type: string
14+
description: Date of creation (ISO-8601 format).
15+
16+
updatedAt:
17+
type: string
18+
description: Date of last update (ISO-8601 format).
19+
20+
deletedAt:
21+
type: string
22+
description: Date of deletion (ISO-8601 format).

specs/search/common/schemas/SearchResponse.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,11 @@ baseSearchResponse:
4343
- params
4444
properties:
4545
abTestID:
46-
$ref: '../../../common/parameters.yml#/abTestID'
46+
type: integer
47+
description: If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.
4748
abTestVariantID:
48-
$ref: '../../../common/parameters.yml#/abTestVariantID'
49+
type: integer
50+
description: If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used.
4951
aroundLatLng:
5052
type: string
5153
description: The computed geo location.

0 commit comments

Comments
 (0)