Skip to content

Commit

Permalink
Docstest Operation.parameter/5
Browse files Browse the repository at this point in the history
  • Loading branch information
zorbash committed Sep 13, 2023
1 parent f90bc11 commit 7c05fa0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
18 changes: 17 additions & 1 deletion lib/open_api_spex/operation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,27 @@ defmodule OpenApiSpex.Operation do

@doc """
Shorthand for constructing an `OpenApiSpex.Parameter` given name, location, type, description and optional examples
## Examples
iex> Operation.parameter(
...> :status,
...> :query,
...> %OpenApiSpex.Schema{type: :string, enum: ["pending", "in_progress", "completed"]},
...> "The status of an entity"
...> )
%OpenApiSpex.Parameter{
name: :status,
in: :query,
description: "The status of an entity",
required: false,
schema: %OpenApiSpex.Schema{enum: ["pending", "in_progress", "completed"], type: :string}
}
"""
@spec parameter(
name :: atom,
location :: Parameter.location(),
type :: Reference.t() | Schema.t() | atom,
type :: Reference.t() | Schema.t() | Parameter.type() | atom(),
description :: String.t(),
opts :: keyword
) :: Parameter.t()
Expand Down
3 changes: 2 additions & 1 deletion lib/open_api_spex/parameter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ defmodule OpenApiSpex.Parameter do
}

@type parameters :: %{String.t() => t | Reference.t()} | nil
@type type :: :boolean | :integer | :number | :string | :array | :object

@doc """
Sets the schema for a parameter from a simple type, reference or Schema
"""
@spec put_schema(t, Reference.t() | Schema.t() | atom) :: t
@spec put_schema(t, Reference.t() | Schema.t() | type) :: t
def put_schema(parameter = %Parameter{}, type = %Reference{}) do
%{parameter | schema: type}
end
Expand Down
2 changes: 2 additions & 0 deletions test/operation_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ defmodule OpenApiSpex.OperationTest do
alias OpenApiSpex.Operation
alias OpenApiSpexTest.UserController

doctest Operation

describe "Operation" do
test "from_route %Phoenix.Router.Route{}" do
plug = UserController
Expand Down

0 comments on commit 7c05fa0

Please sign in to comment.