Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F114003
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
9 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/test/support/pet_controller.ex b/test/support/pet_controller.ex
index 52ccf46..2be2b8f 100644
--- a/test/support/pet_controller.ex
+++ b/test/support/pet_controller.ex
@@ -1,150 +1,156 @@
defmodule OpenApiSpexTest.PetController do
use Phoenix.Controller
- alias OpenApiSpex.Operation
+ alias OpenApiSpex.{Operation, Schema}
alias OpenApiSpexTest.Schemas
plug OpenApiSpex.Plug.CastAndValidate
def open_api_operation(action) do
apply(__MODULE__, :"#{action}_operation", [])
end
@doc """
API Spec for :show action
"""
def show_operation() do
import Operation
%Operation{
tags: ["pets"],
summary: "Show pet",
description: "Show a pet by ID",
operationId: "PetController.show",
parameters: [
- parameter(:id, :path, :integer, "Pet ID", example: 123, minimum: 1)
+ parameter(:id, :path, %Schema{type: :integer, minimum: 1}, "Pet ID", example: 123)
],
responses: %{
200 => response("Pet", "application/json", Schemas.PetResponse)
}
}
end
def show(conn, %{id: _id}) do
json(conn, %Schemas.PetResponse{
data: %Schemas.Dog{
pet_type: "Dog",
bark: "woof"
}
})
end
def index_operation() do
import Operation
%Operation{
tags: ["pets"],
summary: "List pets",
description: "List all petes",
operationId: "PetController.index",
parameters: [
parameter(:validParam, :query, :boolean, "Valid Param", example: true)
],
responses: %{
200 => response("Pet List Response", "application/json", Schemas.PetsResponse)
}
}
end
def index(conn, _params) do
json(conn, %Schemas.PetsResponse{
data: [
%Schemas.Dog{
pet_type: "Dog",
bark: "joe@gmail.com"
}
]
})
end
def create_operation() do
import Operation
%Operation{
tags: ["pets"],
summary: "Create pet",
description: "Create a pet",
operationId: "PetController.create",
parameters: [],
requestBody: request_body("The pet attributes", "application/json", Schemas.PetRequest),
responses: %{
201 => response("Pet", "application/json", Schemas.PetRequest)
}
}
end
def create(conn = %{body_params: %Schemas.PetRequest{pet: pet}}, _) do
json(conn, %Schemas.PetResponse{
data: pet
})
end
def adopt_operation() do
import Operation
%Operation{
tags: ["pets"],
summary: "Adopt pet",
description: "Adopt a pet",
operationId: "PetController.adopt",
parameters: [
parameter(:"x-user-id", :header, :string, "User that performs this action", required: true),
- parameter(:id, :path, :integer, "Pet ID", example: 123, minimum: 1),
+ parameter(:id, :path, %Schema{type: :integer, minimum: 1}, "Pet ID", example: 123),
parameter(:status, :query, Schemas.PetStatus, "New status"),
- parameter(:debug, :cookie, %OpenApiSpex.Schema{type: :integer, enum: [0, 1], default: 0}, "Debug"),
+ parameter(
+ :debug,
+ :cookie,
+ %Schema{type: :integer, enum: [0, 1], default: 0},
+ "Debug"
+ )
],
responses: %{
200 => response("Pet", "application/json", Schemas.PetRequest)
}
}
end
def adopt(conn, %{:"x-user-id" => _user_id, :id => _id, :debug => 0}) do
json(conn, %Schemas.PetResponse{
data: %Schemas.Dog{
pet_type: "Dog",
bark: "woof"
}
})
end
def adopt(conn, %{:"x-user-id" => _user_id, :id => _id, :debug => 1}) do
json(conn, %Schemas.PetResponse{
data: %Schemas.Dog{
pet_type: "Debug-Dog",
bark: "woof"
}
})
end
def appointment_operation() do
import Operation
%Operation{
tags: ["pets"],
summary: "Create pet",
description: "Create a pet",
operationId: "PetController.appointment",
parameters: [],
- requestBody: request_body("The pet attributes", "application/json", Schemas.PetAppointmentRequest),
+ requestBody:
+ request_body("The pet attributes", "application/json", Schemas.PetAppointmentRequest),
responses: %{
201 => response("Pet", "application/json", Schemas.PetResponse)
}
}
end
def appointment(conn, _) do
json(conn, %Schemas.PetResponse{
- data: [%{pet_type: "Dog", bark: "bow wow"}]
-})
+ data: [%{pet_type: "Dog", bark: "bow wow"}]
+ })
end
end
diff --git a/test/support/user_controller.ex b/test/support/user_controller.ex
index 561daa3..069df50 100644
--- a/test/support/user_controller.ex
+++ b/test/support/user_controller.ex
@@ -1,176 +1,176 @@
defmodule OpenApiSpexTest.UserController do
use Phoenix.Controller
- alias OpenApiSpex.Operation
+ alias OpenApiSpex.{Operation, Schema}
alias OpenApiSpexTest.Schemas
plug OpenApiSpex.Plug.CastAndValidate
def open_api_operation(action) do
apply(__MODULE__, :"#{action}_operation", [])
end
@doc """
API Spec for :show action
"""
def show_operation() do
import Operation
%Operation{
tags: ["users"],
summary: "Show user",
description: "Show a user by ID",
operationId: "UserController.show",
parameters: [
- parameter(:id, :path, :integer, "User ID", example: 123, minimum: 1)
+ parameter(:id, :path, %Schema{type: :integer, minimum: 1}, "User ID", example: 123)
],
responses: %{
200 => response("User", "application/json", Schemas.UserResponse)
}
}
end
def show(conn, %{id: id}) do
json(conn, %Schemas.UserResponse{
data: %Schemas.User{
id: id,
name: "joe user",
email: "joe@gmail.com"
}
})
end
def index_operation() do
import Operation
%Operation{
tags: ["users"],
summary: "List users",
description: "List all useres",
operationId: "UserController.index",
parameters: [
parameter(:validParam, :query, :boolean, "Valid Param", example: true)
],
responses: %{
200 => response("User List Response", "application/json", Schemas.UsersResponse)
}
}
end
def index(conn, _params) do
json(conn, %Schemas.UsersResponse{
data: [
%Schemas.User{
id: 123,
name: "joe user",
email: "joe@gmail.com"
}
]
})
end
def create_operation() do
import Operation
%Operation{
tags: ["users"],
summary: "Create user",
description: "Create a user",
operationId: "UserController.create",
parameters: [],
requestBody: request_body("The user attributes", "application/json", Schemas.UserRequest),
responses: %{
201 => response("User", "application/json", Schemas.UserResponse)
}
}
end
def create(conn = %{body_params: %Schemas.UserRequest{user: user = %Schemas.User{}}}, _) do
json(conn, %Schemas.UserResponse{
data: %{user | id: 1234}
})
end
def contact_info_operation() do
import Operation
%Operation{
tags: ["users"],
summary: "Update contact info",
description: "Update contact info",
operationId: "UserController.contact_info",
parameters: [
parameter(:id, :path, :integer, "user ID")
],
requestBody: request_body("Contact info", "application/json", Schemas.ContactInfo),
responses: %{
200 => %OpenApiSpex.Response{
description: "OK"
}
}
}
end
def contact_info(conn = %{body_params: %Schemas.ContactInfo{}}, %{id: id}) do
conn
|> put_status(200)
|> json(%{id: id})
end
def payment_details_operation() do
import Operation
%Operation{
tags: ["users"],
summary: "Show user payment details",
description: "Shows a users payment details",
operationId: "UserController.payment_details",
parameters: [
- parameter(:id, :path, :integer, "User ID", example: 123, minimum: 1)
+ parameter(:id, :path, %Schema{type: :integer, minimum: 1}, "User ID", example: 123)
],
responses: %{
200 => response("Payment Details", "application/json", Schemas.PaymentDetails)
}
}
end
def payment_details(conn, %{"id" => id}) do
response =
case rem(id, 2) do
0 ->
%Schemas.CreditCardPaymentDetails{
credit_card_number: "1234-5678-0987-6543",
name_on_card: "Joe User",
expiry: "0522"
}
1 ->
%Schemas.DirectDebitPaymentDetails{
account_number: "98776543",
account_name: "Joes Savings",
bsb: "123-567"
}
end
json(conn, response)
end
def create_entity_operation() do
import Operation
%Operation{
tags: ["EntityWithDict"],
summary: "Create an EntityWithDict",
description: "Create an EntityWithDict",
operationId: "UserController.create_entity",
parameters: [],
requestBody: request_body("Entity attributes", "application/json", Schemas.EntityWithDict),
responses: %{
201 => response("EntityWithDict", "application/json", Schemas.EntityWithDict)
}
}
end
def create_entity(conn, %Schemas.EntityWithDict{} = entity) do
json(conn, Map.put(entity, :id, 123))
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 25, 5:59 PM (1 d, 6 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39990
Default Alt Text
(9 KB)
Attached To
Mode
R22 open_api_spex
Attached
Detach File
Event Timeline
Log In to Comment