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

[BUG] [typescript-fetch] serialize/deserialze not working with inheritence #3646

Closed
stephanpelikan opened this issue Aug 15, 2019 · 7 comments · Fixed by #3767
Closed

[BUG] [typescript-fetch] serialize/deserialze not working with inheritence #3646

stephanpelikan opened this issue Aug 15, 2019 · 7 comments · Fixed by #3767

Comments

@stephanpelikan
Copy link
Contributor

Description

Properties of super-classes are not serialized/deserialized.

openapi-generator version

4.1.0

OpenAPI declaration file content or url
components:
  schemas:
    Type:
      type: string
      enum:
      - B
    A:
      type: object
      discriminator:
        propertyName: type
      required:
      - type
      properties:
        whatever-a:
          type: string
        type:
          $ref: "#/components/schemas/Type"
    B:
      allOf:
        - $ref: "#/components/schemas/A"
        - type: object
          discriminator:
            propertyName: type
          properties:
            whatever-b:
              type: string
Suggest a fix

in modelGeneric.mustache add the lines with comment:

export function {{classname}}FromJSON(json: any): {{classname}} {
    {{#hasVars}}
    return {
        {{#parent}}...{{{parent}}}FromJSON(json),{{/parent}}  // deserialize inherited properties as well
        {{#additionalPropertiesType}}
            ...json,
        {{/additionalPropertiesType}}

and

export function {{classname}}ToJSON(value?: {{classname}}): any {
    {{#hasVars}}
    if (value === undefined) {
        return undefined;
    }
    return {
        {{#parent}}...{{{parent}}}ToJSON(value),{{/parent}}     // serialize inherited properties as well
        {{#additionalPropertiesType}}
            ...value,
        {{/additionalPropertiesType}}
@auto-labeler
Copy link

auto-labeler bot commented Aug 15, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@denyo
Copy link
Contributor

denyo commented Aug 15, 2019

May be related to #2845.

@stephanpelikan
Copy link
Contributor Author

Maybe. But I tested the fix I suggested and it works. It simply seems to be forgotten.

@stephanpelikan
Copy link
Contributor Author

stephanpelikan commented Aug 15, 2019

Concerning #2845: I suffured this bug in Java-Service with 4.0.0. In this situation the template was ok but the parent-value seems not to be filled. With 4.1.0 and typescript-fetch the parent-value is filled, but the template is not ok :-|

@macjohnny
Copy link
Member

@stephanpelikan can you open an PR?

@stephanpelikan
Copy link
Contributor Author

@macjohnny PR created

macjohnny pushed a commit that referenced this issue Aug 28, 2019
…#3767)

* #3646 - fix inheritence

* #3646: Fix imports

* Update modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache

Co-Authored-By: Esteban Gehring <esteban.gehring@gmail.com>

* generate typeescript-fetch samples
@rcarton
Copy link
Contributor

rcarton commented Sep 12, 2019

There's a bug when there's more than one model inheriting from the base class. In your example, if you have both a B and a C inheriting A's property, the template does not generate valid typescript.

import {
     BJSONTyped<missing comma>
     CJSONTyped
} from './';

It's a quick fix, I'll push a PR
edit: PR: #3881

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

Successfully merging a pull request may close this issue.

4 participants