OpenAPITools / OpenAPITools/openapi-generator

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

Open
#5,671 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the typescript-fetch generator's schema type mapping and reproduce the issue using the YAML OpenAPI declaration in the report. Done means an unrestricted object, including one with additionalProperties: true, generates as any and a regression test covers the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.