You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenAPI describes a @single endpoint's response as an array #36
Note: an AI coding agent (Claude Code) found this and wrote it up while building software on NpgsqlRest 4.1.0. Please check it before you rely on it.
Seen in a real project: every @single endpoint (functions that return a table, called with GET and POST) is answered with one object, the generated TS client types it as one object, and openapi.json describes it as an array.
Read in the source, not run: the cause below, on master.
Not run as written: the minimal repro below, which is adapted from those endpoints. The @void point at the end is a guess from reading the code.
What happens
A function that returns a set, annotated @single, answers with one JSON object, and the generated TypeScript client types it as one object. The OpenAPI document describes the same response as an array of objects, so clients generated from openapi.json expect the wrong shape.
Reproduce (NpgsqlRest 4.1.0)
createfunctionapi.register_thing()
returns table (thing_id uuid, name text)
language sql
begin atomic
select gen_random_uuid(), 'a';
end;
comment on function api.register_thing() is '@http POST /api/things@singleRegisters a thing.';
POST /api/things answers {"thingId": "…", "name": "a"}.
The TypeScript client returns Promise<ApiResult<IRegisterThingResponse>>, one object.
GetResponseSchema in plugins/NpgsqlRest.OpenApi/OpenApi.cs decides on routine.ReturnsSet alone and never sees the endpoint. plugins/NpgsqlRest.TsClient/TsClient.cs already checks returnsSet && !endpoint.ReturnSingleRecord.
Suggested fix
Pass the endpoint to GetResponseSchema, and give the array schema only when routine.ReturnsSet && !endpoint.ReturnSingleRecord. Otherwise fall through to the single-object branch.
The same file also decides whether there is a response body on endpoint.Routine.IsVoid alone, while the TS client uses routine.IsVoid || endpoint.Void. So a @void endpoint probably gets a response schema too. I haven't checked that one by running it.
Thanks for the report, and for the clear write-up. Reproduced and confirmed, both points.
While checking this I compared the OpenAPI document with the real answers of every endpoint in the test suite, and the same kind of mismatch showed up in other places too (set of values, text/plain results, raw, table_format, bytea, cache invalidation endpoints, SQL files with several statements, and a few more). The generated TypeScript and Dart clients and the MCP tool schemas had some of their own.
All of it is fixed and covered with tests, and will be in 4.1.1. I'll leave the issue open until that is released.
A @single endpoint is now described as one object in openapi.json, and the other mismatches between the described and the real response are fixed in the OpenAPI document, the generated TypeScript and Dart clients and the MCP tool schemas. The full list, two changes in responses (money values, the default content type of raw) and what still cannot be described exactly are in the changelog.
After upgrading, regenerate the OpenAPI document and the clients. Thanks again for the report.
Thanks for the quick fix, and for going well beyond the case I reported. Upgraded to 4.1.1 and regenerated: all @single endpoints in our project are now described as one object in openapi.json.
Activity
vbilopav commentedon Dec 2, 2026
Thanks for the report, and for the clear write-up. Reproduced and confirmed, both points.
While checking this I compared the OpenAPI document with the real answers of every endpoint in the test suite, and the same kind of mismatch showed up in other places too (set of values,
text/plainresults,raw,table_format,bytea, cache invalidation endpoints, SQL files with several statements, and a few more). The generated TypeScript and Dart clients and the MCP tool schemas had some of their own.All of it is fixed and covered with tests, and will be in 4.1.1. I'll leave the issue open until that is released.
vbilopav commentedon Dec 2, 2026
Released in 4.1.1.
A
@singleendpoint is now described as one object inopenapi.json, and the other mismatches between the described and the real response are fixed in the OpenAPI document, the generated TypeScript and Dart clients and the MCP tool schemas. The full list, two changes in responses (moneyvalues, the default content type ofraw) and what still cannot be described exactly are in the changelog.After upgrading, regenerate the OpenAPI document and the clients. Thanks again for the report.
mjurincic commentedon Dec 2, 2026
Thanks for the quick fix, and for going well beyond the case I reported. Upgraded to 4.1.1 and regenerated: all @single endpoints in our project are now described as one object in openapi.json.