wcandillon / swagger-js-codegen

A Swagger Codegen for typescript, nodejs & angularjs
Apache License 2.0
693 stars 286 forks source link

`form` param trashes the ability to send `json` #28

Closed pulkitsinghal closed 9 years ago

pulkitsinghal commented 9 years ago

First off, thank you for the awesome work on this library!

Summary

The generated code always looks like:

request({
            method: 'POST',
            uri: domain + path,
            qs: queryParameters,
            headers: headers,
            body: body,
            form: form,
            rejectUnauthorized: false
        }, function(error, response, body) {

And sending a request with json does not work. In order to fix this ... form needs to be removed entirely and body: body, needs to change to be json:body

Long Story

I recently used swagger-js-codegen with a framework known as strongloop/loopback and ran into some issues so I've created a demo branch to make them easy to replicate: https://github.com/ShoppinPal/loopback-example-full-stack/tree/feature/nodejs-client

In total I always have to tweak 5-8 things in a generated file before I can use it. But for each tweak, I'm not sure who is the culprit preventing me from getting a perfectly generated file out-of-the-box:

  1. could it be the code generator?
  2. could it be the swagger spec itself?
  3. could it be the default template which should be replaced with a custom one because one size does not fit all?

So I'll be filing a separate issue per "tweak" and counting on your help to either fix a real issue or better my understanding of how to accomplish what I need.

wcandillon commented 9 years ago

@pulkitsinghal Can you send me an example that would help me to reproduce this problem? We use extensively the node.js codegen in a project and never had such issue.

wcandillon commented 9 years ago

@pulkitsinghal Nevermind, I'm able to reproduce it.

pulkitsinghal commented 9 years ago

awesome!