Skip to content

[Typescript-Axios] Api outputs incorrect serialization type check #4050

@JMontagu

Description

@JMontagu
Description

The typescript-axios generator outputs an incorrect type check for serialization.

Current output:

const needsSerialization = (<any>"Pet" !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';

Expected output:

const needsSerialization = (typeof body !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';

The issue is <any>"Pet" !== "string" will always evaluate to true, as it's comparing a string value to a string value.

What the correct logic should be is: typeof body !== "string", which checks the body object is not a string in order to run serialization.

openapi-generator version

4.1.2

OpenAPI declaration file content or url
Command line used for generation
Steps to reproduce

Generate any api output using the typescript-axios generator.

Related issues/PRs

N/A

Suggest a fix/enhancement

In src/main/resources/typescript-axios/apiInner.mustache, replace

const needsSerialization = (<any>"{{dataType}}" !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';

With:

const needsSerialization = (typeof {{paramName}} !== "string") || localVarRequestOptions.headers['Content-Type'] === 'application/json';

This also matches the current flow generator template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions