View Source OpenAPI.Renderer.Operation (OpenAPI Generator v0.1.0-rc.3)
Default implementation for callbacks related to rendering operations
This module contains the default implementations for:
OpenAPI.Renderer.render_operations/2
OpenAPI.Renderer.render_operation/2
OpenAPI.Renderer.render_operation_doc/2
OpenAPI.Renderer.render_operation_function/2
OpenAPI.Renderer.render_operation_spec/2
These focus on the operation functions and surrounding code.
configuration
Configuration
All configuration offered by the functions in this module lives under the output
key of the
active configuration profile. For example (default values shown):
# config/config.exs
config :oapi_generator, default: [
output: [
base_module: nil,
types: [
error: nil
]
]
]
Link to this section Summary
Functions
Render a single operation
Render all of the operations contained in a single module
Render the docstring for an operation function
Render the function definition for an operation function
Render the spec of an operation function
Link to this section Functions
@spec render(OpenAPI.Renderer.State.t(), OpenAPI.Processor.Operation.t()) :: Macro.t()
Render a single operation
Default implementation of OpenAPI.Renderer.render_operation/2
.
This implementation calls the following callbacks and concatenates their results:
@spec render_all(OpenAPI.Renderer.State.t(), OpenAPI.Renderer.File.t()) :: Macro.t()
Render all of the operations contained in a single module
Default implementation of OpenAPI.Renderer.render_operations/2
.
This implementation simply iterates through the operations contained in a file, sorted by their
function name, and calls the OpenAPI.Renderer.render_operation/2
callback for each. The
results are returned as a list of nodes.
@spec render_doc(OpenAPI.Renderer.State.t(), OpenAPI.Processor.Operation.t()) :: Macro.t()
Render the docstring for an operation function
Default implementation of OpenAPI.Renderer.render_operation_doc/2
.
This implementation uses the docstring created by the processor without modification.
@spec render_function(OpenAPI.Renderer.State.t(), OpenAPI.Processor.Operation.t()) :: Macro.t()
Render the function definition for an operation function
Default implementation of OpenAPI.Renderer.render_operation_function/2
.
This implementation constructs a function that calls a dynamically chosen client module's
request
function with details about the operation.
example
Example
def my_operation(path_param, body, opts \ []) do
client = opts[:client] || @default_client
query = Keyword.take(opts, [:query_param])
client.request(%{
args: [path_param: path_param, body: body],
call: {Example.Operations, :my_operation},
url: "/path/to/#{path_param}",
body: body,
method: :post,
query: query,
request: [{"application/json", :map}],
response: [{200, :map}, {404, {Example.NotFoundError, :t}}],
opts: opts
})
end
@spec render_spec(OpenAPI.Renderer.State.t(), OpenAPI.Processor.Operation.t()) :: Macro.t()
Render the spec of an operation function
Default implementation of OpenAPI.Renderer.render_operation_spec/2
.