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
  • #1563
Closed
Open
Issue created Nov 28, 2018 by Administrator@rootContributor

[typescript-fetch] (4.0.X) unioned types incorrectly deserialized

Created by: someone1

Description

The generated deserializer for unioned types incorrectly inlines the unioned types

openapi-generator version

openapi-generator-cli-4.0.0-20181126.024631-44

OpenAPI declaration file content or url
swagger: "2.0"
info:
  title: "Simple Test"

paths:
  "/get/Simple":
    get:
      summary: Retrieve List of Simple
      operationId: "get.Simple"
      responses:
        200:
          description: OK
          schema:
            allOf:
              - type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: "#/definitions/Simple"
              - $ref: "#/definitions/Paging"
definitions:         
  Simple:
    type: object
    required:
      - Name
    properties:
      Date:
        type: string
        format: date
  Paging:
    properties:
      more:
        type: boolean
      cursor:
        type: string

Generated Code (excerpt):

export interface InlineResponse200 {
    /**
     * 
     * @type {Paging}
     * @memberof InlineResponse200
     */
    paging?: Paging;
    /**
     * 
     * @type {Array<Simple>}
     * @memberof InlineResponse200
     */
    items?: Array<Simple>;
}

export function InlineResponse200FromJSON(json: any): InlineResponse200 {
    return {
        'paging': !exists(json, 'Paging') ? undefined : PagingFromJSON(json['Paging']),
        'items': !exists(json, 'items') ? undefined : (json['items'] as Array<any>).map(SimpleFromJSON),
    };
}

Example response (notice no "Paging" key):

{
  "items": [
    {
      "Date": "2018-11-27"
    }
  ],
  "more": true,
  "cursor": "string"
}
Command line used for generation

openapi-generator generate -i openapi.yaml -l typescript-fetch -c es6.json -o ./typescript-api/

Steps to reproduce
  1. Use the provided yaml excerpt above to generate a client with the provided command line
  2. Buggy code generated
Related issues/PRs

PR #569

Suggest a fix/enhancement

Not sure - the debugModels output makes it look like the generated code is accurate, there is something automatically creating a nested key for the composed model which should have its properties extend the model as it is not named.

Any ideas on how to tackle this? It almost appears as if the models passed to the template is incorrect (adding a named var Paging instead of its properties).

cc @Place1

Assignee
Assign to
Time tracking