Skip to content

Handle schema annotations after function names#197

Merged
tsmacdonald merged 1 commit intoclj-commons:masterfrom
bshepherdson:parse-schema-type-annotations
Mar 14, 2026
Merged

Handle schema annotations after function names#197
tsmacdonald merged 1 commit intoclj-commons:masterfrom
bshepherdson:parse-schema-type-annotations

Conversation

@bshepherdson
Copy link
Copy Markdown
Contributor

Fixes #133.

Both Plumatic Schema and Malli can annotate functions with a return schema using syntax like (def fn-name :- Type "docstring" ...).

Marginalia previously did not recognize those docstrings, therefore they were not extracted to the left-hand prose document, nor removed from the right-hand view of the code.

This PR checks for the :- marker that both schema libraries use, and skips over it to locate and extract the docstring correctly. The :- Type is preserved in the code view.

There are some test cases in the repo, plus I checked it against some Metabase code that uses Malli-powered mu/defn and it works beautifully.

Fixes clj-commons#133.

Both Plumatic Schema and Malli can annotate functions with a return
schema using syntax like `(def fn-name :- Type "docstring" ...)`.

Marginalia previously did not recognize those docstrings, therefore they
were not extracted to the left-hand prose document, nor removed from the
right-hand view of the code.

This PR checks for the `:-` marker that both schema libraries use, and
skips over it to locate and extract the docstring correctly. The `:- Type`
is preserved in the code view.
@tsmacdonald
Copy link
Copy Markdown
Collaborator

Looks great, thanks Braden!

@tsmacdonald tsmacdonald merged commit c3af2e3 into clj-commons:master Mar 14, 2026
3 of 6 checks passed
@tsmacdonald
Copy link
Copy Markdown
Collaborator

I fixed CI in #198 but didn't have the right permissions to rebase Braden's branch in situ. I thought about either cherry-picking it into my own branch/PR (but that muddies the Github history) or asking Braden to do it (which would delay this even more) and decided it was low-risk enough to YOLO-merge it and just make sure the build on master passed. Sure enough, everything's fine: https://github.com/clj-commons/marginalia/actions/runs/23082569614

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No doc-string recognized for the functions that use Prismatic's Schema

2 participants