swagger-api / swagger-api/swagger-codegen

[JAVASCRIPT]- Bug with js client code generation: Allof and Enum Inheritance

Open
#11,984 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description
  • when i try to generate a javascript client from a YAML that has this schemas format
  1. an enum schema
  2. a schema that uses allof and ref for that enum
    the js client generated has a class that tries to extend an enum (that is represented as a const var in the generated client). and then when i try to use the client it fails with an error
    bootstrap:27 Uncaught TypeError: Class extends value #<Object> is not a constructor or null at ./javascript-client-generated/src/model/AllOfPossibleIssueMode.js (AllOfPossibleIssueMode.js:24:1) at options.factory (react refresh:6:1) at __webpack_require__ (bootstrap:24:1) at fn (hot module replacement:62:1) at ./javascript-client-generated/src/index.js (UserApi.js:367:1) at options.factory (react refresh:6:1) at __webpack_require__ (bootstrap:24:1) at fn (hot module replacement:62:1) at ./src/App.js (logo.svg:30:1) at options.factory (react refresh:6:1)
Swagger-codegen version

using the online client generator (from swagger editor)

Swagger declaration file content or url
  • easy to recreate with the pet store example and adding the following schemas (even without referencing them)
components:
  schemas:
    PossibleIssueEnum:
      title: "PossibleIssueEnum"
      enum:
      - "issue1"
      - "issue2"
      description: "An enumeration."
      
    PossibleIssue:
      title: "PossibleIssue"
      required:
      - "mode"
      type: "object"
      properties:
        mode:
          type: "string"
          allOf:
          - $ref: "#/components/schemas/PossibleIssueEnum"
          description: "possible issues.\
            \ Possible options: “issue1” / “issue2”"
Steps to reproduce
  • add the following schemas to the pet store example
  • generate a js client
  • try to use any endpoint
Related issues/PRs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the pet store example plus the provided PossibleIssueEnum and PossibleIssue schemas, using the JavaScript client generator. Inspect the generated AllOfPossibleIssueMode.js and related generated model output; done means the client loads and can call an endpoint without the Class extends value error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.