Open
Description
Same as #6192, but affecting the new typescript generator from #6341 instead of typescript-fetch. Updated description, error messages and repro below.
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used? 4.3.1
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
When an item of an array of a map is specified through a referenced schema, the model type for the item is not imported into DefaultApi.ts
.
For example, for an endpoint specification of:
"/characters":
get:
responses:
"200":
content:
application/json:
schema:
additionalProperties:
type: array
items:
$ref: "#/components/schemas/Character"
And a schema specification of:
Character:
required: ["first", "name"]
properties:
id:
type: integer
name:
type: string
Compiling results in the following error:
Failed to compile.
/tmp/test-openapigen/src/api/apis/DefaultApi.ts
TypeScript error in /tmp/test-openapigen/src/api/apis/DefaultApi.ts(54,92):
Cannot find name 'Character'. TS2304
52 | * @throws ApiException if the response code was not in [200, 299]
53 | */
> 54 | public async charactersGet(response: ResponseContext): Promise<{ [key: string]: Array<Character>; } > {
| ^
55 | const contentType = ObjectSerializer.normalizeMediaType(response.headers["content-type"]);
56 | if (isCodeInRange("200", response.httpStatusCode)) {
57 | const body: { [key: string]: Array<Character>; } = ObjectSerializer.deserialize(
openapi-generator version
5.0.0-SNAPSHOT
OpenAPI declaration file content or url
https://github.com/bard/openapi-generator-missing-type-2/blob/master/example.yaml
Command line used for generation
OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT /tmp/openapi-generator-cli.sh generate -g typescript -i example.yaml -o ./src/api
Steps to reproduce
- Clone https://github.com/bard/openapi-generator-missing-type-2
- Run
OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT /tmp/openapi-generator-cli.sh generate -g typescript -i example.yaml -o ./src/api
- Run
yarn && yarn start
Related issues/PRs
#5995 seems to solve a similar issue
Suggest a fix
Import the missing type into DefaultApi.ts
:
// TODO: better import syntax?
import { BaseAPIRequestFactory, RequiredError } from './baseapi';
import {Configuration} from '../configuration';
import { RequestContext, HttpMethod, ResponseContext, HttpFile} from '../http/http';
import {ObjectSerializer} from '../models/ObjectSerializer';
import {ApiException} from './exception';
import {isCodeInRange} from '../util';
+ import {Character} from '../models/Character'
/**
* no description
*/
export class DefaultApiRequestFactory extends BaseAPIRequestFactory {