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.2) serialize/deserialize return value is any empty object by using allOf #3281

Closed
kay-schecker opened this issue Jul 4, 2019 · 2 comments

Comments

@kay-schecker
Copy link
Contributor

This issue is similar to #1547.
If I use the following spec file:

openapi-generator version: 4.0.2
generator: typescript-fetch

Sample Spec:

openapi: 3.0.2

info:
  title: AllOf SampleAPI
  version: 1

components:
  schemas:
    addressObject:
      description: Object containing address information.
      properties:
        city:
          example: Munich
          type: string
        country_code:
          example: DE
          type: string
        house_number:
          example: 5a
          type: string
        street:
          example: Sternstraße
          type: string
        zip:
          example: '80538'
          type: string
      required:
        - zip
        - country_code
        - city
      type: object
    shippingAddressObject:
      description: Object containing shipping address information.
      allOf:
        - $ref: '#/components/schemas/addressObject'
        - type: object
          properties:
            address_line_1:
              example: Max Mustermann
              type: string
            address_line_2:
              example: 5th floor
              type: string
          required:
            - address_line_1
paths:
  '/order':
    post:
      operationId: placeOrder
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/shippingAddressObject'
      responses:
        '200':
          description: "Hello Order"
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/shippingAddressObject'

The generator create a model, where the serialize/deserialize functions return an empty object:

export function ShippingAddressObjectFromJSON(json: any): ShippingAddressObject {
    return {
    };
}

export function ShippingAddressObjectToJSON(value?: ShippingAddressObject): any {
    if (value === undefined) {
        return undefined;
    }
    return {
    };
}

As i can see in the git history there was a change in the file called "modelGeneric.mustache" to use allVars instead of vars. It looks like that the allVars array seems to be empty in that case :/ If I revert that change locally back to use vars the code is generated well:

export function ShippingAddressObjectFromJSON(json: any): ShippingAddressObject {
    return {
        'city': json['city'],
        'countryCode': json['country_code'],
        'houseNumber': !exists(json, 'house_number') ? undefined : json['house_number'],
        'street': !exists(json, 'street') ? undefined : json['street'],
        'zip': json['zip'],
        'addressLine1': json['address_line_1'],
        'addressLine2': !exists(json, 'address_line_2') ? undefined : json['address_line_2'],
    };
}

export function ShippingAddressObjectToJSON(value?: ShippingAddressObject): any {
    if (value === undefined) {
        return undefined;
    }
    return {
        'city': value.city,
        'country_code': value.countryCode,
        'house_number': value.houseNumber,
        'street': value.street,
        'zip': value.zip,
        'address_line_1': value.addressLine1,
        'address_line_2': value.addressLine2,
    };
}
@auto-labeler
Copy link

auto-labeler bot commented Jul 4, 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.

@wing328
Copy link
Member

wing328 commented Jul 5, 2019

Fixed with #2899.

I'll work on fixing allVars later (probably after the Japan OpenSummit 2019)

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

No branches or pull requests

2 participants