expose JSON schema for inspection (#351)

intending to document more about how our schemas work, i found our code currently buries this somewhere in `/nix/store`.
this change exposes that generated file in the project structure as well, facilitating inspection of our data schema in this more generic format.

Reviewed-on: Fediversity/Fediversity#351
Reviewed-by: Nicolas Jeannerod <nicolas.jeannerod@moduscreate.com>
Co-authored-by: Kiara Grouwstra <kiara@procolix.eu>
Co-committed-by: Kiara Grouwstra <kiara@procolix.eu>
This commit is contained in:
Kiara Grouwstra 2025-06-04 19:15:26 +02:00 committed by kiara Grouwstra
parent afc7ad2b88
commit 69579fea1c
2 changed files with 31 additions and 24 deletions

2
panel/.gitignore vendored
View file

@ -11,5 +11,5 @@ db.sqlite3
src/db.sqlite3 src/db.sqlite3
src/static src/static
src/panel/static/htmx* src/panel/static/htmx*
src/panel/configuration/schema.py src/panel/configuration/schema.*
.credentials .credentials

View file

@ -14,7 +14,7 @@ let
root = ../src; root = ../src;
fileset = intersection (gitTracked ../../.) ../src; fileset = intersection (gitTracked ../../.) ../src;
}; };
pyproject = with lib; fromTOML pyproject-toml; pyproject = fromTOML pyproject-toml;
# TODO: define this globally # TODO: define this globally
name = "panel"; name = "panel";
# TODO: we may want this in a file so it's easier to read statically # TODO: we may want this in a file so it's easier to read statically
@ -29,28 +29,35 @@ let
include-package-data = true include-package-data = true
''; '';
generated = [ generated =
{ let
from = "${sources.htmx}/dist/htmx.min.js"; jsonschema = callPackage "${sources.clan-core}/lib/jsonschema" { } { };
to = "./panel/static/htmx.min.js"; frontend-options = jsonschema.parseModule ../../deployment/options.nix;
} schema = with builtins; toFile "schema.json" (toJSON frontend-options);
{ in
from = [
let {
jsonschema = callPackage "${sources.clan-core}/lib/jsonschema" { } { }; from = "${sources.htmx}/dist/htmx.min.js";
frontend-options = jsonschema.parseModule ../../deployment/options.nix; to = "./panel/static/htmx.min.js";
schema = with builtins; toFile "schema.json" (toJSON frontend-options); }
codegen = "${python3Packages.datamodel-code-generator}/bin/datamodel-codegen"; {
pydantic = runCommand "schema.py" { } '' from = schema;
# replace plain `pydantic` with `drf_pydantic` so we can create forms automatically to = "./panel/configuration/schema.json";
${codegen} --input ${schema} | sed '/from pydantic/a\ }
from drf_pydantic import BaseModel' > $out {
''; from =
in let
"${pydantic}"; codegen = "${python3Packages.datamodel-code-generator}/bin/datamodel-codegen";
to = "./panel/configuration/schema.py"; pydantic = runCommand "schema.py" { } ''
} # replace plain `pydantic` with `drf_pydantic` so we can create forms automatically
]; ${codegen} --input ${schema} | sed '/from pydantic/a\
from drf_pydantic import BaseModel' > $out
'';
in
"${pydantic}";
to = "./panel/configuration/schema.py";
}
];
in in
python3.pkgs.buildPythonPackage { python3.pkgs.buildPythonPackage {
pname = name; pname = name;