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:

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

Link to this function

render(state, operation)

View Source

Render a single operation

Default implementation of OpenAPI.Renderer.render_operation/2.

This implementation calls the following callbacks and concatenates their results:

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.

Link to this function

render_doc(state, operation)

View Source

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.

Link to this function

render_function(state, operation)

View Source

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
Link to this function

render_spec(state, operation)

View Source

Render the spec of an operation function

Default implementation of OpenAPI.Renderer.render_operation_spec/2.