-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Document client SDK #1294
Comments
@jpangburn for JS SDK, do you actually mean http://github.com/swagger-api/swagger-js? Currently, swagger-codegen does not offer a JS (client-side) code generator. |
Hi, thanks,
|
We'll mark this as a feature request (there's a similar request before) and we're looking for contribution from the community to implement the JS SDK in swagger codegen. |
Added PR #1671, here are the details of the currently added changes to support Javascript SDKs: Add basic Javascript SDK support(based on the Java templates):
Sample model output:function StateEnum() {
var self = this;
self.ACTIVE = "ACTIVE",
self.DISABLED = "DISABLED";
}
/**
* User object
**/
function User(id, lastname, firstname) {
var self = this;
/**
* First name of the user
* datatype: String
* required
**/
self.firstname = firstname;
...
self.constructFromObject = function(data) {
self.firstname = data.firstname;
self.id = data.id;
self.lastname = data.lastname;
self.location.constructFromObject(data.location);
self.nickname = data.nickname;
self.state = data.state;
}
/**
* get First name of the user
* @return {String}
**/
self.getFirstname = function() {
return self.firstname;
}
/**
* set First name of the user
* @param {String} firstname
**/
self.setFirstname = function (firstname) {
self.firstname = firstname;
}
...
self.toJson = function () {
return JSON.stringify(self);
}
}
Sample invocation with SDK supportSample invocation in Javascript after generating the SDK (first save the user object, then read it again): var myGlobalUser = new User();
/**
* basic example to create and read a User
*/
function callApiSwagger() {
var myUser = new User(1, 'surname', 'my first name');
myUser.setState(StateEnum.ACTIVE);
myUser.getLocation().setCity("Vienna");
console.log('request: ' + myUser.toJson());
var myUsercrudApi = new UsercrudApi();
myUsercrudApi.saveUserCompleteUsingPOST1(myUser,
/**
* @param {User} response
*/
function (response, textStatus, jqXHR) {
console.log('firstname: ' + response.getFirstname());
console.log('location.city: ' + response.getLocation().getCity());
console.log('response: ' + response.toJson());
myUsercrudApi.getUserUsingGET1(response.getId(),
/**
* @param {User} response
*/
function (response, textStatus, jqXHR) {
console.log('location.city: ' + response.getLocation().getCity());
myGlobalUser.setFirstname(response.getFirstname() + " in " + response.getLocation().getCity());
});
});
} Sample invocation before without SDK supportAnd this is what the invoking code looked before with plain ajax: /**
* basic example to create and read a User
*/
function callApi() {
var backend_url = 'http://localhost:8080/user';
var data = {id: 1, firstname: 'my first name', lastname: 'surname', state: 'ACTIVE', location: { city: 'Vienna' }};
var json_data = JSON.stringify(data);
console.log('request: ' + json_data);
var options = {type: "post", async: true, contentType: "application/json", dataType: "json", data: json_data};
var request = $.ajax(backend_url, options, data);
request.done(function(response){
console.log('firstname: ' + response.firstname);
console.log('location.city: ' + response.location.city);
console.log('response: ' + JSON.stringify(response));
var queryString = '?id=' + response.id;
var url = backend_url + queryString;
var options = {type: "get", async: true, contentType: "application/json", dataType: "json"};
var request = $.ajax(url, options, data);
request.done(function(response){
console.log('location.city: ' + response.location.city);
myGlobalUser1.firstname = response.firstname + " in " + response.location.city;
});
});
}
|
I'm trying to generate a Javascript SDK for my API and find that there's no good way to generate documentation for how a user would use that SDK to connect to my API. The swagger doc shows HTTP methods and URLs but those don't matter to the client SDK user- what matters to them is what methods they call in the SDK, and what parameters those methods take.
It seems like swagger-codegen has all the data available needed to generate such a static HTML documentation for a generated SDK. This should also generate doc for a Javascript SDK too please.
The text was updated successfully, but these errors were encountered: