Skip to content

Commit

Permalink
fix(specs): correct type for taskID APIC-478 (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
millotp authored May 16, 2022
1 parent 27f5e4a commit 340b7bd
Show file tree
Hide file tree
Showing 23 changed files with 97 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -401,11 +401,15 @@ private void handlePrimitive(
Map<String, Object> testOutput,
IJsonSchemaValidationProperties spec
) throws CTSException {
inferDataType(param, null, testOutput);
if (
spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType
) {
testOutput.put("isAnyType", true);
if (isPrimitiveType(spec)) {
transferPrimitiveData(spec, testOutput);
} else {
inferDataType(param, null, testOutput);
if (
spec instanceof CodegenParameter && ((CodegenParameter) spec).isAnyType
) {
testOutput.put("isAnyType", true);
}
}
testOutput.put("value", param);
}
Expand Down Expand Up @@ -439,6 +443,16 @@ private boolean isEnum(IJsonSchemaValidationProperties param) {
return false;
}

private boolean isPrimitiveType(IJsonSchemaValidationProperties param) {
if (param instanceof CodegenParameter) {
return ((CodegenParameter) param).isPrimitiveType;
}
if (param instanceof CodegenProperty) {
return ((CodegenProperty) param).isPrimitiveType;
}
return false;
}

private String inferDataType(
Object param,
CodegenParameter spec,
Expand Down Expand Up @@ -472,6 +486,31 @@ private String inferDataType(
}
}

private void transferPrimitiveData(
IJsonSchemaValidationProperties spec,
Map<String, Object> output
) throws CTSException {
switch (getTypeName(spec)) {
case "String":
output.put("isString", true);
break;
case "Integer":
output.put("isInteger", true);
break;
case "Long":
output.put("isLong", true);
break;
case "Double":
output.put("isDouble", true);
break;
case "Boolean":
output.put("isBoolean", true);
break;
default:
throw new CTSException("Unknown primitive: " + getTypeName(spec));
}
}

private IJsonSchemaValidationProperties findMatchingOneOf(
Object param,
CodegenModel model
Expand Down
2 changes: 1 addition & 1 deletion specs/abtesting/common/schemas/ABTestResponse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ABTestResponse:
abTestID:
$ref: '../parameters.yml#/abTestID'
taskID:
$ref: '../../../common/parameters.yml#/taskID'
$ref: '../../../common/responses/common.yml#/taskID'
required:
- abTestID
- index
Expand Down
2 changes: 1 addition & 1 deletion specs/analytics/paths/status/getStatus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ get:
- updatedAt
properties:
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
$ref: '../../../common/responses/common.yml#/updatedAt'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
35 changes: 0 additions & 35 deletions specs/common/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ Limit:
default: 10

# misc
taskID:
type: integer
description: taskID of the task to wait for.

objectID:
type: string
description: Unique identifier of the object.
Expand All @@ -106,37 +102,6 @@ id:
type: string
description: objectID of the inserted object.

objectIDs:
type: array
items:
type: string
description: List of objectID.

queryID:
type: string
pattern: '^[a-f0-9]{32}$'
example: 43b15df305339e827f0ac0bdc5ebcaa7

abTestID:
type: integer
description: If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.

abTestVariantID:
type: integer
description: If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used.

createdAt:
type: string
description: Date of creation (ISO-8601 format).

updatedAt:
type: string
description: Date of last update (ISO-8601 format).

deletedAt:
type: string
description: Date of deletion (ISO-8601 format).

indexName:
type: string
example: products
Expand Down
2 changes: 1 addition & 1 deletion specs/common/responses/CreatedAt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ content:
- createdAt
properties:
createdAt:
$ref: '../parameters.yml#/createdAt'
$ref: '../responses/common.yml#/createdAt'
4 changes: 2 additions & 2 deletions specs/common/responses/DeletedAt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ content:
- deletedAt
properties:
taskID:
$ref: '../parameters.yml#/taskID'
$ref: '../responses/common.yml#/taskID'
deletedAt:
$ref: '../parameters.yml#/deletedAt'
$ref: '../responses/common.yml#/deletedAt'
4 changes: 2 additions & 2 deletions specs/common/responses/UpdatedAt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ content:
- updatedAt
properties:
taskID:
$ref: '../parameters.yml#/taskID'
$ref: '../responses/common.yml#/taskID'
updatedAt:
$ref: '../parameters.yml#/updatedAt'
$ref: '../responses/common.yml#/updatedAt'
4 changes: 2 additions & 2 deletions specs/common/responses/UpdatedAtWithObjectId.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ content:
type: object
properties:
taskID:
$ref: '../parameters.yml#/taskID'
$ref: '../responses/common.yml#/taskID'
updatedAt:
$ref: '../parameters.yml#/updatedAt'
$ref: '../responses/common.yml#/updatedAt'
objectID:
$ref: '../parameters.yml#/objectID'
22 changes: 22 additions & 0 deletions specs/common/responses/common.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
taskID:
type: integer
format: int64
description: taskID of the task to wait for.

objectIDs:
type: array
items:
type: string
description: List of objectID.

createdAt:
type: string
description: Date of creation (ISO-8601 format).

updatedAt:
type: string
description: Date of last update (ISO-8601 format).

deletedAt:
type: string
description: Date of deletion (ISO-8601 format).
6 changes: 4 additions & 2 deletions specs/search/common/schemas/SearchResponse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ baseSearchResponse:
- params
properties:
abTestID:
$ref: '../../../common/parameters.yml#/abTestID'
type: integer
description: If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.
abTestVariantID:
$ref: '../../../common/parameters.yml#/abTestVariantID'
type: integer
description: If a search encounters an index that is being A/B tested, abTestVariantID reports the variant ID of the index used.
aroundLatLng:
type: string
description: The computed geo location.
Expand Down
2 changes: 1 addition & 1 deletion specs/search/common/schemas/listIndicesResponse.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ indice:
type: string
description: Index creation date. An empty string means that the index has no records.
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
$ref: '../../../common/responses/common.yml#/updatedAt'
entries:
type: integer
description: Number of records contained in the index.
Expand Down
1 change: 1 addition & 0 deletions specs/search/paths/advanced/getTask.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ get:
required: true
schema:
type: integer
format: int64
example: '13235'
responses:
'200':
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/keys/common/schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ createdAtObject:
- createdAt
properties:
createdAt:
$ref: '../../../../common/parameters.yml#/createdAt'
$ref: '../../../../common/responses/common.yml#/createdAt'

key:
allOf:
Expand All @@ -69,7 +69,7 @@ addApiKeyResponse:
key:
$ref: '#/keyString'
createdAt:
$ref: '../../../../common/parameters.yml#/createdAt'
$ref: '../../../../common/responses/common.yml#/createdAt'
required:
- key
- createdAt
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/keys/key.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ put:
key:
$ref: 'common/schemas.yml#/keyString'
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
$ref: '../../../common/responses/common.yml#/updatedAt'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down Expand Up @@ -83,7 +83,7 @@ delete:
- deletedAt
properties:
deletedAt:
$ref: '../../../common/parameters.yml#/deletedAt'
$ref: '../../../common/responses/common.yml#/deletedAt'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/multiclusters/searchUserIds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ post:
hitsPerPage:
$ref: '../../../common/parameters.yml#/hitsPerPage'
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
$ref: '../../../common/responses/common.yml#/updatedAt'
required:
- hits
- nbHits
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/multiclusters/userId.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ delete:
additionalProperties: false
properties:
deletedAt:
$ref: '../../../common/parameters.yml#/deletedAt'
$ref: '../../../common/responses/common.yml#/deletedAt'
required:
- deletedAt
'400':
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/objects/batch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ post:
additionalProperties: false
properties:
taskID:
$ref: '../../../common/parameters.yml#/taskID'
$ref: '../../../common/responses/common.yml#/taskID'
objectIDs:
$ref: '../../../common/parameters.yml#/objectIDs'
$ref: '../../../common/responses/common.yml#/objectIDs'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/objects/multipleBatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ post:
type: object
description: List of tasksIDs per index.
objectIDs:
$ref: '../../../common/parameters.yml#/objectIDs'
$ref: '../../../common/responses/common.yml#/objectIDs'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/objects/objects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ post:
createdAt:
type: string
taskID:
$ref: '../../../common/parameters.yml#/taskID'
$ref: '../../../common/responses/common.yml#/taskID'
objectID:
$ref: '../../../common/parameters.yml#/objectID'
'400':
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/rules/common/schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ updatedRuleResponse:
objectID:
$ref: '../../../../common/parameters.yml#/objectID'
updatedAt:
$ref: '../../../../common/parameters.yml#/updatedAt'
$ref: '../../../../common/responses/common.yml#/updatedAt'
taskID:
$ref: '../../../../common/parameters.yml#/taskID'
$ref: '../../../../common/responses/common.yml#/taskID'
required:
- objectID
- updatedAt
Expand Down
4 changes: 2 additions & 2 deletions specs/search/paths/synonyms/synonym.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ put:
additionalProperties: false
properties:
taskID:
$ref: '../../../common/parameters.yml#/taskID'
$ref: '../../../common/responses/common.yml#/taskID'
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
$ref: '../../../common/responses/common.yml#/updatedAt'
id:
$ref: '../../../common/parameters.yml#/id'
required:
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/vault/deleteSource.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ delete:
- deletedAt
properties:
deletedAt:
$ref: '../../../common/parameters.yml#/deletedAt'
$ref: '../../../common/responses/common.yml#/deletedAt'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down
2 changes: 1 addition & 1 deletion specs/search/paths/vault/vaultSources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ put:
- updatedAt
properties:
updatedAt:
$ref: '../../../common/parameters.yml#/updatedAt'
$ref: '../../../common/responses/common.yml#/updatedAt'
'400':
$ref: '../../../common/responses/BadRequest.yml'
'402':
Expand Down

0 comments on commit 340b7bd

Please sign in to comment.