Skip to content

[javascript client] constructFromObject calls undefined function constructFromObject on enums #3639

@rgarcia

Description

@rgarcia
Description

When constructing an object, the generated javascript client recursively calls constructFromObject on enum types. This method is not defined on enum types.

Swagger-codegen version

Latest master (8c2267c)

Swagger declaration file content or url
swagger: '2.0'
info:
  title: test title
  description: test description
  version: 0.1.0
schemes:
  - http
produces:
  - application/json
consumes:
  - application/json
paths:
  /foos:
    post:
      operationId: createFoo
      description: Create a new Foo
      tags:
        - Foos
      parameters:
        - name: CreateFooRequest
          in: body
          schema:
            $ref: '#/definitions/CreateFooRequest'
          required: true
      responses:
        200:
          description: OK response

definitions:
  CreateFooRequest:
    type: object
    properties:
      bar:
        $ref: '#/definitions/Bar'
  Bar:
    type: string
    enum:
      - baz1
      - baz2
      - baz3
Command line used for generation

java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i swagger.yml -l javascript -o gen-js

Steps to reproduce
  1. Run codegen against the above config.
  2. Open src/model/CreateFooRequest.js and notice this logic for constructing the enum:
      if (data.hasOwnProperty('bar')) {
        obj['bar'] = Bar.constructFromObject(data['bar']);
      }

If you open src/model/Bar.js, there is no constructFromObject method on that type.

Related issues

Didn't find any.

Suggest a Fix

Still digging...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions