Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #100
Closed
Open
Issue created May 18, 2018 by Administrator@rootContributor

[Typescript-Node] Incorrect serialization of subclasses in generated code

Created by: gbrown-ce

Description

When using a generated client, serialization only looks at the referenced type when serializing properties of the object. If you are using inheritance, you will lose properties of the subclasses when you serialize.

Openapi-codegen version

3.0.0

Swagger declaration file content or url
swagger: "2.0"
info:
  version: "1.0.0"
  title: Price Lists Service
# during dev, should point to your local machine
host: localhost:10010
# basePath prefixes all resource paths 
basePath: /
# 
schemes:
  # tip: remove http to make production-grade
  - http
# format of bodies a client can send (Content-Type)
consumes:
  - application/json
# format of the responses to the client (Accepts)
produces:
  - application/json
paths:
  /pricelists/{priceListId}/pricepoints/{pricePointId}:
    x-swagger-router-controller: pricePoints
    put:
      description: Updates a price point
      operationId: updatePricePoint
      parameters:
        - name: priceListId
          in: path
          description: Unique id of the price list to retrieve
          required: true
          type: integer
          format: int64
          minimum: 0
        - name: pricePointId
          in: path
          description: Unique id of the price point to update
          required: true
          type: integer
          format: int64
          minimum: 0
        - name: pricePoint
          in: body
          description: Price point to update
          required: true
          schema:
            $ref: "#/definitions/UpdatePricePointRequest"
      responses:
        200:
          description: Success
          schema:
            $ref: "#/definitions/PricePoint"
        400:
          description: Bad Request
          schema:
            $ref: "#/definitions/BadRequestResponse"
        404:
          description: Not Found
          schema:
            $ref: "#/definitions/NotFoundResponse"
        409:
          description: Conflict
          schema:
            $ref: "#/definitions/ConflictResponse"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
      description: Deletes a price point
      operationId: deletePricePoint
      parameters:
      - name: priceListId
        in: path
        description: Unique id of the price list
        required: true
        type: integer
        format: int64
        minimum: 0
      - name: pricePointId
        in: path
        description: Unique id of the price point to delete
        required: true
        type: integer
        format: int64
        minimum: 0
      responses:
        204:
          description: Success
          schema:
            type: string
        400:
          description: Bad Request
          schema:
            $ref: "#/definitions/BadRequestResponse"
        404:
          description: Not Found
          schema:
            $ref: "#/definitions/NotFoundResponse"
        default:
          description: Error
          schema:
            $ref: "#/definitions/ErrorResponse"
  /swagger:
    x-swagger-pipe: swagger_raw
# complex objects have schema definitions
definitions:
    type: object
    properties:
      restrictions:
        $ref: "#/definitions/PricePointRestrictions"
  PricePointRestrictions:
    type: array
    items:
      $ref: "#/definitions/PricePointRestriction"
  PricePointRestriction:
    type: object
    discriminator: restrictionType
    required:
      - restrictionType
    properties:
      restrictionType:
        type: string
        enum:
        - EntityRestriction
  EntityRestriction:
    type: object
    allOf:
      - $ref: "#/definitions/PricePointRestriction"
      - required:
          - entityId
          - entityType
        properties:
          entityId:
            type: string
          entityType:
            type: string
            format: string
            enum:
            - sku
      type: object
    required:
    - entityId
    - entityType
    - price
    properties:
      entityId:
        type: string
      entityType:
        type: string
        format: string
        enum:
        - product
      price:
        type: number
        format: double
        minimum: 0.00
  PricePoint:
    type: object
    required:
    - id
    - entryId
    - pricePointType
    - restrictions
    - price
    properties:
      id:
        type: integer
        format: int64
        minimum: 0
      entryId:
        type: integer
        format: int64
        minimum: 0
      pricePointType:
        type: string
        format: string
        enum:
        - addition
        - override
      restrictions:
        type: array
        items:
          $ref: "#/definitions/PricePointRestriction"
      price:
        type: number
        format: double
        minimum: 0.00
    type: object
    required:
      - pricePointType
      - restrictions
      - price
    properties:
      pricePointType:
        type: string
        format: string
        enum:
        - addition
        - override
      restrictions:
        type: array
        minItems: 1
        items:
          $ref: "#/definitions/PricePointRestriction"
      price:
        type: number
        format: double
        minimum: 0.00
  UpdatePricePointRequest:
    type: object
    required:
      - pricePointType
      - restrictions
      - price
    properties:
      pricePointType:
        type: string
        format: string
        enum:
        - addition
        - override
      restrictions:
        type: array
        minItems: 1
        items:
          $ref: "#/definitions/PricePointRestriction"
      price:
        type: number
        format: double
        minimum: 0.00
  BadRequestResponse:
    type: object
    required:
    - errorCode
    - messages
    properties:
      errorCode:
        type: string
        example: "400.5.2.0"
      messages:
        type: array
        items:
          type: string
        example:
        - Message here about why the request is invalid
        - Another message here about why the request is invalid
  ConflictResponse:
    type: object
    required:
    - errorCode
    - messages
    properties:
      errorCode:
        type: string
        example: "409.5.2.0"
      messages:
        type: array
        items:
          type: string
        example:
        - Name 'EntryType' is already in use
  ErrorResponse:
    type: object
    required:
    - errorCode
    - messages
    properties:
      errorCode:
        type: string
        example: "500.5.2.0"
      messages:
        type: array
        items:
          type: string
        example:
        - "Something went wrong"
  NotFoundResponse:
    type: object
    required:
    - errorCode
    - messages
    properties:
      errorCode:
        type: string
        example: "404.5.2.0"
      messages:
        type: array
        items:
          type: string
        example:
        - Not Found
  ServiceUnavailableResponse:
    type: object
    required:
      - errorCode
      - messages
    properties:
      errorCode:
        type: string
        example: "503.5.2.0"
      messages:
        type: array
        items:
          type: string
        example:
        - Service is currently unavailable
Command line used for generation

java -jar .\openapi-generator-cli.jar generate -i /path/to/swagger.yaml -l typescript-node -o /path/to/target/directory

Steps to reproduce

With the generated code, run the following:

import { 
    DefaultApi, UpdatePricePointRequest, PricePointRestriction, EntityRestriction 
} from "/path/to/target/directory";

var api:DefaultApi = new DefaultApi();
var updatePricePointRequest: UpdatePricePointRequest = new UpdatePricePointRequest();
updatePricePointRequest.price = 0
updatePricePointRequest.pricePointType = UpdatePricePointRequest.PricePointTypeEnum.Override;
updatePricePointRequest.restrictions = [
    {
       restrictionType: PricePointRestriction.RestrictionTypeEnum.EntityRestriction,
       entityId: 'Success',
       entityType: EntityRestriction.EntityTypeEnum.Sku
    }
];
api.updatePricePoint(0, 0, updatePricePointRequest);

If you step into the updatePricePoint call to where it goes to serialize the list of restrictions, you'll notice that entityId and entityType get left off the serialized object, so that when it is sent onto the server, it is invalid.

Assignee
Assign to
Time tracking