mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
feat: show_private?
option for diagrams (#396)
This commit is contained in:
parent
2c685a6a2e
commit
14a1b92963
2 changed files with 88 additions and 8 deletions
|
@ -12,8 +12,9 @@ defmodule Ash.Api.Info.Diagram do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@indent " "
|
@indent " "
|
||||||
|
@show_private? false
|
||||||
|
|
||||||
@default_opts indent: @indent
|
@default_opts indent: @indent, show_private?: @show_private?
|
||||||
|
|
||||||
defp resource_name(resource) do
|
defp resource_name(resource) do
|
||||||
resource
|
resource
|
||||||
|
@ -68,12 +69,22 @@ defmodule Ash.Api.Info.Diagram do
|
||||||
"""
|
"""
|
||||||
def mermaid_er_diagram(api, opts \\ @default_opts) do
|
def mermaid_er_diagram(api, opts \\ @default_opts) do
|
||||||
indent = opts[:indent] || @indent
|
indent = opts[:indent] || @indent
|
||||||
|
show_private? = Access.get(opts, :show_private?, @show_private?)
|
||||||
|
|
||||||
resources =
|
resources =
|
||||||
for resource <- Ash.Api.Info.resources(api) do
|
for resource <- Ash.Api.Info.resources(api) do
|
||||||
attrs = Ash.Resource.Info.public_attributes(resource)
|
{attrs, calcs, aggs} =
|
||||||
calcs = Ash.Resource.Info.public_calculations(resource)
|
if show_private? do
|
||||||
aggs = Ash.Resource.Info.public_aggregates(resource)
|
{
|
||||||
|
Ash.Resource.Info.attributes(resource),
|
||||||
|
Ash.Resource.Info.calculations(resource),
|
||||||
|
Ash.Resource.Info.aggregates(resource)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{Ash.Resource.Info.public_attributes(resource),
|
||||||
|
Ash.Resource.Info.public_calculations(resource),
|
||||||
|
Ash.Resource.Info.public_aggregates(resource)}
|
||||||
|
end
|
||||||
|
|
||||||
contents =
|
contents =
|
||||||
[
|
[
|
||||||
|
@ -121,14 +132,26 @@ defmodule Ash.Api.Info.Diagram do
|
||||||
"""
|
"""
|
||||||
def mermaid_class_diagram(api, opts \\ @default_opts) do
|
def mermaid_class_diagram(api, opts \\ @default_opts) do
|
||||||
indent = opts[:indent] || @indent
|
indent = opts[:indent] || @indent
|
||||||
|
show_private? = Access.get(opts, :show_private?, @show_private?)
|
||||||
|
|
||||||
resources =
|
resources =
|
||||||
for resource <- Ash.Api.Info.resources(api) do
|
for resource <- Ash.Api.Info.resources(api) do
|
||||||
attrs = Ash.Resource.Info.public_attributes(resource)
|
|
||||||
calcs = Ash.Resource.Info.public_calculations(resource)
|
|
||||||
aggs = Ash.Resource.Info.public_aggregates(resource)
|
|
||||||
actions = Ash.Resource.Info.actions(resource)
|
actions = Ash.Resource.Info.actions(resource)
|
||||||
relationships = Ash.Resource.Info.public_relationships(resource)
|
|
||||||
|
{attrs, calcs, aggs, relationships} =
|
||||||
|
if show_private? do
|
||||||
|
{
|
||||||
|
Ash.Resource.Info.attributes(resource),
|
||||||
|
Ash.Resource.Info.calculations(resource),
|
||||||
|
Ash.Resource.Info.aggregates(resource),
|
||||||
|
Ash.Resource.Info.relationships(resource)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{Ash.Resource.Info.public_attributes(resource),
|
||||||
|
Ash.Resource.Info.public_calculations(resource),
|
||||||
|
Ash.Resource.Info.public_aggregates(resource),
|
||||||
|
Ash.Resource.Info.public_relationships(resource)}
|
||||||
|
end
|
||||||
|
|
||||||
contents =
|
contents =
|
||||||
[
|
[
|
||||||
|
|
|
@ -51,4 +51,61 @@ defmodule Ash.Test.Api.Info.DiagramTest do
|
||||||
Org -- User
|
Org -- User
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "include private fields in a mermaid entity relationship diagram from an Api if specified" do
|
||||||
|
assert Ash.Api.Info.Diagram.mermaid_er_diagram(Ash.Test.Support.Flow.Api, show_private?: true) ==
|
||||||
|
"""
|
||||||
|
erDiagram
|
||||||
|
User {
|
||||||
|
UUID id
|
||||||
|
String first_name
|
||||||
|
String last_name
|
||||||
|
String email
|
||||||
|
Boolean approved
|
||||||
|
UUID org_id
|
||||||
|
}
|
||||||
|
Org {
|
||||||
|
UUID id
|
||||||
|
String name
|
||||||
|
}
|
||||||
|
|
||||||
|
Org ||--|| User : ""
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
test "include private fields in a mermaid class diagram from an Api if specified" do
|
||||||
|
assert Ash.Api.Info.Diagram.mermaid_class_diagram(Ash.Test.Support.Flow.Api,
|
||||||
|
show_private?: true
|
||||||
|
) == """
|
||||||
|
classDiagram
|
||||||
|
class User {
|
||||||
|
UUID id
|
||||||
|
String first_name
|
||||||
|
String last_name
|
||||||
|
String email
|
||||||
|
Boolean approved
|
||||||
|
UUID org_id
|
||||||
|
Org org
|
||||||
|
destroy()
|
||||||
|
read()
|
||||||
|
for_org()
|
||||||
|
create()
|
||||||
|
update()
|
||||||
|
approve()
|
||||||
|
unapprove()
|
||||||
|
}
|
||||||
|
class Org {
|
||||||
|
UUID id
|
||||||
|
String name
|
||||||
|
User[] users
|
||||||
|
destroy()
|
||||||
|
update()
|
||||||
|
read()
|
||||||
|
create()
|
||||||
|
by_name()
|
||||||
|
}
|
||||||
|
|
||||||
|
Org -- User
|
||||||
|
"""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue