From c91ca54f22daa96600d318bcb8710034c62fa73e Mon Sep 17 00:00:00 2001 From: Thomas Raffray Date: Wed, 19 Jun 2024 20:23:00 +0200 Subject: [PATCH] feat(specs): add validate endpoint (#3087) Co-authored-by: shortcuts --- specs/ingestion/common/schemas/source.yml | 22 +++++++++++ specs/ingestion/paths/sources/validate.yml | 26 +++++++++++++ specs/ingestion/paths/sources/validateID.yml | 28 +++++++++++++ specs/ingestion/spec.yml | 4 ++ .../requests/ingestion/validateSource.json | 39 +++++++++++++++++++ .../ingestion/validateSourceBeforeUpdate.json | 18 +++++++++ 6 files changed, 137 insertions(+) create mode 100644 specs/ingestion/paths/sources/validate.yml create mode 100644 specs/ingestion/paths/sources/validateID.yml create mode 100644 tests/CTS/requests/ingestion/validateSource.json create mode 100644 tests/CTS/requests/ingestion/validateSourceBeforeUpdate.json diff --git a/specs/ingestion/common/schemas/source.yml b/specs/ingestion/common/schemas/source.yml index 2e9e8a5a37..21ade93348 100644 --- a/specs/ingestion/common/schemas/source.yml +++ b/specs/ingestion/common/schemas/source.yml @@ -524,3 +524,25 @@ sourceShopifyBase: - shopURL x-discriminator-fields: - shopURL + +SourceValidateResponse: + type: object + additionalProperties: false + properties: + runID: + $ref: './common.yml#/runID' + data: + type: array + description: depending on the source type, the validation returns sampling data of your source (JSON, CSV, BigQuery). + items: + type: object + events: + description: in case of error, observability events will be added to the response, if any. + type: array + items: + $ref: '../../common/schemas/event.yml#/Event' + message: + description: a message describing the outcome of a validate run. + type: string + required: + - message diff --git a/specs/ingestion/paths/sources/validate.yml b/specs/ingestion/paths/sources/validate.yml new file mode 100644 index 0000000000..45420d3dbf --- /dev/null +++ b/specs/ingestion/paths/sources/validate.yml @@ -0,0 +1,26 @@ +post: + tags: + - sources + summary: Validates a source payload + description: | + Validates a source payload to ensure it can be created and that the data source can be reached by Algolia. + operationId: validateSource + x-acl: + - addObject + - deleteIndex + - editSettings + requestBody: + description: '' + content: + application/json: + schema: + $ref: '../../common/schemas/source.yml#/SourceCreate' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '../../common/schemas/source.yml#/SourceValidateResponse' + '400': + $ref: '../../../common/responses/BadRequest.yml' diff --git a/specs/ingestion/paths/sources/validateID.yml b/specs/ingestion/paths/sources/validateID.yml new file mode 100644 index 0000000000..0a1cc499fc --- /dev/null +++ b/specs/ingestion/paths/sources/validateID.yml @@ -0,0 +1,28 @@ +post: + tags: + - sources + summary: Validates an update of a source payload + description: | + Validates an update of a source payload to ensure it can be created and that the data source can be reached by Algolia. + operationId: validateSourceBeforeUpdate + x-acl: + - addObject + - deleteIndex + - editSettings + parameters: + - $ref: '../../common/parameters.yml#/pathSourceID' + requestBody: + content: + application/json: + schema: + $ref: '../../common/schemas/source.yml#/SourceUpdate' + required: true + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: '../../common/schemas/source.yml#/SourceValidateResponse' + '400': + $ref: '../../../common/responses/BadRequest.yml' diff --git a/specs/ingestion/spec.yml b/specs/ingestion/spec.yml index 383a9db98c..bd34e8ba5e 100644 --- a/specs/ingestion/spec.yml +++ b/specs/ingestion/spec.yml @@ -122,10 +122,14 @@ paths: # sources API. /1/sources: $ref: 'paths/sources/sources.yml' + /1/sources/validate: + $ref: 'paths/sources/validate.yml' /1/sources/search: $ref: 'paths/sources/searchSources.yml' /1/sources/{sourceID}: $ref: 'paths/sources/sourceID.yml' + /1/sources/{sourceID}/validate: + $ref: 'paths/sources/validateID.yml' /1/sources/{sourceID}/discover: $ref: 'paths/sources/discover.yml' diff --git a/tests/CTS/requests/ingestion/validateSource.json b/tests/CTS/requests/ingestion/validateSource.json new file mode 100644 index 0000000000..131fd6fc77 --- /dev/null +++ b/tests/CTS/requests/ingestion/validateSource.json @@ -0,0 +1,39 @@ +[ + { + "testName": "validateSource", + "parameters": { + "type": "commercetools", + "name": "sourceName", + "input": { + "storeKeys": [ + "myStore" + ], + "locales": [ + "de" + ], + "url": "http://commercetools.com", + "projectKey": "keyID" + }, + "authenticationID": "6c02aeb1-775e-418e-870b-1faccd4b2c0f" + }, + "request": { + "path": "/1/sources/validate", + "method": "POST", + "body": { + "type": "commercetools", + "name": "sourceName", + "input": { + "storeKeys": [ + "myStore" + ], + "locales": [ + "de" + ], + "url": "http://commercetools.com", + "projectKey": "keyID" + }, + "authenticationID": "6c02aeb1-775e-418e-870b-1faccd4b2c0f" + } + } + } +] diff --git a/tests/CTS/requests/ingestion/validateSourceBeforeUpdate.json b/tests/CTS/requests/ingestion/validateSourceBeforeUpdate.json new file mode 100644 index 0000000000..2d3c603d91 --- /dev/null +++ b/tests/CTS/requests/ingestion/validateSourceBeforeUpdate.json @@ -0,0 +1,18 @@ +[ + { + "testName": "validateSourceBeforeUpdate", + "parameters": { + "sourceID": "6c02aeb1-775e-418e-870b-1faccd4b2c0f", + "sourceUpdate": { + "name": "newName" + } + }, + "request": { + "path": "/1/sources/6c02aeb1-775e-418e-870b-1faccd4b2c0f/validate", + "method": "POST", + "body": { + "name": "newName" + } + } + } +]