Skip to content

Commit

Permalink
Tweak type printing again for mermaid diagrams (#26)
Browse files Browse the repository at this point in the history
* add failing test

* Fix test

* Update reference tests

* Breaking bump (again)

* Update src/mermaid.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* add some `type_string` unit tests

* Update test/mermaid.jl

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ericphanson and github-actions[bot] authored Sep 14, 2023
1 parent 260c250 commit 1d600a2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TransformSpecifications"
uuid = "b92eaff8-8912-4b32-ad24-14d7c692d780"
authors = ["Beacon Biosignals, Inc"]
version = "0.3.0"
version = "0.4.0"

[deps]
Legolas = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd"
Expand Down
11 changes: 8 additions & 3 deletions src/mermaid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function _mermaid_subgraph_from_dag_step(step::DAGStep)
", :" => ",\n ")
"$(node_name){{\"$fieldname:\n $fieldstr\"}}"
else
"$(node_name){{\"$fieldname::$(nameof(type))\"}}"
"$(node_name){{\"$fieldname::$(type_string(type))\"}}"
end
return [node_contents,
"class $(node_name) classSpecField"]
Expand All @@ -131,7 +131,7 @@ function _mermaid_subgraph_from_dag_step(step::DAGStep)
inputs_subgraph = let
prefix = "_InputSchema"
contents = _schema_subgraph(field_dict(input_specification(process)), prefix)
label = string("Input: ", nameof(input_specification(process)))
label = string("Input: ", type_string(input_specification(process)))
_mermaid_subgraph(node_key * prefix, label; contents, direction="RL")
end

Expand All @@ -143,7 +143,7 @@ function _mermaid_subgraph_from_dag_step(step::DAGStep)
outputs_subgraph = let
prefix = "_OutputSchema"
type = result_type(output_specification(process))
label = string("Output: ", nameof(type))
label = string("Output: ", type_string(type))
contents = _schema_subgraph(field_dict(type), prefix)
_mermaid_subgraph(node_key * prefix, label; contents, direction="RL")
end
Expand All @@ -156,3 +156,8 @@ function _mermaid_subgraph_from_dag_step(step::DAGStep)
return _mermaid_subgraph(node_key, uppercasefirst(replace(string(key), "_" => " "));
contents, direction="TB")
end

# https://github.com/beacon-biosignals/TransformSpecifications.jl/issues/25
# Meant to return a canonical printed representation of the unqualified type name
# Any output of `fieldtype` is a valid input for this function.
type_string(t::Type) = sprint(print, t; context=:compact => true)
10 changes: 9 additions & 1 deletion test/mermaid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end # module

@schema "schema-rad" SchemaRad
@version SchemaRadV1 begin
foo::String
foo::Union{String,Missing}
list::Vector{Int}
end

