OpenApiSpex.Operation (open_api_spex v3.10.0) View Source

Defines the OpenApiSpex.Operation.t type.

Link to this section Summary

Functions

Cast params to the types defined by the schemas of the operation parameters and requestBody

Constructs an Operation struct from plug module and opts

Constructs an Operation struct from the plug and opts specified in the given route

Shorthand for constructing an OpenApiSpex.Parameter given name, location, type, description and optional examples

Shorthand for constructing a RequestBody with description, media_type, schema and optional examples

Shorthand for constructing a Response with description, media_type, schema and optional examples

Validate params against the schemas of the operation parameters and requestBody

Link to this section Types

Specs

t() :: %OpenApiSpex.Operation{
  callbacks: %{
    required(String.t()) => OpenApiSpex.Callback.t() | OpenApiSpex.Reference.t()
  },
  deprecated: boolean(),
  description: String.t() | nil,
  externalDocs: OpenApiSpex.ExternalDocumentation.t() | nil,
  operationId: String.t() | nil,
  parameters: [OpenApiSpex.Parameter.t() | OpenApiSpex.Reference.t()],
  requestBody: OpenApiSpex.RequestBody.t() | OpenApiSpex.Reference.t() | nil,
  responses: OpenApiSpex.Responses.t(),
  security: [OpenApiSpex.SecurityRequirement.t()] | nil,
  servers: [OpenApiSpex.Server.t()] | nil,
  summary: String.t() | nil,
  tags: [String.t()]
}

Operation Object

Describes a single API operation on a path.

Link to this section Functions

Link to this function

cast(operation, conn, content_type, schemas)

View Source

Specs

cast(
  t(),
  Conn.t(),
  content_type :: String.t() | nil,
  schemas :: %{required(String.t()) => OpenApiSpex.Schema.t()}
) :: {:ok, Plug.Conn.t()} | {:error, String.t()}

Cast params to the types defined by the schemas of the operation parameters and requestBody

Specs

from_plug(module(), opts :: any()) :: t() | nil

Constructs an Operation struct from plug module and opts

Specs

from_route(PathItem.route()) :: t() | nil

Constructs an Operation struct from the plug and opts specified in the given route

Link to this function

parameter(name, location, type, description, opts \\ [])

View Source

Specs

parameter(
  name :: atom(),
  location :: OpenApiSpex.Parameter.location(),
  type :: OpenApiSpex.Reference.t() | OpenApiSpex.Schema.t() | atom(),
  description :: String.t(),
  opts :: keyword()
) :: OpenApiSpex.Parameter.t()

Shorthand for constructing an OpenApiSpex.Parameter given name, location, type, description and optional examples

Link to this function

request_body(description, media_type, schema_ref, opts \\ [])

View Source

Specs

request_body(
  description :: String.t(),
  media_type :: String.t(),
  schema_ref :: OpenApiSpex.Schema.t() | OpenApiSpex.Reference.t() | module(),
  opts :: keyword()
) :: OpenApiSpex.RequestBody.t()

Shorthand for constructing a RequestBody with description, media_type, schema and optional examples

Link to this function

response(description, media_type, schema_ref, opts \\ [])

View Source

Specs

response(
  description :: String.t(),
  media_type :: String.t(),
  schema_ref :: OpenApiSpex.Schema.t() | OpenApiSpex.Reference.t() | module(),
  opts :: keyword()
) :: OpenApiSpex.Response.t()

Shorthand for constructing a Response with description, media_type, schema and optional examples

Link to this function

validate(operation, conn, content_type, schemas)

View Source

Specs

validate(t(), Conn.t(), String.t() | nil, %{
  required(String.t()) => OpenApiSpex.Schema.t()
}) :: :ok | {:error, String.t()}

Validate params against the schemas of the operation parameters and requestBody