Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
someone1 opened this issue Nov 26, 2018 · 3 comments
Closed

Comments

@someone1
Copy link
Contributor

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?

@someone1
Copy link
Contributor Author

I think this can also extend to the ToJSON generated function. All variables are not added to the returned JSON and no attention is given to readOnly variables. I think switching to the allVars template variable makes sense for both functions and adding functionality for readOnly parameters can be added in the process.

@macjohnny
Copy link
Member

cc @Place1

@someone1 someone1 closed this as completed Dec 6, 2018
@Downchuck
Copy link

@someone1 Did you see this fixed? I'm seeing the same behavior in 4.0.0-beta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants