swagger-api / swagger-api/swagger-codegen
[Javascript] ES6 and react / react-native
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I am trying to use swagger-codegen to generate client-side code in my monorepo project
Swagger-codegen version
2.4.7
Swagger declaration file content or url
http://petstore.swagger.io/v2/swagger.json
Command line used for generation
swagger-codegen generate \
--input-spec http://petstore.swagger.io/v2/swagger.json \
--lang javascript \
--output ./petstore \
--template-dir ./es6 \
--additional-properties usePromises=true,useES6=true
Steps to reproduce
- Within my monorepo I am running the
swagger-codegen generatecommand at thepackageslevel
app
- packages
- repo1
- repo2
- repo3
- package.json
The es6 template-dir is taken from the github issue linked below.
-
cdintopackages/petstoreand runnpm install -
rerun my react app
First issue
The template-dir does not seem to solve the experimental classProperties problem:
../petstore/src/ApiClient.js
SyntaxError: /path/to/packages/petstore/src/ApiClient.js: Support for the experimental syntax 'classProperties' isn't currently enabled (231:33):
I can get around this issue by replacing all classProperties with methods of the same name.
Second issue
If I use the workaround in the first issue, I now receive the error
TypeError: _petstore_src__WEBPACK_IMPORTED_MODULE_5__.PetApi.getPetById is not a function
when importing import { PetApi } from '../path/to/petstore/src and trying to call
PetApi.getPetById(1)
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/8024
I'm sure I'm missing an obvious step here, so any help is appreciated.
Thank you
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
Reproduce the command against the Petstore specification, then inspect the generated src/ApiClient.js and PetApi entry point under the es6 template directory. Check the reported classProperties failure and the PetApi.getPetById import/call in the React monorepo. Done means the generated client installs and the example call works without either reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react, react-native
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100