-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Open
Labels
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
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: objectGeneration 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