swagger-api / swagger-api/swagger-codegen

[JavaScript] Invalid definition classes

Open
#9,269 0 comments 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

Entities specified as swagger definitions are imported with Definitions prefix,

Swagger-codegen version

Docker image with swagger-codegen-cli 2.4.2

Swagger declaration file content or url

For example, given the next declaration:

{
  ...
  "definitions": {
    "Company": {
      "type": "object",
      "properties": {
        "uid": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "companySize": {
          "$ref": "#definitions/CompanySize"
        }
    },
   "CompanySize": {
      "type": "string",
      "enum": [
        "small",
        "medium",
        "large"
      ]
    },

next files are generated: model/Company.js and model/CompanySize.js but the problem is the model/Company.js has de code:

import DefinitionsCompanySize from './DefinitionsCompanySize';

which should be

import CompanySize from './CompanySize';
Command line used for generation

docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -i /local/swagger.json -l javascript -o /local/api-sdk --additional-properties usePromises=true,useES6=true

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

Reproduce the generated model files with the reported Docker command and declaration, then inspect the JavaScript generator templates that produce imports for model/Company.js and model/CompanySize.js. The work is done when Company.js imports CompanySize from './CompanySize' rather than DefinitionsCompanySize from './DefinitionsCompanySize'.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.