swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

webpack error building javascript generated client

Open saharj opened this issue 10 years ago • 8 comments

From @zsimo on August 3, 2016 16:17

Swagger File

 {
  "swagger": "2.0",
  "info": {
    "title": "Test",
    "description": "Test",
    "version": "1.0.0"
  },
  "host": "localhost",
  "schemes": [
    "http"
  ],
  "basePath": "/services/search",
  "paths": {
    "/institutions": {
      "post": {
        "produces": [
          "application/json"
        ],
        "parameters": [
          {
            "name": "value",
            "in": "query",
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "Records found",
            "schema": {
              "$ref": "#/definitions/QuickSearchRecords"
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "404": {
            "description": "No record found"
          },
          "500": {
            "description": "Unexpected error"
          }
        }
      }
    }
  },


  "definitions": {
    "QuickSearchRecords": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/QuickSearchRecord"
      }
    },
    "QuickSearchRecord": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "count": {
          "type": "integer"
        }
      }
    }

  }
}
  • Version:
  • Browser/OS:

Issue Hello! It seems Webpack (I'm using 1.13.1) fail to manage AMD syntax: by changing the source code, forcing to use CommonJs syntax Webpack succeeds in compiling the scripts. Can you please try/fix?

Thanks!

Copied from original issue: swagger-api/swagger-editor#1035

saharj avatar Aug 05 '16 15:08 saharj

Can you provide more details? Are you trying to modify Swagger Editor code base?

saharj avatar Aug 05 '16 15:08 saharj

From @zsimo on August 4, 2016 9:39

Hello,

No, I just try to edit the client source code generated by the Swagger Editor. It seems Webpack (I'm using 1.13.1) fail to manage AMD syntax: by disabling the Module system the Javascript client works. 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'}

Have you ever try to bundle your Js client generated code via Webpack?

Thanks!

saharj avatar Aug 05 '16 15:08 saharj

This is a Codegene issue. let me move your issue there.

saharj avatar Aug 05 '16 15:08 saharj

i wrote a template for webpack build. may help https://github.com/hasangilak/webpack-swagger-template

hasangilak avatar Dec 12 '16 13:12 hasangilak

@hasangilak thanks for sharing the link. Is that something we can add back to the JS generator? I'm sure the JS developers would welcome the enhancements.

wing328 avatar Feb 16 '17 16:02 wing328

It seems to be a duplicate of #3466.

frol avatar Mar 04 '17 20:03 frol

I think you're right but I can't seem to do what was advised

akeemphilbert avatar Mar 04 '17 21:03 akeemphilbert

Closed via https://github.com/swagger-api/swagger-codegen/issues/3466#issuecomment-284187483

wing328 avatar Mar 06 '17 07:03 wing328