Open kianmeng opened 4 months ago
Hi @kianmeng, I'm cool with that. I'll circle back and let you know. In the meantime, what's pros/cons if within/separate repo? what's your preference?
Up to you, whichever you find convenient.
Sorry @kianmeng I'm late to reply, too many errands in past few weeks. What I did is copying exactly what's in the example openapi.yml file and ran mix api.gen
. I have few noob questions 😅:
Replace the API wrapper code
, does that mean move HttpClient
(Req client) endpoint definitions to openapi.yml
?
- When we say
Replace the API wrapper code
, does that mean moveHttpClient
(Req client) endpoint definitions toopenapi.yml
?
Replacing the HTTPClient
and some modules entirely. I'm unsure whether this is feasible so far.
- What should we see inside this yml file?
It is from https://raw.githubusercontent.com/typesense/typesense-api-spec/master/openapi.yml and we don't need to generate on our own.
- Can you point me on few articles regarding this? cause I'm lost 🥲
You can start with https://github.com/aj-foster/open-api-generator by trying to generate an Elixir Open API client first based on the OpenAPI spec file mentioned (2).
Hi @kianmeng, kindly check #47. Lmk what's missing.
@kianmeng I raised a discussion here. It seems that after I generate e.g. mix api.gen...
, there's an implementation of the http client:
e.g.
@default_client OpenApiTypesense.Client
@doc """
Creates an analytics rule
When an analytics rule is created, we give it a name and describe the type, the source collections and the destination collection.
"""
@spec create_analytics_rule(OpenApiTypesense.AnalyticsRuleSchema.t(), keyword) ::
{:ok, OpenApiTypesense.AnalyticsRuleSchema.t()}
| {:error, OpenApiTypesense.ApiResponse.t()}
def create_analytics_rule(body, opts \\ []) do
client = opts[:client] || @default_client
client.request(%{
args: [body: body],
call: {OpenApiTypesense.Analytics, :create_analytics_rule},
url: "/analytics/rules",
body: body,
method: :post,
request: [{"application/json", {OpenApiTypesense.AnalyticsRuleSchema, :t}}],
response: [
{201, {OpenApiTypesense.AnalyticsRuleSchema, :t}},
{400, {OpenApiTypesense.ApiResponse, :t}}
],
opts: opts
})
end
Which from my understanding client.request
is hardcoded, But I don't know how to use other adapter to bend according to its needs.
@jaeyson What does adapter
here means?
@jaeyson What does
adapter
here means?
I meant customizing the http client, the library author just told me what to do. All good now.
Would it possible to replace the existing API related code in https://github.com/jaeyson/ex_typesense/tree/main/lib/ex_typesense with generated code using the OpenAPI spec, https://raw.githubusercontent.com/typesense/typesense-api-spec/master/openapi.yml, using from https://github.com/aj-foster/open-api-generator?
Not sure if we want to put the generated code within the same repository or into two separate repositories or packages.
WDYT?