Bug Report Checklist
Description
TypeScript clients do not correctly serialize a header parameter declared with Parameter.content: application/json. The required representation is one header containing JSON, using the model’s OpenAPI wire property names:
X-Json-Arg: {"file_path":"/x"}
typescript-fetch: the generated header assignment uses the ordinary string path:
headerParameters['X-Json-Arg'] = String(requestParameters['xJsonArg']);
For an object this produces [object Object]. Even direct JSON.stringify of a generated model with filePath: "/x" would produce {"filePath":"/x"}; the generator’s existing model-to-wire conversion is needed to produce file_path.
typescript-node: the generated assignment passes the serialized model object as the header value without converting it to a JSON string:
localVarHeaderParams['X-Json-Arg'] = ObjectSerializer.serialize(xJsonArg, "HeaderArg");
The same problem applies to a present optional JSON-content header and to application/vnd.example+json. An ordinary schema-based string header should retain its current behavior.
typescript-axios was also checked. Its generated model uses the wire member name file_path, and its header path already uses JSON.stringify; this reproduction did not show the bug there.
openapi-generator version
7.26.0-SNAPSHOT, reproduced from master commit 271e4dd6e6d03ee456d8acef6542617371ef827c.
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: JSON header serialization
version: 1.0.0
paths:
/json:
get:
operationId: getJson
parameters:
- name: X-Json-Arg
in: header
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/HeaderArg'
- name: X-Optional-Json-Arg
in: header
content:
application/json:
schema:
$ref: '#/components/schemas/HeaderArg'
- name: X-Plain-Arg
in: header
required: true
schema:
type: string
responses:
'204':
description: No content
/vendor:
get:
operationId: getVendor
parameters:
- name: X-Vendor-Arg
in: header
required: true
content:
application/vnd.example+json:
schema:
$ref: '#/components/schemas/HeaderArg'
responses:
'204':
description: No content
components:
schemas:
HeaderArg:
type: object
properties:
file_path:
type: string
Generation Details
Generate clients from the YAML above with the default options for typescript-fetch and typescript-node, for example:
openapi-generator-cli generate -i json-header.yaml -g typescript-fetch -o /tmp/json-header-fetch
openapi-generator-cli generate -i json-header.yaml -g typescript-node -o /tmp/json-header-node
Steps to reproduce
- Generate either client from the specification above.
- Call
getJson with X-Json-Arg represented by a generated model value equivalent to { filePath: "/x" } and X-Plain-Arg set to "plain". Optionally provide the same model value for X-Optional-Json-Arg.
- Inspect the outgoing headers or the generated assignments shown above. Also call
getVendor with the same model value.
Expected: exactly one X-Json-Arg header with the value {"file_path":"/x"}. The present optional and vendor JSON headers should have the same JSON value under their declared names. X-Plain-Arg should remain plain.
Actual: typescript-fetch stringifies the object as [object Object]; typescript-node assigns a serialized object as the header value rather than a JSON string.
Related issues/PRs
The same OpenAPI parameter serialization problem has been reported for other client generators:
Suggest a fix
Use the common CodegenParameter.headerIsJsonMimeType metadata populated by DefaultCodegen to identify JSON-content headers, including application/json and JSON structured-suffix media types such as application/vnd.example+json.
For affected TypeScript clients, serialize using their existing model-to-wire paths before forming the JSON header string: typescript-fetch should apply its model ToJSON conversion before JSON.stringify; typescript-node should apply ObjectSerializer.serialize before JSON.stringify. Preserve ordinary schema-based header handling.
Bug Report Checklist
Description
TypeScript clients do not correctly serialize a header parameter declared with
Parameter.content: application/json. The required representation is one header containing JSON, using the model’s OpenAPI wire property names:X-Json-Arg: {"file_path":"/x"}typescript-fetch: the generated header assignment uses the ordinary string path:For an object this produces
[object Object]. Even directJSON.stringifyof a generated model withfilePath: "/x"would produce{"filePath":"/x"}; the generator’s existing model-to-wire conversion is needed to producefile_path.typescript-node: the generated assignment passes the serialized model object as the header value without converting it to a JSON string:The same problem applies to a present optional JSON-content header and to
application/vnd.example+json. An ordinary schema-based string header should retain its current behavior.typescript-axioswas also checked. Its generated model uses the wire member namefile_path, and its header path already usesJSON.stringify; this reproduction did not show the bug there.openapi-generator version
7.26.0-SNAPSHOT, reproduced from master commit271e4dd6e6d03ee456d8acef6542617371ef827c.OpenAPI declaration file content or url
Generation Details
Generate clients from the YAML above with the default options for
typescript-fetchandtypescript-node, for example:Steps to reproduce
getJsonwithX-Json-Argrepresented by a generated model value equivalent to{ filePath: "/x" }andX-Plain-Argset to"plain". Optionally provide the same model value forX-Optional-Json-Arg.getVendorwith the same model value.Expected: exactly one
X-Json-Argheader with the value{"file_path":"/x"}. The present optional and vendor JSON headers should have the same JSON value under their declared names.X-Plain-Argshould remainplain.Actual:
typescript-fetchstringifies the object as[object Object];typescript-nodeassigns a serialized object as the header value rather than a JSON string.Related issues/PRs
The same OpenAPI parameter serialization problem has been reported for other client generators:
Suggest a fix
Use the common
CodegenParameter.headerIsJsonMimeTypemetadata populated byDefaultCodegento identify JSON-content headers, includingapplication/jsonand JSON structured-suffix media types such asapplication/vnd.example+json.For affected TypeScript clients, serialize using their existing model-to-wire paths before forming the JSON header string:
typescript-fetchshould apply its modelToJSONconversion beforeJSON.stringify;typescript-nodeshould applyObjectSerializer.serializebeforeJSON.stringify. Preserve ordinary schema-based header handling.