-
Hi! I'm confused on how to use an HTTP client (e.g. Edit Let me rephrase what I meant: after I use It seems that after I generate e.g. e.g. config :oapi_generator,
default: [
output: [
base_module: ExampleModule,
location: "lib/example_module",
operation_subdirectory: "operations/",
schema_subdirectory: "schemas/"
]
]
end @default_client ExampleModule.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(ExampleModule.AnalyticsRuleSchema.t(), keyword) ::
{:ok, ExampleModule.AnalyticsRuleSchema.t()}
| {:error, ExampleModule.ApiResponse.t()}
def create_analytics_rule(body, opts \\ []) do
client = opts[:client] || @default_client
client.request(%{
args: [body: body],
call: {ExampleModule.Analytics, :create_analytics_rule},
url: "/analytics/rules",
body: body,
method: :post,
request: [{"application/json", {ExampleModule.AnalyticsRuleSchema, :t}}],
response: [
{201, {ExampleModule.AnalyticsRuleSchema, :t}},
{400, {ExampleModule.ApiResponse, :t}}
],
opts: opts
})
end Which from my understanding |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello there! It looks like there's a naming conflict between the operations in your API's description and the default names used by the generator. But don't worry, because you can fix it. The code generator doesn't want to force you to use a specific library for making HTTP requests, so it makes all of its function calls to a generic module like Unfortunately, it looks like the API description has some operations that would naturally be placed in a "Client" module. This is unusual to find in an API description, but obviously not impossible. Luckily there's a way for you to change the name of the module saved in the config :oapi_generator, default: [
output: [
default_client: MyLib.MyClient
]
] In this example, you would create the |
Beta Was this translation helpful? Give feedback.
Hello there!
It looks like there's a naming conflict between the operations in your API's description and the default names used by the generator. But don't worry, because you can fix it.
The code generator doesn't want to force you to use a specific library for making HTTP requests, so it makes all of its function calls to a generic module like
MyApp.Client
. This is a module that you would implement, and it can pass on the request to any HTTP library you would like. Here's an example.Unfortunately, it looks like the API description has some operations that would naturally be placed in a "Client" module. This is unusual to find in an API description, but obviously not impossible. Luckily…