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/static
src/panel/static/htmx*
src/panel/configuration/schema.py
src/panel/configuration/schema.*
.credentials

View file

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