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

[typescript-fetch] (4.0.X) Missing required parameter in <Model>FromJSON

Created by: someone1

Description

When there is a composition of multiple models, the generated typescript code does not add the required parameters of the extended type in the generated FromJSON function.

openapi-generator version

openapi-generator-cli-4.0.0-20181126.024631-44

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

paths:
  "/get/Combined":
    get:
      summary: Retrieve List of Combined
      operationId: "get.Combined"
      responses:
        200:
          description: OK
          schema:
            $ref: "#/definitions/Combined"

definitions:         
  Simple:
    type: object
    required:
      - Name
    properties:
      Name:
        type: string
  Combined:
    allOf:
      - $ref: "#/definitions/Simple"
      - type: object
        properties:
          Occupation:
            type: string

Generated Code (excerpt):

export interface Simple {
    /**
     * 
     * @type {string}
     * @memberof Simple
     */
    name: string;
}

export interface Combined extends Simple {
    /**
     * 
     * @type {string}
     * @memberof Combined
     */
    occupation?: string;
}

export function CombinedFromJSON(json: any): Combined {
    return {
        'occupation': !exists(json, 'Occupation') ? undefined : json['Occupation'],
    };
}

Compiler throws an error since its missing the required name parameter

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 - any suggestions on how to tackle this would be appreciated and I can add it to PR #1545

Looking at the debugModels export for the provided yaml definition, it seems that parentVars is an empty list for model Combined which could have been used to add additional required params to the function. Alternatively, the allVars template variable could be used over the vars variable in this block as it contains all potential params?

Assignee
Assign to
Time tracking