Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6332
Closed
Open
Issue created May 16, 2020 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[bug][typescript] `AnyType` is not defined

Created by: codeserk

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

AnyType is not defined in typescript generated code. In some situations, schemas return any, this is handled in other languages where that is translated into something the language understands, examples:

  • Java: Object
  • C#: `Object
  • Rust: serde_json:Value

However, this translation is not made for typescript, and the generators write AnyType in such situations, leading to type errors:

Cannot find name 'AnyType' image

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

The part that is causing troubles look like this:

          "cat": {
            "allOf": [
              {
                "$ref": "#/components/schemas/Cat"
              },
              {
                "description": "Cat information"
              }
            ]

This was generated using @nestjs/swagger and the problem is that the generator is unable to understand the second part and that one ends in _AnyType_

This is a full example:

openapi: 3.0.1
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
servers:
  - url: http://api.example.xyz/v1
paths:
  /person/display/{personId}:
    get:
      parameters:
        - name: personId
          in: path
          required: true
          description: The id of the person to retrieve
          schema:
            type: string
      operationId: list
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Person"
components:
  schemas:
    Person:
      type: object
      discriminator:
        propertyName: $_type
        mapping:
          a: '#/components/schemas/Adult'
          c: Child
      properties:
        $_type:
          type: string
        lastName:
          type: string
        firstName:
          type: string
    Adult:
      description: A representation of an adult
      allOf:
      - $ref: '#/components/schemas/Person'
      - type: object
        properties:
          children:
            type: array
            items:
              $ref: "#/components/schemas/Child"
          firstChild:
            allOf:
              - $ref: '#/components/schemas/Person'
              - description: First child
    Child:
      description: A representation of a child
      allOf:
      - type: object
        properties:
          age:
            type: integer
            format: int32
      - $ref: '#/components/schemas/Person'

output using typescript-axios

/**
 * A representation of an adult
 * @export
 * @interface Adult
 */
export interface Adult extends Person {
    /**
     * 
     * @type {Array<Child>}
     * @memberof Adult
     */
    children?: Array<Child>;
    /**
     * 
     * @type {Person & AnyType}
     * @memberof Adult
     */
    firstChild?: Person & AnyType;
}
/**

NOTE: AnyType is not defined anywhere.

Suggest a fix

The proposal is simple, adding a translation for AnyType -> object for all the typescript generators. This can be achieved adding one line to AbstractTypeScriptCodegen.java like the ones we have in other generators:

typeMapping.put("AnyType", "Object");
Assignee
Assign to
Time tracking