Changelog v4.1.1
Version 4.1.1 (2026-12-02)
Patch release. What the generators say an endpoint answers with now matches what the endpoint answers with: the OpenAPI document, the generated TypeScript and Dart clients, and the MCP tool schemas. Reported in #36 for one case (@single in the OpenAPI document). The other cases were found by calling every endpoint of the test suite and comparing each answer with the document. Two responses were wrong themselves and are fixed: a money value made the response invalid JSON, and a raw response was labelled as JSON. No configuration key was added or changed.
Who should upgrade: everyone who generates clients from openapi.json, and everyone who uses raw, table_format, money or bytea results, uploads, the void annotation or cache invalidation endpoints with the generated TypeScript or Dart clients or with MCP tools.
After upgrading: regenerate the OpenAPI document and the clients. Read Changes in responses first: two responses change. What still cannot be described exactly is listed in Known limits.
Summary
| What | Affects | |
|---|---|---|
| Changed | money values are JSON strings ("$1,234.50"); they were written without quotes, which is not valid JSON | responses, all generators |
| Changed | raw responses without a content type are text/plain; they were application/json | responses, OpenAPI |
| Fixed | the described response follows the endpoint's annotations and return type (single, void, single values, bytea, raw, table_format, json, composite types, SQL files with several statements, cache invalidation, proxy, login) | OpenAPI |
| Fixed | upload endpoints have a multipart/form-data request body | OpenAPI |
| Fixed | a 204 response is documented for endpoints that answer NULL or no row with it | OpenAPI |
| Fixed | the cache invalidation endpoint of a hidden endpoint is hidden, and has the tags of its endpoint | OpenAPI, MCP |
| Fixed | functions for raw, table_format, bytea, cache invalidation and upload endpoints read and type the response the endpoint gives | TypeScript and Dart clients |
| Fixed | outputSchema and structuredContent agree for a set with one named column, single and the void annotation | MCP |
| Documented | what cannot be described exactly | Known limits |
Contents
Changes in responses
money values are JSON strings
A money value in a row was written without quotes:
json
[{"id":1,"price":$1,234.50}]This is not valid JSON, so no client could read a response that had a money column, an array of money, or a composite type with a money field. It is now a string, as PostgreSQL writes it:
json
[{"id":1,"price":"$1,234.50"}]- The text is in the format of the database's
lc_monetarysetting ($1,234.50,1.234,50 €), which is why it cannot be a JSON number. To get a number, returnprice::numericfrom the routine. - A routine that returns one
moneyvalue answers with it astext/plain, as before. - A
moneyparameter is unchanged: it is a decimal number, sent as a number (12.5) or as a string ("12.5"). - The generators follow:
moneyisstringin the TypeScript client,Stringin the Dart client (it wasdouble), and a string in the OpenAPI document and in MCP schemas. This applies to parameters as well.
raw responses are text/plain
A raw endpoint that does not set a content type answered with the content type application/json, although its body is text that is not JSON. It now answers with text/plain. The same goes for a raw routine that returns a single array value.
If you rely on the old header: set it on the endpoint.
sql
comment on function export_users() is '
HTTP GET
raw
Content-Type: application/json';Endpoints that already set a content type (Content-Type: text/csv) are not affected.
Fixes
OpenAPI: the described response did not match the response
The document decided the response from the routine alone and did not look at the endpoint's annotations. Before the fix, 482 of the 1,271 answers of the test suite's endpoints that could be compared were not what the document said.
| Endpoint | The document said | The endpoint answers with, and the document now says |
|---|---|---|
single on a set of rows (#36) | an array of objects | one object |
single on a set of values (returns setof text) | an array of objects | one value |
a set of values (returns setof text) | an array of objects | an array of values |
void annotation, or a routine that returns nothing | 200 | 204, no body |
a single value that is not json or an array (returns text, int, boolean...) | application/json | text/plain; a boolean is t or f |
bytea | application/json, a string | application/octet-stream |
raw | an array of objects | a string, text/plain |
table_format (HTML, Excel) | application/json, an array of objects | the content type of the format |
json and jsonb values and columns | an object | any JSON value |
money | a number | a string |
| a column that is an array of a composite type | an array of strings | an array of objects with the type's fields |
nested composite columns | the fields of the type as columns of the row | one object under the column name |
returns record | an object | an array of strings |
| SQL files with several statements | the columns of the first statement | an object with a property for each statement: its rows (one object with single), or the number of rows it affected |
cache invalidation endpoint (InvalidateCacheSuffix) | the response of the cached endpoint | {"invalidated": true} or {"invalidated": false} |
proxy with a routine that returns nothing, and proxy_out | no body | the response of the upstream service (*/*) |
login | the routine's columns | a body that depends on the authentication scheme (*/*) |
a content type taken from a parameter (Content-Type: {_type}) | the content type {_type} | */* |
For the function in the report
sql
create function api.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
@single
Registers a thing.';the response in openapi.json was
json
"200": { "description": "Successful response", "content": { "application/json": { "schema": {
"type": "array", "items": { "type": "object", "properties": { "thingId": { "type": "string", "format": "uuid" }, "name": { "type": "string" } } }
} } } }and is now
json
"200": { "description": "Successful response", "content": { "application/json": { "schema": {
"type": "object", "properties": { "thingId": { "type": "string", "format": "uuid" }, "name": { "type": "string" } }
} } } }OpenAPI: three more things the document did not say
- Uploads. An upload endpoint had no request body in the document. It now has a
multipart/form-databody with the files. 204for no value. An endpoint that answers aNULLvalue, orsinglewith no row, with204(response_null_handling no_content) now has a204response next to its200.- Hidden endpoints. The cache invalidation endpoint of an endpoint with
openapi hidewas still in the document, so the path that was meant to be hidden was visible. It is hidden now, and an invalidation endpoint also gets theopenapi tagsof its endpoint.
TypeScript and Dart clients: functions that read the wrong kind of response
raw. The function read the response as JSON (response.json(),jsonDecode) and failed, because arawendpoint answers with text. It now returns the text (string,String).table_formatandbytea. The function read an HTML table or an Excel file as JSON, and bytes as text. It now returns the response itself (Response,http.Response), as functions of proxy endpoints do, so the caller reads it as text or as bytes.- Cache invalidation endpoints. The function was typed as the cached endpoint's response. It now returns
{ invalidated: boolean }(Map<String, dynamic>in Dart). It is also written to the same module as the function of the cached endpoint, and the othertsclient_...anddartclient_...annotations of that endpoint apply to it. Before, they did not, and the function went to the default module. - Uploads. The function of every upload endpoint was typed as a list of file descriptions (the upload metadata). That is right only when the routine returns the metadata, which is a routine that returns one
jsonvalue. For any other routine the response is nowany(dynamicin Dart). - Dart,
voidannotation. The function read a body from an endpoint that answers204without one. The TypeScript client was already correct.
MCP: outputSchema and structuredContent for four return shapes
- A set with one named column (
returns table (val text)): the schema saiditemsare values, and they are objects ({"val": ...}). singleon a set with one named column: the row was wrapped as text ({"value": "{\"val\":\"a\"}"}). It is now the object itself ({"val": "a"}).singleon a set of values: a text value kept its JSON quotes ({"value": "\"a\""}). It is now the value ({"value": "a"}).voidannotation: the tool declared anoutputSchemaand returned nostructuredContent. It now declares none.
Known limits
What a generator cannot know when the endpoints are built. None of these is new in this version.
- Arrays of more than one dimension. The number of dimensions is not part of a PostgreSQL array type:
int[]andint[][]are the same type. An array is described as one of a single dimension (number[],List<int>,{"type":"array","items":{"type":"integer"}}), also when its values are arrays themselves ([[1,2],[3,4]]). An array of a composite type with more than one dimension holds its values as text ("(1,a)"), not as objects. jsonandjsonb. The value can be any JSON value, so it is described as any value (any,dynamic,{}), not as its actual shape.NULLand missing rows. A single value that isNULL, andsinglewith no row, are answered with an empty body, withnullor with204, depending onresponse_null_handling. The document describes the response with a value (and the204, when it is configured). It does not mark values as nullable: the OpenAPI document has no nullability at all yet, for parameters or for responses.- Responses decided at request time. A content type or a table format taken from a parameter (
Content-Type: {_type},table_format = {_format}), the response of a proxied upstream service, and the body of alogin(it depends on the authentication scheme) are described as any content (*/*), and the generated client functions for proxies and table formats return the response itself. - A text value declared as JSON. A routine that returns
texton an endpoint withContent-Type: application/jsonis described as any JSON value. Whether the text is valid JSON is up to the routine. - Uploads in the generated clients. The upload function reads the response as JSON. A routine of an upload endpoint that returns plain text (
returns text) is answered astext/plain, and the function fails to read it. Returnjsonfrom such a routine. - Columns with the same name. A result with two columns of the same name is written as a JSON object with that key twice (
{"value":1,"value":2}). The descriptions hold one property of that name. Give the columns different names. moneytext depends on the database. See above: the same value is$1,234.50in one database and1.234,50 €in another.- Responses written by custom code. A response written by a
CommandCallbackAsyncor another extension point of the library is not known to the generators. They describe what the endpoint would answer with on its own.
For plugin authors
RoutineEndpoint.GetResponseKind(NpgsqlRestOptions?) returns what kind of response an endpoint gives (EndpointResponseKind: Routine, NoContent, RawText, Binary, TableFormat, Upstream, CacheInvalidation). The four generators above now use it instead of each deciding on its own, which is how they came to disagree. A custom IEndpointCreateHandler that describes responses should use it as well.
The cache invalidation endpoint of a cached endpoint now carries that endpoint's CustomParameters and Items, so a handler sees for it what it saw for the cached endpoint. A handler that registers something for each endpoint with its metadata (as the MCP plugin registers tools) should skip endpoints with InvalidateCache set.
Dependencies
Packages of the npgsqlrest client (the executable and its Docker images) were upgraded to their latest versions. The NpgsqlRest library and the plugins have no dependency changes.
| Package | Version |
|---|---|
Serilog.Sinks.OpenTelemetry | 4.2.0 → 4.3.0 |
Microsoft.Extensions.Caching.Hybrid | 11.0.0 → 11.0.1 |
For builds of the client on .NET 10: Microsoft.Extensions.Caching.Hybrid 10.7.0 → 10.11.1, Microsoft.AspNetCore.Authentication.JwtBearer and Microsoft.Extensions.Caching.StackExchangeRedis 10.0.9 → 10.0.15.
In the test project: WireMock.Net 2.31.0 → 2.35.0, and Microsoft.AspNetCore.Mvc.Testing 10.0.9 → 10.0.15 for .NET 10. The whole test suite passes on .NET 11 and on .NET 10.
NuGet Package Upgrades
| Package | Version |
|---|---|
NpgsqlRest | 4.1.0 → 4.1.1 |
NpgsqlRest.OpenApi | 1.4.0 → 1.4.1 |
NpgsqlRest.TsClient | 1.39.0 → 1.39.1 |
NpgsqlRest.DartClient | 1.2.0 → 1.2.1 |
NpgsqlRest.Mcp | 1.2.1 → 1.2.2 |
The other plugins are unchanged.