All checks were successful
Build and Publish / build-release (push) Successful in 2m13s
180 lines
4.8 KiB
Elixir
180 lines
4.8 KiB
Elixir
defmodule CustomerServiceWeb.Schemas.Customer do
|
|
alias OpenApiSpex.Schema
|
|
|
|
defmodule PaginationMeta do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "PaginationMeta",
|
|
type: :object,
|
|
properties: %{
|
|
total_count: %Schema{type: :integer},
|
|
total_pages: %Schema{type: :integer},
|
|
current_page: %Schema{type: :integer},
|
|
page_size: %Schema{type: :integer},
|
|
has_next: %Schema{type: :boolean},
|
|
has_prev: %Schema{type: :boolean}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule IndividualCustomerData do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "IndividualCustomer",
|
|
type: :object,
|
|
properties: %{
|
|
id: %Schema{type: :string, format: :uuid},
|
|
customer_type: %Schema{type: :string, enum: ["individual"]},
|
|
first_name: %Schema{type: :string},
|
|
last_name: %Schema{type: :string},
|
|
email: %Schema{type: :string, format: :email},
|
|
phone: %Schema{type: :string},
|
|
birth_date: %Schema{type: :string, format: :date},
|
|
gender: %Schema{type: :string},
|
|
document_id: %Schema{type: :string}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule CorporateCustomerData do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "CorporateCustomer",
|
|
type: :object,
|
|
properties: %{
|
|
id: %Schema{type: :string, format: :uuid},
|
|
customer_type: %Schema{type: :string, enum: ["corporate"]},
|
|
legal_name: %Schema{type: :string},
|
|
commercial_name: %Schema{type: :string},
|
|
ruc: %Schema{type: :string},
|
|
legal_rep_name: %Schema{type: :string},
|
|
legal_rep_document_id: %Schema{type: :string},
|
|
email: %Schema{type: :string, format: :email},
|
|
phone: %Schema{type: :string},
|
|
address: %Schema{type: :string}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule CustomerData do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "Customer",
|
|
oneOf: [IndividualCustomerData, CorporateCustomerData],
|
|
discriminator: %OpenApiSpex.Discriminator{
|
|
propertyName: "customer_type",
|
|
mapping: %{
|
|
"individual" => IndividualCustomerData,
|
|
"corporate" => CorporateCustomerData
|
|
}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule CreateCustomer do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "CreateCustomer",
|
|
type: :object,
|
|
required: [:first_name, :last_name],
|
|
properties: %{
|
|
first_name: %Schema{type: :string},
|
|
last_name: %Schema{type: :string},
|
|
email: %Schema{type: :string, format: :email},
|
|
phone: %Schema{type: :string},
|
|
birth_date: %Schema{type: :string, format: :date},
|
|
gender: %Schema{type: :string},
|
|
document_id: %Schema{type: :string}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule CreateCorporateCustomer do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "CreateCorporateCustomer",
|
|
type: :object,
|
|
required: [:legal_name, :ruc],
|
|
properties: %{
|
|
legal_name: %Schema{type: :string},
|
|
commercial_name: %Schema{type: :string},
|
|
ruc: %Schema{type: :string},
|
|
legal_rep_name: %Schema{type: :string},
|
|
legal_rep_document_id: %Schema{type: :string},
|
|
email: %Schema{type: :string, format: :email},
|
|
phone: %Schema{type: :string},
|
|
address: %Schema{type: :string}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule UpdateCustomer do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "UpdateCustomer",
|
|
type: :object,
|
|
properties: %{
|
|
first_name: %Schema{type: :string},
|
|
last_name: %Schema{type: :string},
|
|
email: %Schema{type: :string, format: :email},
|
|
phone: %Schema{type: :string},
|
|
birth_date: %Schema{type: :string, format: :date},
|
|
gender: %Schema{type: :string},
|
|
document_id: %Schema{type: :string},
|
|
address: %Schema{type: :string}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule UpdateCorporateCustomer do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "UpdateCorporateCustomer",
|
|
type: :object,
|
|
properties: %{
|
|
legal_name: %Schema{type: :string},
|
|
commercial_name: %Schema{type: :string},
|
|
ruc: %Schema{type: :string},
|
|
legal_rep_name: %Schema{type: :string},
|
|
legal_rep_document_id: %Schema{type: :string},
|
|
email: %Schema{type: :string, format: :email},
|
|
phone: %Schema{type: :string},
|
|
address: %Schema{type: :string}
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule CustomerListResponse do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "CustomerListResponse",
|
|
type: :object,
|
|
properties: %{
|
|
data: %Schema{type: :array, items: CustomerData},
|
|
meta: PaginationMeta
|
|
}
|
|
})
|
|
end
|
|
|
|
defmodule CustomerResponse do
|
|
require OpenApiSpex
|
|
|
|
OpenApiSpex.schema(%{
|
|
title: "CustomerResponse",
|
|
type: :object,
|
|
properties: %{
|
|
data: CustomerData
|
|
}
|
|
})
|
|
end
|
|
end
|