Expand Down Expand Up @@ -56,6 +56,7 @@ end
function TransformSpecifications.field_dict_value(t::Type{SchemaRadV1})
return TransformSpecifications.field_dict(t)
end
local ref_test_file, test_str
try
test_str = ("```mermaid\n$(mermaidify(dag))\n```\n")
ref_test_file = joinpath(pkgdir(TransformSpecifications), "test",
Expand All @@ -71,4 +72,11 @@ end
# update the reference by doing
# write(ref_test_file, test_str)
end

@testset "type_string" begin
@test type_string(fieldtype(SchemaRadV1, 1)) == "Union{Missing, String}"
@test type_string(fieldtype(SchemaRadV1, 2)) == "Vector{Int64}"
@test type_string(Vector{String}) == "Vector{String}"
@test type_string(RobustImportsTest.A.X) == "X"
end
end
10 changes: 5 additions & 5 deletions test/reference_tests/mermaid_custom.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ subgraph STEP_A[Step a]
direction TB
subgraph STEP_A_InputSchema[Input: SchemaRadV1]
direction RL
STEP_A_InputSchemalist{{"list::Array"}}
STEP_A_InputSchemalist{{"list::Vector{Int64}"}}
class STEP_A_InputSchemalist classSpecField
STEP_A_InputSchemafoo{{"foo::String"}}
STEP_A_InputSchemafoo{{"foo::Union{Missing, String}"}}
class STEP_A_InputSchemafoo classSpecField
end
class STEP_A_InputSchema classSpec
Expand All @@ -19,16 +19,16 @@ subgraph STEP_B[Step b]
direction TB
subgraph STEP_B_InputSchema[Input: SchemaRadV1]
direction RL
STEP_B_InputSchemalist{{"list::Array"}}
STEP_B_InputSchemalist{{"list::Vector{Int64}"}}
class STEP_B_InputSchemalist classSpecField
STEP_B_InputSchemafoo{{"foo::String"}}
STEP_B_InputSchemafoo{{"foo::Union{Missing, String}"}}
class STEP_B_InputSchemafoo classSpecField
end
subgraph STEP_B_OutputSchema[Output: SchemaYayV1]
direction RL
STEP_B_OutputSchemarad{{"rad:
list::Vector{Int64},
foo::String"}}
foo::Union{Missing, String}"}}
class STEP_B_OutputSchemarad classSpecField
end
STEP_B_InputSchema:::classSpec -- make_rad --> STEP_B_OutputSchema:::classSpec
Expand Down
8 changes: 4 additions & 4 deletions test/reference_tests/mermaid_legolas.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ subgraph STEP_A[Step a]
direction TB
subgraph STEP_A_InputSchema[Input: SchemaRadV1]
direction RL
STEP_A_InputSchemalist{{"list::Array"}}
STEP_A_InputSchemalist{{"list::Vector{Int64}"}}
class STEP_A_InputSchemalist classSpecField
STEP_A_InputSchemafoo{{"foo::String"}}
STEP_A_InputSchemafoo{{"foo::Union{Missing, String}"}}
class STEP_A_InputSchemafoo classSpecField
end
class STEP_A_InputSchema classSpec
Expand All @@ -19,9 +19,9 @@ subgraph STEP_B[Step b]
direction TB
subgraph STEP_B_InputSchema[Input: SchemaRadV1]
direction RL
STEP_B_InputSchemalist{{"list::Array"}}
STEP_B_InputSchemalist{{"list::Vector{Int64}"}}
class STEP_B_InputSchemalist classSpecField
STEP_B_InputSchemafoo{{"foo::String"}}
STEP_B_InputSchemafoo{{"foo::Union{Missing, String}"}}
class STEP_B_InputSchemafoo classSpecField
end
subgraph STEP_B_OutputSchema[Output: SchemaYayV1]
Expand Down
8 changes: 4 additions & 4 deletions test/reference_tests/mermaid_nothrowdag.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ subgraph STEP_A[Step a]
direction TB
subgraph STEP_A_InputSchema[Input: SchemaFooV1]
direction RL
STEP_A_InputSchemalist{{"list::Array"}}
STEP_A_InputSchemalist{{"list::Vector{Int64}"}}
class STEP_A_InputSchemalist classSpecField
STEP_A_InputSchemafoo{{"foo::String"}}
class STEP_A_InputSchemafoo classSpecField
Expand All @@ -26,14 +26,14 @@ subgraph STEP_B[Step b]
direction TB
subgraph STEP_B_InputSchema[Input: SchemaFooV1]
direction RL
STEP_B_InputSchemalist{{"list::Array"}}
STEP_B_InputSchemalist{{"list::Vector{Int64}"}}
class STEP_B_InputSchemalist classSpecField
STEP_B_InputSchemafoo{{"foo::String"}}
class STEP_B_InputSchemafoo classSpecField
end
subgraph STEP_B_OutputSchema[Output: SchemaFooV1]
direction RL
STEP_B_OutputSchemalist{{"list::Array"}}
STEP_B_OutputSchemalist{{"list::Vector{Int64}"}}
class STEP_B_OutputSchemalist classSpecField
STEP_B_OutputSchemafoo{{"foo::String"}}
class STEP_B_OutputSchemafoo classSpecField
Expand All @@ -51,7 +51,7 @@ subgraph STEP_C[Step c]
end
subgraph STEP_C_OutputSchema[Output: SchemaFooV1]
direction RL
STEP_C_OutputSchemalist{{"list::Array"}}
STEP_C_OutputSchemalist{{"list::Vector{Int64}"}}
class STEP_C_OutputSchemalist classSpecField
STEP_C_OutputSchemafoo{{"foo::String"}}
class STEP_C_OutputSchemafoo classSpecField
Expand Down
1 change: 1 addition & 0 deletions test/set_up_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using TransformSpecifications
using Logging
using OrderedCollections
using Test
using TransformSpecifications: type_string

# For doctests
if !isdefined(TransformSpecifications, :META) # avoids annoying warning if this has already been run once
Expand Down

2 comments on commit 1d600a2

@ericphanson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/91445

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" 1d600a277a60237ad6e28d753a100b62438f1c4e
git push origin v0.4.0

Please sign in to comment.