Skip to content

Commit ca5c615

Browse files
authored
Fix typos in docs (#12)
1 parent 2e7cee1 commit ca5c615

19 files changed

Lines changed: 289 additions & 123 deletions

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## major.minor.patch (yyyy.mm.dd)
99

10+
## 0.5.2 (2025.01.16)
11+
12+
### Changed
13+
14+
* Documentation typos
15+
* Tidy documentation flow
16+
17+
### Added
18+
19+
* Error status code missing from creating a snapshot
20+
* More test coverage
21+
1022
## 0.5.1 (2025.01.12)
1123

1224
### Removed

README.md

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,27 @@ if config_env() == :prod do # if you'll use this in prod environment
5454
...
5555
```
5656

57-
> **Note**: The `options` key can be used to pass additional configuration options such as custom Finch instance or receive timeout settings. You can add any options supported by Req here. For more details check [Req documentation](https://hexdocs.pm/req/Req.Steps.html#run_finch/1-request-options).
57+
> #### `options` key {: .tip}
58+
>
59+
> The `options` key can be used to pass additional configuration
60+
> options such as custom Finch instance or receive timeout
61+
> settings. You can add any options supported by Req here. For
62+
> more details check [Req documentation](https://hexdocs.pm/req/Req.Steps.html#run_finch/1-request-options).
63+
64+
```
65+
config :open_api_typesense,
66+
api_key: "credential", # Admin API key
67+
host: "111222333aaabbbcc-9.x9.typesense.net", # Nodes
68+
port: 443,
69+
scheme: "https"
70+
options: [finch: MyApp.CustomFinch] # <- add options
71+
```
72+
73+
> #### during tests {: .tip}
74+
>
75+
> If you have a different config for your app, consider
76+
> adding it in `config/test.exs`.
5877
59-
> **Note**: If you use this for adding tests in your app, you might want to add this in `config/test.exs`:
6078

6179
For Cloud hosted, you can generate and obtain the credentials from cluster instance admin interface:
6280

@@ -85,8 +103,15 @@ called `request` that contains 2 args:
85103
Here's a custom client example ([`HTTPoison`](https://hexdocs.pm/httpoison/readme.html))
86104
in order to match the usage:
87105

106+
<!-- tabs-open -->
107+
108+
### Client module
109+
88110
```elixir
89111
defmodule MyApp.CustomClient do
112+
@behaviour OpenApiTypesense.Client
113+
114+
@impl OpenApiTypesense.Client
90115
def request(conn, params) do
91116
url = %URI{
92117
scheme: conn.scheme,
@@ -102,7 +127,7 @@ defmodule MyApp.CustomClient do
102127
request =
103128
if params[:request] do
104129
[{content_type, _schema}] = params.request
105-
130+
106131
headers = [
107132
{"X-TYPESENSE-API-KEY", conn.api_key}
108133
{"Content-Type", content_type}
@@ -125,41 +150,28 @@ defmodule MyApp.CustomClient do
125150
end
126151
```
127152

128-
Then add your client in your config file:
153+
### Client config
129154

130155
```elixir
131156
config :open_api_typesense,
132-
api_key: "credential", # Admin API key
133-
host: "111222333aaabbbcc-9.x9.typesense.net", # Nodes
134-
port: 443,
135-
scheme: "https",
157+
api_key: "xyz", # Admin API key
158+
host: "localhost", # Nodes
159+
port: 8108,
160+
scheme: "http",
136161
client: MyApp.CustomClient # <- add this
137162
```
138163

139-
And here's a reference taken from one of functions from [`Collections`](https://hexdocs.pm/open_api_typesense/OpenApiTypesense.Collections.html#create_collection/3), as
140-
you may want to match the params:
164+
<!-- tabs-close -->
165+
166+
Check [the examples](./guides/custom_http_client.md) on some HTTP client implementations.
167+
168+
## Adding [cache, retry, compress_body](https://hexdocs.pm/req/Req.html#new/1) in the built in client
169+
170+
E.g. when a user wants to change `retry` and `cache` options
141171

142172
```elixir
143-
def create_collection(%Connection{} = conn, body, opts) when is_struct(conn) do
144-
client = opts[:client] || @default_client
145-
query = Keyword.take(opts, [:src_name])
146-
147-
client.request(conn, %{
148-
args: [body: body],
149-
call: {OpenApiTypesense.Collections, :create_collection},
150-
url: "/collections",
151-
body: body,
152-
method: :post,
153-
query: query,
154-
request: [{"application/json", {OpenApiTypesense.CollectionSchema, :t}}],
155-
response: [
156-
{201, {OpenApiTypesense.CollectionResponse, :t}},
157-
{400, {OpenApiTypesense.ApiResponse, :t}},
158-
{409, {OpenApiTypesense.ApiResponse, :t}}
159-
],
160-
opts: opts
161-
})
162-
end
173+
ExTypesense.get_collection("companies", req: [retry: false, cache: true])
163174
```
164175

165-
Check [the examples](./guides/custom_http_client.md) on some HTTP client implementations.
176+
See implementation [OpenApiTypesense.Client](`OpenApiTypesense.Client`) https://github.com/jaeyson/open_api_typesense/blob/main/lib/open_api_typesense/client.ex
177+

guides/custom_http_client.md

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ config :open_api_typesense,
1717

1818
```elixir
1919
defmodule CustomClient do
20+
@behaviour OpenApiTypesense.Client
21+
22+
@impl OpenApiTypesense.Client
2023
def request(conn, params) do
2124
uri =
2225
%URI{
@@ -84,6 +87,9 @@ end
8487

8588
```elixir
8689
defmodule MyApp.CustomClient do
90+
@behaviour OpenApiTypesense.Client
91+
92+
@impl OpenApiTypesense.Client
8793
def request(conn, params) do
8894
url = %URI{
8995
scheme: conn.scheme,
@@ -126,6 +132,9 @@ end
126132

127133
```elixir
128134
defmodule MyApp.CustomClient do
135+
@behaviour OpenApiTypesense.Client
136+
137+
@impl OpenApiTypesense.Client
129138
def request(conn, params) do
130139
url = %URI{
131140
scheme: conn.scheme,
@@ -169,6 +178,9 @@ end
169178

170179
```elixir
171180
defmodule MyApp.CustomClient do
181+
@behaviour OpenApiTypesense.Client
182+
183+
@impl OpenApiTypesense.Client
172184
def request(conn, params) do
173185
url = %URI{
174186
scheme: conn.scheme,
@@ -252,27 +264,15 @@ end
252264

253265
## [Finch](https://hexdocs.pm/finch)
254266

255-
Add to your supervision tree:
256-
257-
```elixir
258-
# e.g. lib/my_app/application.ex
259-
@impl true
260-
def start(_type, _args) do
261-
children = [
262-
# Starts a worker by calling: Githubber.Worker.start_link(arg)
263-
# {Githubber.Worker, arg}
264-
{Finch, name: MyFinch} # <- add this
265-
]
267+
<!-- tabs-open -->
266268

267-
# See https://hexdocs.pm/elixir/Supervisor.html
268-
# for other strategies and supported options
269-
opts = [strategy: :one_for_one, name: Githubber.Supervisor]
270-
Supervisor.start_link(children, opts)
271-
end
272-
```
269+
### Client
273270

274271
```elixir
275272
defmodule MyApp.CustomClient do
273+
@behaviour OpenApiTypesense.Client
274+
275+
@impl OpenApiTypesense.Client
276276
def request(conn, _params) do
277277
uri = %URI{
278278
scheme: conn.scheme,
@@ -314,15 +314,44 @@ defmodule MyApp.CustomClient do
314314
end
315315
```
316316

317+
### `application.ex`
318+
319+
Add to your supervision tree:
320+
321+
```elixir
322+
# e.g. lib/my_app/application.ex
323+
@impl true
324+
def start(_type, _args) do
325+
children = [
326+
# Starts a worker by calling: Githubber.Worker.start_link(arg)
327+
# {Githubber.Worker, arg}
328+
{Finch, name: MyFinch} # <- add this
329+
]
330+
331+
# See https://hexdocs.pm/elixir/Supervisor.html
332+
# for other strategies and supported options
333+
opts = [strategy: :one_for_one, name: Githubber.Supervisor]
334+
Supervisor.start_link(children, opts)
335+
end
336+
```
337+
338+
<!-- tabs-close -->
339+
317340
## [Tesla](https://hexdocs.pm/tesla)
318341

342+
<!-- tabs-open -->
343+
344+
### Adapter
345+
319346
```elixir
320347
# e.g. config/config.exs
321348
import Config
322349

323350
config :tesla, adapter: Tesla.Adapter.Hackney
324351
```
325352

353+
### Config
354+
326355
```elixir
327356
# e.g. config/runtime.exs
328357
config :open_api_typesense,
@@ -333,8 +362,13 @@ config :open_api_typesense,
333362
client: MyApp.CustomClient
334363
```
335364

365+
### Client
366+
336367
```elixir
337368
defmodule MyApp.CustomClient do
369+
@behaviour OpenApiTypesense.Client
370+
371+
@impl OpenApiTypesense.Client
338372
def request(conn, params) do
339373
url =
340374
%URI{
@@ -385,10 +419,15 @@ defmodule MyApp.CustomClient do
385419
end
386420
```
387421

422+
<!-- tabs-close -->
423+
388424
## [`:gun`](https://hexdocs.pm/gun)
389425

390426
```elixir
391427
defmodule MyApp.CustomClient do
428+
@behaviour OpenApiTypesense.Client
429+
430+
@impl OpenApiTypesense.Client
392431
def request(conn, params) do
393432
# Open a connection
394433
{:ok, pid} =

lib/open_api_typesense/client.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,15 +166,7 @@ defmodule OpenApiTypesense.Client do
166166
# end
167167
# end
168168

169-
defp parse_resp(%Req.TransportError{} = error, _opts_resp) do
170-
{:error, Exception.message(error)}
171-
end
172-
173-
defp parse_resp(%Req.HTTPError{} = error, _opts_resp) do
174-
{:error, Exception.message(error)}
175-
end
176-
177-
defp parse_resp(resp, opts_resp) do
169+
defp parse_resp(%Req.Response{} = resp, opts_resp) do
178170
{code, values} =
179171
opts_resp
180172
|> Enum.find(fn {code, _values} ->
@@ -184,6 +176,10 @@ defmodule OpenApiTypesense.Client do
184176
parse_values(code, values, resp.body)
185177
end
186178

179+
defp parse_resp(error, _opts_resp) do
180+
{:error, Exception.message(error)}
181+
end
182+
187183
@spec parse_values(
188184
non_neg_integer(),
189185
atom() | list() | tuple(),

lib/open_api_typesense/connection.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ defmodule OpenApiTypesense.Connection do
4949

5050
@doc since: "0.2.0"
5151
@spec new(t() | map()) :: %__MODULE__{}
52+
def new(%__MODULE__{} = connection) when is_struct(connection) do
53+
connection
54+
end
55+
5256
def new(connection) when is_map(connection) do
5357
missing_fields = Enum.sort(required_fields() -- Map.keys(connection))
5458

lib/open_api_typesense/operations/curation.ex

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ defmodule OpenApiTypesense.Curation do
7171

7272
@doc """
7373
List all collection overrides
74+
75+
## Options
76+
77+
* `limit`: Limit results in paginating on collection listing.
78+
* `offset`: Skip a certain number of results and start after that.
79+
7480
"""
7581
@spec get_search_overrides(String.t()) ::
7682
{:ok, OpenApiTypesense.SearchOverridesResponse.t()} | :error
@@ -109,13 +115,18 @@ defmodule OpenApiTypesense.Curation do
109115

110116
def get_search_overrides(%Connection{} = conn, collectionName, opts) when is_struct(conn) do
111117
client = opts[:client] || @default_client
118+
query = Keyword.take(opts, [:limit, :offset])
112119

113120
client.request(conn, %{
114121
args: [collectionName: collectionName],
115122
call: {OpenApiTypesense.Curation, :get_search_overrides},
116123
url: "/collections/#{collectionName}/overrides",
117124
method: :get,
118-
response: [{200, {OpenApiTypesense.SearchOverridesResponse, :t}}],
125+
query: query,
126+
response: [
127+
{200, {OpenApiTypesense.SearchOverridesResponse, :t}},
128+
{404, {OpenApiTypesense.ApiResponse, :t}}
129+
],
119130
opts: opts
120131
})
121132
end

lib/open_api_typesense/operations/documents.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,11 @@ defmodule OpenApiTypesense.Documents do
559559
method: :post,
560560
query: query,
561561
request: [{"application/json", :map}],
562-
response: [{201, :map}, {404, {OpenApiTypesense.ApiResponse, :t}}],
562+
response: [
563+
{201, :map},
564+
{404, {OpenApiTypesense.ApiResponse, :t}},
565+
{409, {OpenApiTypesense.ApiResponse, :t}}
566+
],
563567
opts: opts
564568
})
565569
end

lib/open_api_typesense/operations/health.ex

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ defmodule OpenApiTypesense.Health do
2424
"""
2525
@spec health(Connection.t() | map() | keyword()) ::
2626
{:ok, OpenApiTypesense.HealthStatus.t()} | :error
27-
def health(%Connection{} = conn) when is_struct(conn) do
28-
health(conn, [])
27+
def health(opts) when is_list(opts) do
28+
health(Connection.new(), opts)
2929
end
3030

31-
def health(conn) when not is_struct(conn) and is_map(conn) do
31+
def health(conn) do
3232
health(conn, [])
3333
end
3434

35-
def health(opts) when is_list(opts) do
36-
health(Connection.new(), opts)
37-
end
38-
3935
@doc """
4036
Either one of:
4137
- `health(%{api_key: xyz, host: ...}, opts)`

lib/open_api_typesense/operations/operations.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,10 @@ defmodule OpenApiTypesense.Operations do
142142
url: "/operations/snapshot",
143143
method: :post,
144144
query: query,
145-
response: [{201, {OpenApiTypesense.SuccessStatus, :t}}],
145+
response: [
146+
{201, {OpenApiTypesense.SuccessStatus, :t}},
147+
{409, {OpenApiTypesense.ApiResponse, :t}}
148+
],
146149
opts: opts
147150
})
148151
end

0 commit comments

Comments
 (0)