Bug Report Checklist
Description
Support for generics in TypeScript generated libraries was added in #21414 after being reported as a bug in #21317; this bug report is a follow-up to that implementation.
When using Record<string, unknown> as a mapped type in the configuration and an API returns object as its schema, it incorrectly generates the FromJSON function to use that generic.
// These imports should not exist since `Record` is a built-in type
import type {
Recordstringunknown,
} from '../models/index';
import {
RecordstringunknownFromJSON,
RecordstringunknownToJSON,
} from '../models/index';
// Return type should be `Record<string, unknown>` to match `config.yml`
async usersGetRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Recordstringunknown>> {
const queryParameters: any = {};
const headerParameters: runtime.HTTPHeaders = {};
const response = await this.request({
path: `/users`,
method: 'GET',
headers: headerParameters,
query: queryParameters,
}, initOverrides);
// This should be changed to not use a `FromJSON` maybe?
return new runtime.JSONApiResponse(response, (jsonValue) => RecordstringunknownFromJSON(jsonValue));
}
/cc @macjohnny for visibility since they made the original PR to fix the original bug
openapi-generator version
7.17.0
OpenAPI declaration file content or url
openapi: 3.1.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 1.0.0
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
paths:
/users:
get:
summary: Returns a list of users.
description: Optional extended description in CommonMark or HTML.
responses:
"200": # status code
description: A JSON array of user names
content:
application/json:
schema:
type: object
Generation Details
# config.yml
typeMappings:
object: Record<string,unknown>
Steps to reproduce
docker run --rm \
-v ".:/local" \
openapitools/openapi-generator-cli:latest generate \
-c "/local/config.yml" \
-g "typescript-fetch" \
-i "/local/openapi.yml" \
-o /local/src
Related issues/PRs
Related to #21317 and #21414
Suggest a fix
Bug Report Checklist
Description
Support for generics in TypeScript generated libraries was added in #21414 after being reported as a bug in #21317; this bug report is a follow-up to that implementation.
When using
Record<string, unknown>as a mapped type in the configuration and an API returnsobjectas its schema, it incorrectly generates theFromJSONfunction to use that generic./cc @macjohnny for visibility since they made the original PR to fix the original bug
openapi-generator version
7.17.0
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Related to #21317 and #21414
Suggest a fix