OpenAPITools / OpenAPITools/openapi-generator
[QUESTION][JAVASCRIPT] generated source differs from your example (How to use it)
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Hi
I have got a small api and generate some code for it. I am figuring out how to use it.
From the examples I found this https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/javascript/docs/PetApi.md#addPet
So I have tried to apply this example for my api. But I don't get it working, nothing is send to the api server.
I have got this:
var Api = require('api')
vae UserApi = new Api.UserApi()
var body = new Api.NewUserRequest()
body.name = 'test name'
body.email = 'test email'
UserApi.createUser(body, callback)
This is the generated UserApi:
import ApiClient from "../ApiClient";
import ErrorResponse from '../model/ErrorResponse';
import NewUserRequest from '../model/NewUserRequest';
import User from '../model/User';
/**
* User service.
* @module api/UserApi
* @version 1.0
*/
export default class UserApi {
/**
* Constructs a new UserApi.
* @alias module:api/UserApi
* @class
* @param {module:ApiClient} [apiClient] Optional API client implementation to use,
* default to {@link module:ApiClient#instance} if unspecified.
*/
constructor(apiClient) {
this.apiClient = apiClient || ApiClient.instance;
}
/**
* Callback function to receive the result of the createUser operation.
* @callback module:api/UserApi~createUserCallback
* @param {String} error Error message, if any.
* @param data This operation does not return a value.
* @param {String} response The complete HTTP response.
*/
/**
* Create user
* @param {Object} opts Optional parameters
* @param {module:model/NewUserRequest} opts.newUserRequest
* @param {module:api/UserApi~createUserCallback} callback The callback function, accepting three arguments: error, data, response
*/
createUser(opts, callback) {
opts = opts || {};
let postBody = opts['newUserRequest'];
let pathParams = {
};
let queryParams = {
};
let headerParams = {
};
let formParams = {
};
let authNames = [];
let contentTypes = ['application/json'];
let accepts = ['application/json'];
let returnType = null;
return this.apiClient.callApi(
'/users', 'POST',
pathParams, queryParams, headerParams, formParams, postBody,
authNames, contentTypes, accepts, returnType, null, callback
);
}
I did some research how the UserApi must send the request and found the line
let postBody = opts['newUserRequest'];
This differs from the generated pet store api from the examples:
https://github.com/OpenAPITools/openapi-generator/blob/master/samples/client/petstore/javascript/src/api/PetApi.js
check the addPet function
How should I use my generated code to get it working?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Compare the generated UserApi.createUser implementation with samples/client/petstore/javascript/src/api/PetApi.js and the usage documented in samples/client/petstore/javascript/docs/PetApi.md#addPet. Start by checking how the generated method expects newUserRequest and how the request callback is invoked; done means reproducing a request to /users and confirming the callback receives the result or error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100