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
  • #2739
Closed
Open
Issue created Apr 25, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[BUG] [typescript-fetch] (v4.0.0) Generated models no longer produce valid to/from JSON functions - can't compile

Created by: someone1

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

I've been using a nightly snapshot from early December (shortly after my last PR) to generate my typescript client. I decided to try out the latest beta and am happy with some of the changes/fixes (great job)! However, there seems to have been a change with how models are computed/generated, models that "extend" another model (e.g. allOf with a $ref) no longer seem to be generated as such. Additionally, the change I previously put in to use allVars vs vars seems to be breaking things now whereas before it was necessary.

openapi-generator version

I'm testing via the latest version shipped with the npm package: 4.0.0-beta3 The old version that was working as expected:: 4.0.0-SNAPSHOT (20181206.114535-69)

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:
            $ref: '#/definitions/ModelFull'

definitions:
  ModelPartial:
    type: object
    required:
      - id
    properties:
      id:
        type: string
      name:
        type: string
  ModelFull:
    allOf:
      - $ref: '#/definitions/ModelPartial'
      - properties:
          creationDate:
            type: string
            format: date-time
            readOnly: true

Generated Code (notice the missing inherited fields including the required field id in ModelFullFromJSON):

/**
 * 
 * @export
 * @interface ModelFull
 */
export interface ModelFull {
    /**
     * 
     * @type {string}
     * @memberof ModelFull
     */
    id: string;
    /**
     * 
     * @type {string}
     * @memberof ModelFull
     */
    name?: string;
    /**
     * 
     * @type {Date}
     * @memberof ModelFull
     */
    readonly creationDate?: Date;
}

export function ModelFullFromJSON(json: any): ModelFull {
    return {
        'creationDate': !exists(json, 'creationDate') ? undefined : new Date(json['creationDate']),
    };
}

Generated code from older generator (notice ModelFull extends ModelPartial and includes all required fields in ModelFullFromJSON):

/**
 * 
 * @export
 * @interface ModelFull
 */
export interface ModelFull extends ModelPartial {
    /**
     * 
     * @type {Date}
     * @memberof ModelFull
     */
    readonly creationDate?: Date;
}

export function ModelFullFromJSON(json: any): ModelFull {
    return {
        'id': json['id'],
        'name': !exists(json, 'name') ? undefined : json['name'],
        'creationDate': !exists(json, 'creationDate') ? undefined : new Date(json['creationDate']),
    };
}

export function ModelFullToJSON(value?: ModelFull): any {
    if (value === undefined) {
        return undefined;
    }
    return {
        'id': value.id,
        'name': value.name,
    };
}

ModelPartial:

/**
 * 
 * @export
 * @interface ModelPartial
 */
export interface ModelPartial {
    /**
     * 
     * @type {string}
     * @memberof ModelPartial
     */
    id: string;
    /**
     * 
     * @type {string}
     * @memberof ModelPartial
     */
    name?: string;
}
Command line used for generation

openapi-generator generate -i test.yaml -g typescript-fetch -o ./test-api

Steps to reproduce

Generate the code from the example yaml and command line I provided.

Related issues/PRs
Suggest a fix

I'm not aware of what happened in the backend for the "parent" attribute to be dropped when generating models and for the allVars not to include everything as it did in the past. If this is truly preferred then I think the allVars can be switched back to vars when generating the *FromJSON functions.

Please let me know if this was intentional and I can try and put in a PR accordingly.

Assignee
Assign to
Time tracking