swagger-api / swagger-api/swagger-codegen
[JavaScript] Usage with create-react-app + Promises + ES6 unsupported?
Nessuno ha ancora preso questa issue.
- Lingua principale
- Mustache
- Stelle
- 17.8k
- Fork
- 6k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Description
The generated JavaScript output from passing the usePromises and/or useES6 options don't seem to play nicely with a fresh non-ejected React app created using create-react-app. I realize this sounds more like a create-react-app problem than a Swagger problem, but some initial findings indicate that Swagger's ES6 static property syntax isn't (yet) supported. It's possible I'm just overlooking something simple, but figured I'd float it to the community.
Swagger-codegen version
2.3.1
Swagger declaration file content or url
http://petstore.swagger.io/v2/swagger.json
Command line used for generation
JavaScript, with Promises:
swagger-codegen generate -i http://petstore.swagger.io/v2/swagger.json -l javascript -o . --additional-properties usePromises=true
Yields:
Failed to compile.
../my-app/src/index.js
Module not found: Can't resolve 'ApiClient' in '/Users/jgoldsmith/Sites/my-app/src'
(which, to me, just looks like some missing relative path qualifiers, e.g., ./ApiClient)
JavaScript, with Promises and ES6:
swagger-codegen generate -i http://petstore.swagger.io/v2/swagger.json -l javascript -o . --additional-properties usePromises=true,useES6=true
Yields:
../my-app/src/ApiClient.js
Module parse failed: Unexpected token (231:32)
You may need an appropriate loader to handle this file type.
| * @readonly
| */
| static CollectionFormatEnum = {
| /**
| * Comma-separated values. Value: <code>csv</code>
(ref)
I manually changed all instances of static someProperty in the generated SDK to static get someProperty() and things seemed to work fine (but obviously that's not a real solution).
Steps to reproduce
- Using
swagger-codegen, generate JavaScript SDKs, passing theusePromisesand/oruseES6options - Use
create-react-appto create a new app - Install/link the generated SDK into the app
- Run
npm startin the React app - Note the compilation errors
Related issues/PRs
- Possibly #8017
- https://github.com/facebook/create-react-app/issues/3247
Suggest a fix/enhancement
For non-ES6 output: use the correct relative paths
For ES6 output: change static properties to static get myProp() { return value; } or MyClass.myProp (my personal preference, ref)
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo entrambi i fallimenti con i comandi swagger-codegen forniti e un progetto create-react-app nuovo, non sottoposto a eject. Esamina modules/swagger-codegen/src/main/resources/Javascript/es6/ApiClient.mustache e il file ApiClient.js generato; il lavoro è completato quando gli SDK generati vengono compilati nella configurazione React indicata per le opzioni usePromises e useES6 pertinenti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, react
- Ambito
- api, frontend
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100