Better example in API explorer for /-/upsert, closes #1936

This commit is contained in:
Simon Willison 2026-04-15 15:29:59 -07:00
commit 73f338b9f3
2 changed files with 24 additions and 2 deletions

View file

@ -813,9 +813,15 @@ class ApiExplorerView(BaseView):
"json": {
"rows": [
{
column: None
column: "<{}{}>".format(
column,
(
" (primary key)"
if column in pks
else ""
),
)
for column in await db.table_columns(table)
if column not in pks
}
]
},

View file

@ -44,6 +44,22 @@ def _headers(token):
}
@pytest.mark.asyncio
async def test_api_explorer_upsert_example_json(ds_write):
response = await ds_write.client.get("/-/api", actor={"id": "root"})
print("STATUS", response.status_code)
assert response.status_code == 200
import urllib.parse
text = urllib.parse.unquote_plus(response.text)
upsert_idx = text.index("/data/docs/-/upsert")
upsert_chunk = text[upsert_idx : upsert_idx + 500]
assert '"id": "<id (primary key)>"' in upsert_chunk
assert '"title": "<title>"' in upsert_chunk
assert '"score": "<score>"' in upsert_chunk
assert '"age": "<age>"' in upsert_chunk
@pytest.mark.asyncio
@pytest.mark.parametrize(
"content_type",