Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JavaScript Module - LoginRequest doesn't seem to work #2892

Open
cwbuecheler opened this issue May 17, 2016 · 11 comments
Open

JavaScript Module - LoginRequest doesn't seem to work #2892

cwbuecheler opened this issue May 17, 2016 · 11 comments

Comments

@cwbuecheler
Copy link

Greets,

I used swagger-codegen to generate a node module that I could then reference in my React project. This worked fine and I have it up and running, however the LoginRequest method doesn't appear to be working right. I just want to make sure I have the syntax correct. The following code always sends an empty body to the server, resulting in a 500 error. Is there something wrong with it?

(note: the auth info is obviously fake, but even with fake creds it should return a 401, not a 500 -- with the real creds, it's still a 500 because they're never being sent)

import SwaggerJsClient from 'swagger-js-client';

const api = new SwaggerJsClient.DefaultApi()

const opts = {
  'body': new SwaggerJsClient.LoginRequest({ email: 'test@test.com', password: 'testme' }),
};

const callback = (error, data, response) => {
  console.log('error: ', error);
  console.log('data: ', data);
  console.log('response: ', response);
};

api.login(opts, callback);

If I skip using the LoginRequest() method and just do the following, it works:

const opts = {
  'body': {
    'email': 'test@test.com',
    'password': 'testme',
  },
};

I've looked through the docs, I've tried using JSON.stringify() on the data I'm passing to LoginRequest(), and even tried to do some testing on LoginRequest.js but haven't been able to figure out what the problem is. Any ideas?

@wing328
Copy link
Contributor

wing328 commented May 17, 2016

@cwbuecheler please share the spec so that we can help look into the issue

@cwbuecheler
Copy link
Author

@wing328 Thanks for the quick response. Happy to share whatever you need. Here's the raw swagger.json spec. If you need anything else, let me know. Thanks!

swagger.json.txt

@wing328
Copy link
Contributor

wing328 commented May 18, 2016

@cwbuecheler the model definition looks good to me:

  LoginRequest:
    type: object
    properties:
      email:
        type: string
      password:
        type: string

and I believe the backend is expecting something like the following:

{
  "email": "test@email.com",
  "password": "abcefg123456"
}

How did you generate the JS API client?

@cwbuecheler
Copy link
Author

cwbuecheler commented May 18, 2016

Yep, that's exactly what the back-end is expecting.

I generated it with swagger-codegen on OSX, installed via homebrew, with the Java 8 SDK and Maven installed, using the following command:

swagger-codegen generate -i http://api.url/swagger.json -l javascript -o /Users/chris/swaggeroutput/

where api.url is the ... url to our api :)

I then moved the entirety of swagger output to our project, changed the default URI from localhost to our API URI, and npm linked the module so I can use it in the project. It's definitely being accessed, as it makes the API call and all that. It's just not returning any params when doing new SwaggerJsClient.LoginRequest({ email: 'test@test.com', password: 'testme' }), part of the code above.

I'd be happy to send the entire swaggeroutput dir (minus its node_modules folder) if you'd like. Or if I screwed up something in the initial generation syntax, please let me know.

Thanks!

@wing328
Copy link
Contributor

wing328 commented May 18, 2016

We do have a test case for JS API client to cover post model (JSON): https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/javascript/test/api/PetApiTest.js#L58

@wing328
Copy link
Contributor

wing328 commented May 18, 2016

I also suspect you're not using the latest version/master. I would suggest you to pull the latest and build the jar locally. Here is a good starting point: https://github.com/swagger-api/swagger-codegen#getting-started

@cwbuecheler
Copy link
Author

cwbuecheler commented May 18, 2016

OK, thanks, I'll skip homebrew and build manually (I've not worked with Java before so I figured I'd take the easy road first). Will also run some tests and see if they come up with any issues.

@cwbuecheler
Copy link
Author

@wing328 - I've snagged the lastest master from github, built the jar locally and installed it as a node module, but am running into issues with webpack that I don't fully understand. Basically it won't load any of the factories listed at the top of src/index.js. For each of the attempted requires in src/index.js, I get the following type of error:

ERROR in ./~/swagger-js-client/src/index.js
Module not found: Error: Cannot resolve module 'model/Account' in /Users/chris/work/client/platform/partner_portal/node_modules/swagger-js-client/src
resolve module model/Account in /Users/chris/work/client/platform/partner_portal/node_modules/swagger-js-client/src
  looking for modules in /Users/chris/work/client/platform/partner_portal/src
    /Users/chris/work/client/platform/partner_portal/src/model doesn't exist (module as directory)
  looking for modules in /Users/chris/work/client/platform/partner_portal/node_modules
    /Users/chris/work/dataclientista/platform/partner_portal/node_modules/model doesn't exist (module as directory)
[/Users/chris/work/client/platform/partner_portal/src/model]
[/Users/chris/work/client/platform/partner_portal/node_modules/model]
 @ ./~/swagger-js-client/src/index.js 4:4-575

I've looked into adjusting my webpack config but it should be working -- I can and do import plenty of other node modules into my React app, most of which use the require() syntax, without any problems.

I understand this may be a webpack issue (or more likely, a problem with my config) and is therefor kind of outside of the scope of what you may be able to provide support on, but I figured I'd check and see if you had any thoughts.

@wing328
Copy link
Contributor

wing328 commented Jun 20, 2016

@cwbuecheler sorry I've no idea either.

I've marked this as "Need community contribution" for the time being to see if anyone from the community has a clue.

@wing328 wing328 modified the milestones: v2.2.0, v2.3.0 Jul 7, 2016
@wing328 wing328 modified the milestones: v2.2.1, v2.2.2 Aug 8, 2016
@monte-hayward
Copy link

@cwbuecheler did you find a solution? Would you share the solution and/or the directory structure generated? I have a similar issue, and it feels like a path problem.

@cwbuecheler
Copy link
Author

Honestly, I switched to swagger-client and stopped using swagger-codegen after encountering this issue, so I'm afraid I don't have an answer.

@wing328 wing328 modified the milestones: v2.2.2, Future Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants