Skip to content

Support swagger module with AMD imports? #3247

Closed
@chenatu

Description

@chenatu

I am using swagger-codegen to generate swagger js client. However, it is hard to import the client module.

Environment

  1. node -v: 8.1.4
  2. npm -v: 5.4.2
  3. yarn --version (if you use Yarn): 1.1.0
  4. npm ls react-scripts (if you haven’t ejected): 1.0.14

Then, specify:

  1. Operating system: MAC OSX
  2. Browser and version (if relevant): chrome

Steps to Reproduce

  1. install swagger-codegen and generate javascript project according to some api spec
  2. install local swagger module according to README.md file in the generated swagger project
  3. import the module in the react project ant it shows:
Module not found: Can't resolve 'ApiClient' in /path/to/API

Expected Behavior

No error

Actual Behavior

image

In swagger issue 3537. It discusses this issue and bring 2 solutions:

Disabling directly edit the code source :

// commenting the first IF branch
  //if (typeof define === 'function' && define.amd) {
  //  // AMD. Register as an anonymous module.
  //  define(['superagent'], factory);
  //} else
  if (typeof module === 'object' && module.exports) {
    // CommonJS-like environments that support module.exports, like Node.
    module.exports = factory(require('superagent'));
  }

or via Webpack configs:

npm install --save-dev imports-loader
// and then add this loader to the webpack configs
{ test: /\.js/, loader: 'imports?define=>false'}

Since, it is not advised to revise the react-scripts, could create-react-app support swagger client imports?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions