Skip to content

[BUG][typescript-fetch] Objects as FormParams generate invalid code (missing type before ToJSON) #21670

@madpah

Description

@madpah

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

Invalid Typescript code is generated for Form Data Parameters that have an Object Type.

openapi-generator version

OpenAPI Generator Version 7.14.0

OpenAPI declaration file content or url

Example OpenAPI spec portion for path that reproduces this issue:

   put:
      description: A description
      operationId: doOperation
      requestBody:
        content:
          multipart/form-data:
            schema:
              properties:
                stringProp:
                  description: This is our string
                  type: string
                samlConfiguration:
                  $ref: '#/components/schemas/ANOtherObject'
              type: object
Generation Details

Generating code using:

 java -jar openapi-generator-cli.jar generate -g typescript-fetch -i openapi.yaml

The generated API TS files has this line:

if (requestParameters['samlConfiguration'] != null) {
            formParams.append('samlConfiguration', new Blob([JSON.stringify(ToJSON(requestParameters['samlConfiguration']))], { type: "application/json", }));
                    }

Which fails to compile as ToJSON should be ApiSamlConfigurationDTOToJSON.

Suggest a fix

I will supply a PR shortly to address this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions