swagger-api / swagger-api/swagger-codegen

[JavaScript] Scoped packages throw SyntaxError when running tests

Open
#9,084 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

When passing a scoped npm package (@scope/my-project) to the projectName argument, it seems to produce test files that are not valid syntax, due to the @ symbol.

SyntaxError: /Users/jgoldsmith/Sites/personal/my-project/test/api/AuthApi.spec.js: Unexpected token (23:30)
  21 |   } else {
  22 |     // Browser globals (root is window)
> 23 |     factory(root.expect, root.@ScopeMyProject);
     |                               ^
  24 |   }
  25 | }(this, function(expect, @ScopeMyProject) {
  26 |   'use strict';
Swagger-codegen version

2.4.0

Command line used for generation
docker run \
  --rm \
  --volume ${PWD}:/local \
  swaggerapi/swagger-codegen-cli \
  generate \
    --input-spec http://localhost:3000/v1/docs \
    --lang javascript \
    --output /local \
    --additional-properties usePromises=true,useES6=true,emitModelMethods=true,projectName='@scope/my-project',projectDescription='Some description...'
Steps to reproduce
  1. Run the above docker command (be sure to pass it a Swagger spec that both exists and is valid).
  2. Run npm test.
  3. Observe the error that is thrown.
Suggest a fix/enhancement

Modify https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Javascript/model_test.mustache#L11

I'll try and get a PR going, just wanted to solicit some quick feedback.

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

Inspect modules/swagger-codegen/src/main/resources/Javascript/model_test.mustache at the referenced line, then reproduce the issue with the Docker generation command and run npm test. Done means generated tests for a scoped projectName parse and pass without the @ symbol causing invalid JavaScript syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.