Create Malli (API) schemas from captured HTTP requests and responses or from recording inputs and outputs of instrumented functions, e.g. during a test run. You can also diff the API schemas (for example to explore how the REST API changed between versions) and the instrumentation-based process includes the schemas in the functions' docstrings, which might help in familiarizing with an unknown code base.
We use https://github.com/stathissideris/spec-provider to infer Malli (https://github.com/metosin/malli) schemas and https://github.com/wilkerlucio/pathom3 as our main API.
Malli has a way to generate schemas, but it was too slow in comparison
with spec-provider
.
See a post about Pitoco at https://pfeodrippe.github.io/posts/pitoco.html.
See the test file and rich comments (comment
) in the core for usage.
We have a web app which uses Pitoco so you can visualize your schemas easily, but you can use Pitoco as a library.
You can start the server at http://localhost:8081 by loading the
pitoco.server
namespace. Now start the shadow-cljs
server and access http://localhost:8000.
The first use case of Pitoco is generating Malli schemas for REST APIs based on captured HTTP requests and responses (using either HAR archives from your browser or .pcap files from tcpdump).
See a quick video at https://youtu.be/iMcUTygFrfk.
The second use case of Pitoco is to instrument selected vars, record their inputs and outputs, and generate Malli schemas from those, including them in the vars' docstrings.
See the pitoco.instrumentation
namespace.
Also you can watch https://youtu.be/MloJSCl38d0.
There is a [VSCode Extension](https://marketplace.visualstudio.com/items?itemName=feodrippe.pitoco-extension&ssr=false#overview) where you can visualize the inferred schemas (+ examples) using VSCode in the web (e.g. during PRs so you can have augmented context when needed).
Clone the repo and enter in the repo
git clone https://github.com/pfeodrippe/pitoco
cd pitoco
Enter in the web_app
directory, install npm
deps and start the frontend.
cd web_dev
npm install
npm start
The npm start
command should spawn both shadow-cljs
and tailwindcss
.
Then in another terminal, you can enter in the web_dev
folder again and start the backend.
cd pitoco/web_dev
clj -e "(require,'pitoco.server)"
After a while, the frontend will be available at localhost:8000. You can connect on it via browser.
The backend will be available at localhost:8081. You can check if it is running with curl
curl http://localhost:8081/chsk
# {"type":"exception","class":"clojure.lang.ExceptionInfo"}