question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support swagger module with AMD imports?

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
martnucommented, Jan 3, 2019

@seanlaff When it comes to node_modules, CRA only compiles standard language features (not class properties). See https://github.com/facebook/create-react-app/pull/3776

0reactions
seanlaffcommented, Jan 3, 2019

Using the useES6 flag in the swagger generation is a way to get around the AMD problem, however Im seeing the same errors @john-goldsmith saw about class fields Support for the experimental syntax 'classProperties' isn't currently enabled

Which is odd because I know CRA supports that transform

[
        require("@babel/plugin-proposal-class-properties").default,
        {
          loose: true,
        },
      ],
Read more comments on GitHub >

github_iconTop Results From Across the Web

Micronaut Open API - OpenAPI/Swagger Support
OpenAPIDefinition; import io.swagger.v3.oas.annotations.info. ... (Swagger) YAML for built-in endpoints or paths from some other modules, such as security .
Read more >
Installation - Swagger Documentation
The module, when imported, includes an absolutePath helper function that returns the absolute filesystem path to where the swagger-ui-dist module is ...
Read more >
How to bundle Swagger generated code with webpack
I found a solution, I need to add the following in my webpack.config.js module: { rules: [ { test: /my_client\/.
Read more >
Building REST API with Express, TypeScript and Swagger
How to build REST API server with Express & TypeScript, and auto-generate OpenAPI documentation with Swagger.
Read more >
API with NestJS #60. The OpenAPI specification and Swagger
We use the OpenAPI and Swagger to create a user interface that serves as interactive API documentation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found