swagger-api / swagger-api/swagger-codegen
[JavaScript] Scoped packages throw SyntaxError when running tests
Open
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
- Run the above
dockercommand (be sure to pass it a Swagger spec that both exists and is valid). - Run
npm test. - Observe the error that is thrown.
Suggest a fix/enhancement
I'll try and get a PR going, just wanted to solicit some quick feedback.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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