OpenAPITools / OpenAPITools/openapi-generator

[BUG][JAVASCRIPT] Node scope in projectName generates code that is unusable (e.g. projectName=@mypackagescope/mypackagename)

Open
#4,384 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: JavaScript/Node.js Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

If you want use a scoped node package name, then the generator will generate unusable code.

Actual
openapi-generator generate -i .\api-with-examples.yaml -g javascript -o generated-sources/openapi --additional-properties="projectName=@mypackagescope/mypackagename
Will generate the README.md excerpt

var @MypackagescopeMypackagename = require('@mypackagescope/mypackagename');
var api = new @MypackagescopeMypackagename.DefaultApi()

Expected
Expected input is up for discussion. What I would do is add a nodeScope parameter so that
--additional-properties="nodeScopeName=mypackagescope,projectName=mypackagename
generates

var Mypackagename = require('@mypackagescope/mypackagename');
var api = new Mypackagename.DefaultApi()
openapi-generator version

4.2.0

OpenAPI declaration file content or url
openapi: "3.0.0"
info:
  title: Simple API overview
  version: 2.0.0
paths:
  /:
    get:
      operationId: listVersionsv2
      summary: List API versions
      responses:
        '200':
          description: |-
            200 response
          content:
            application/json:
              examples: 
                foo:
                  value: { }
Command line used for generation

Actual
openapi-generator generate -i .\api-with-examples.yaml -g javascript -o generated-sources/openapi --additional-properties="projectName=@mypackagescope/mypackagename"
Expected (suggested)
openapi-generator generate -i .\api-with-examples.yaml -g javascript -o generated-sources/openapi --additional-properties="nodeScope=mypackagescope,projectName=mypackagename"

Steps to reproduce

Run the command on any valid specification.yaml. Observe the generated README and code.

Related issues/PRs
Suggest a fix

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 documented openapi-generator command with the supplied OpenAPI declaration and inspect the generated README and JavaScript code. Compare the scoped projectName output with the suggested nodeScope and projectName inputs; done means the generated require statement and client variable use valid JavaScript identifiers while retaining the scoped package name.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.