OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.56k stars 6.52k forks source link

[BUG] [typescript-fetch] object types should not be marked as object types in typescript #5671

Open samuelallan72 opened 4 years ago

samuelallan72 commented 4 years ago

Bug Report Checklist

Description

Given a property that is labeled as type: object in the openapi spec, and no extra restrictions, the typescript generator produces a parameter with type signature object. In the openapi spec, object with no extra restrictions/parameters, or with additionalProperties: true set, denotes any valid object with any extra properties. This should be declared in typescript as the any type.

This is an issue because now it's impossible to reference a key from the object type in typescript. For example, this used to be (and should be) valid: profile.name.first_name given the schema below. Now, tsc raises an error because first_name isn't a property of an object.

openapi-generator version

4.2.3

Previous versions set type to any. Not sure which versions; 4.0.0-beta3 is known to have worked.

OpenAPI declaration file content or url
swagger: '2.0'
info:
  title: test
  version: v1
basePath: /api/v1
consumes:
  - application/json
produces:
  - application/json
paths:
  /users/profile:
    get:
      operationId: user_profile
      description: Get my profile
      parameters: []
      responses:
        '200':
          description: ''
          schema:
            $ref: '#/definitions/Profile'
definitions:
  Profile:
    type: object
    properties:
      name:
        title: Name
        type: object
Command line used for generation
Steps to reproduce
Related issues/PRs
Suggest a fix

Set type to any for typescript values set from an openapi spec object field.

amakhrov commented 4 years ago

Probably a duplicate of https://github.com/OpenAPITools/openapi-generator/issues/5279

@swalladge would you be willing to make a PR with the proposed change (making this mapping a default behavior)?

samuelallan72 commented 4 years ago

@amakhrov Sorry, I won't have time to work on this.