Openapi-generator: [BUG] [typescript-angular] Upgrade from 3.3.4 to 4.1.2 breaks any type functionality.

Created on 21 Oct 2019  路  4Comments  路  Source: OpenAPITools/openapi-generator

Description

Upgrading code generator from 3.3.4 to 4.1.2 doesn't allow for any as a type.
This functionality seems to be broken since this PR: https://github.com/OpenAPITools/openapi-generator/pull/2453

While I understand the need for this change, it is an inconsistency in some environments, take for example a server in Spring, where Object can be anything but a primitive, and a client in TypeScript where object can only be { }, and not a string of number.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: Test
  description: Test
  version: 0.0.0
servers:
  - url: http://localhost:8080/api/
paths:
  /example:
    post:
      operationId: filter example
      requestBody:
        description: One filter item
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FilterDTO'  
      responses:
        "200":
          description: "Success"

components:
  schemas:
    FilterDTO:
      properties:
        attribute:
          type: string
        value:
          type: object
Command line used for generation

npx openapi-generator generate -i spec.yml -g typescript-angular -o output

Steps to reproduce

Generate the code, and observe how value is of type object and not any.
I was using this in order to be able to pass any value to this field.

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/2453

Suggest a fix

What I suggest is to offer an option to generate a property of type any, maybe using a config option allowAny = true or something similar.

TypeScript Bug

Most helpful comment

What about using --type-mappings to map "object" back to "any"?

e.g. --type-mappings object=any

All 4 comments

馃憤 Thanks for opening this issue!
馃彿 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

What about using --type-mappings to map "object" back to "any"?

e.g. --type-mappings object=any

Hi @wing328, thanks a lot for the quick reply, it seems to do the trick for me. Is this documented somewhere for future reference?

Please refer to https://openapi-generator.tech/docs/usage or the project's readme.

Was this page helpful?
0 / 5 - 0 ratings