Skip to content

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

Description

@stephanpelikan
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}}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions