swagger-api / swagger-api/swagger-codegen

[Javascript] ES6 and react / react-native

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

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
  1. Within my monorepo I am running the swagger-codegen generate command at the packages level
app
  - packages
    - repo1
    - repo2
    - repo3
  - package.json

The es6 template-dir is taken from the github issue linked below.

  1. cd into packages/petstore and run npm install

  2. 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.