[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
- Use the provided yaml excerpt above to generate a client with the provided command line
- 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?