Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: openapi sample with search, index, and batch API #4

Merged
merged 8 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions openapi_spec/parameters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
AppId:
name: X-Algolia-Application-Id
in: header
description: Algolia appID
required: true
schema:
type: string
pattern: "^(?:beta|testing)?[A-Z0-9]{10}$"
example: "DJNVGS47DK"
ApiKey:
name: X-Algolia-API-Key
in: header
description: Algolia API key
required: true
schema:
type: string
pattern: "^[a-f0-9]{32}$"
example: "43b15df305339e827f0ac0bdc5ebcaa7"
IndexName:
name: indexName
in: path
description: The index in which to perform the request
required: true
schema:
type: string
example: "myIndexName"
58 changes: 58 additions & 0 deletions openapi_spec/paths/indexes/batch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
post:
tags:
- object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bundled with the search package atm, do we want to change it?

operationId: batch
summary: Performs multiple write operations in a single API call
parameters:
- $ref: "../../parameters.yml#/AppId"
- $ref: "../../parameters.yml#/ApiKey"
- $ref: "../../parameters.yml#/IndexName"
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
requests:
type: array
items:
title: operation
type: object
additionalProperties: false
properties:
action:
type: string
enum:
- "addObject"
- "updateObject"
- "partialUpdateObject"
- "partialUpdateObjectNoCreate"
- "deleteObject"
- "delete"
- "clear"
description: type of operation
body:
type: object
# this could be a long oneOf with every possibilities
additionalProperties: true
description: arguments to the operation (depends on the type of the operation)
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
additionalProperties: false
properties:
taskID:
type: integer
objectIDs:
type: array
items:
type: string
"400":
$ref: "../../responses/BadRequest.yml"
"404":
$ref: "../../responses/IndexNotFound.yml"
36 changes: 36 additions & 0 deletions openapi_spec/paths/indexes/saveObject.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
post:
tags:
- object
operationId: saveObject
summary: Save object
description: Add an object to the index, automatically assigning it an object ID
parameters:
- $ref: "../../parameters.yml#/AppId"
- $ref: "../../parameters.yml#/ApiKey"
- $ref: "../../parameters.yml#/IndexName"
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties: true
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
additionalProperties: false
properties:
createdAt:
type: string
taskID:
type: integer
objectID:
millotp marked this conversation as resolved.
Show resolved Hide resolved
type: string
"400":
$ref: "../../responses/BadRequest.yml"
"404":
$ref: "../../responses/IndexNotFound.yml"
40 changes: 40 additions & 0 deletions openapi_spec/paths/indexes/search.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
post:
tags:
- search
operationId: search
summary: Get search results
parameters:
- $ref: "../../parameters.yml#/AppId"
- $ref: "../../parameters.yml#/ApiKey"
- $ref: "../../parameters.yml#/IndexName"
requestBody:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are missing the query here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's in the search params with the rest

$ref: "../../schemas/SearchParams.yml"
responses:
"200":
description: OK
content:
application/json:
schema:
title: singleQueryResponse
type: object
additionalProperties: false
properties:
hits:
type: array
items:
type: object
additionalProperties: false
properties:
objectID:
type: string
example: objectID1
nbHits:
type: integer
queryID:
type: string
pattern: "[a-f0-9]{32}"
example: 43b15df305339e827f0ac0bdc5ebcaa7
"400":
$ref: "../../responses/BadRequest.yml"
"404":
$ref: "../../responses/IndexNotFound.yml"
83 changes: 83 additions & 0 deletions openapi_spec/paths/indexes/searchMulti.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
post:
tags:
- search
operationId: searchMulti
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Not important at all for now but searchMulti is a bit vague)

summary: Get search results for the given requests.
parameters:
- $ref: "../../parameters.yml#/AppId"
- $ref: "../../parameters.yml#/ApiKey"
requestBody:
required: true
content:
application/json:
schema:
type: object
additionalProperties: false
properties:
requests:
type: array
items:
title: multipleQueries
type: object
additionalProperties: false
properties:
indexName:
type: string
example: products
description: The Algolia index name
query:
type: string
description: The query to search for
type:
type: string
enum: [default, facet]
default: default
description: Perform a search query with `default`, will search for facet values if `facet` is given
facet:
type: string
description: The `facet` name
params:
type: string
description: A query string of search parameters
required:
- indexName
strategy:
type: string
enum: ["none", "stopIfEnoughMatches"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be an object with only the strategy option for now, it's closer to what we have actually and avoid breaking the API if we add requestOptions in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean removing the requests property ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean search methods both receive 2 parameters, query (or queries here) and requestOptions (which contains the strategy), we should have the same shape here.

Copy link
Collaborator Author

@millotp millotp Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the doc I understand that the body should contain the requests and maybe the strategy, it's not in the requestOptions I think.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a usual in the API clients to bundle the real property in a requests property ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a usual in the API clients to bundle the real property in a requests property ?

Copy link
Member

@shortcuts shortcuts Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the doc I understand that the body should contain the requests and maybe the strategy, it's not in the requestOptions I think.

Oh I see, I was referring to our API client structure and not the REST API. Since we pass options to our transporter etc. it may differ

required:
- requests
responses:
"200":
description: OK
content:
application/json:
schema:
title: multipleQueriesResponse
type: object
additionalProperties: false
properties:
results:
type: array
items:
type: object
additionalProperties: false
properties:
hits:
type: array
items:
type: object
additionalProperties: false
properties:
objectID:
type: string
example: objectID1
nbHits:
type: integer
queryID:
type: string
pattern: "[a-f0-9]{32}"
example: 43b15df305339e827f0ac0bdc5ebcaa7
"400":
$ref: "../../responses/BadRequest.yml"
"404":
$ref: "../../responses/IndexNotFound.yml"
5 changes: 5 additions & 0 deletions openapi_spec/responses/BadRequest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Bad request or request arguments
content:
application/json:
schema:
$ref: "../schemas/Error.yml"
5 changes: 5 additions & 0 deletions openapi_spec/responses/IndexNotFound.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
description: Index not found
content:
application/json:
schema:
$ref: "../schemas/Error.yml"
7 changes: 7 additions & 0 deletions openapi_spec/schemas/Error.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description: Error
type: object
additionalProperties: true
properties:
message:
type: string
example: "Invalid application id"
Loading