Description
When generating transformers for nested objects from a JSON schema, the @hey-api/transformers plugin uses the same parameter name key for all levels of the object's nesting depth.
This creates code that does not ts compile, such as:
const myNestedObjectSchemaResponseTransformer = (data: any) => {
if (data.property) {
for (const key of Object.keys(data.property) {
for (const key of Object.keys(data.property[key])) {
data.property[key][key] = myValueSchemaResponseTransformer(data.property[key][key]);
}
}
}
return data;
};
src/.gen/transformers.gen.ts:4:24 - error TS7022: 'key' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
4 for (const key of Object.keys(data.property[key])) {
~~~
src/.gen/transformers.gen.ts:4:57 - error TS2448: Block-scoped variable 'key' used before its declaration.
4 for (const key of Object.keys(data.property[key])) {
~~~
Reproducible example or configuration
Config:
{
input: spec as unknown as string,
output: {
path: './src/.gen',
importFileExtension: '.ts',
},
plugins: [
// Adds generated schemas,
// validation is enabled/disabled via `validator` below
// https://heyapi.dev/openapi-ts/plugins/zod
'zod',
{
name: '@hey-api/sdk',
operations: {strategy: 'flat'},
// https://heyapi.dev/openapi-ts/plugins/sdk#validators
// see link to zod plugin above
validator: false,
},
'@hey-api/client-fetch',
'@hey-api/transformers',
],
}
OpenAPI specification (optional)
{
"paths": {
"/it": {
"get": {
"tags": [
"Status"
],
"summary": "Dummy route",
"description": "Dummy route",
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UserBestResultForContentIdSnapshot"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"UserBestResultForContentIdSnapshot": {
"type": "object",
"title": "projection.aggregates.UserBestResultForContentIdSnapshot",
"properties": {
"content_ids": {
"type": "object",
"additionalProperties": {
"type": "object",
"additionalProperties": {
"leaf": {
"type": "string"
}
}
}
}
}
}
}
}
}
System information (optional)
No response
Description
When generating transformers for nested objects from a JSON schema, the
@hey-api/transformersplugin uses the same parameter namekeyfor all levels of the object's nesting depth.This creates code that does not ts compile, such as:
Reproducible example or configuration
Config:
OpenAPI specification (optional)
{ "paths": { "/it": { "get": { "tags": [ "Status" ], "summary": "Dummy route", "description": "Dummy route", "responses": { "200": { "description": "OK", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/UserBestResultForContentIdSnapshot" } } } } } } } }, "components": { "schemas": { "UserBestResultForContentIdSnapshot": { "type": "object", "title": "projection.aggregates.UserBestResultForContentIdSnapshot", "properties": { "content_ids": { "type": "object", "additionalProperties": { "type": "object", "additionalProperties": { "leaf": { "type": "string" } } } } } } } } }System information (optional)
No response