forked from loafle/openapi-generator-original
update js doc
This commit is contained in:
@@ -1,69 +1,104 @@
|
||||
# {{projectName}}
|
||||
|
||||
{{moduleName}} - JavaScript client for {{projectName}}
|
||||
{{#appDescription}}
|
||||
{{{appDescription}}}
|
||||
{{/appDescription}}
|
||||
This SDK is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:
|
||||
|
||||
Version: {{projectVersion}}
|
||||
|
||||
Automatically generated by the JavaScript Swagger Codegen project:
|
||||
|
||||
- API verion: {{appVersion}}
|
||||
- Package version: {{projectVersion}}
|
||||
- Build date: {{generatedDate}}
|
||||
- Build package: {{generatorClass}}
|
||||
{{#infoUrl}}
|
||||
For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}})
|
||||
{{/infoUrl}}
|
||||
|
||||
## Installation
|
||||
|
||||
### Use in [Node.js](https://nodejs.org/)
|
||||
### For [Node.js](https://nodejs.org/)
|
||||
|
||||
The generated client is valid [npm](https://www.npmjs.com/) package, you can publish it as described
|
||||
in [Publishing npm packages](https://docs.npmjs.com/getting-started/publishing-npm-packages).
|
||||
#### npm
|
||||
|
||||
After that, you can install it into your project via:
|
||||
To publish the library as a [npm](https://www.npmjs.com/),
|
||||
please follow the procedure in ["Publishing npm packages"](https://docs.npmjs.com/getting-started/publishing-npm-packages).
|
||||
|
||||
Then install it via:
|
||||
|
||||
```shell
|
||||
npm install {{{projectName}}} --save
|
||||
```
|
||||
|
||||
You can also host the generated client as a git repository on github, e.g.
|
||||
https://github.com/YOUR_USERNAME/{{projectName}}
|
||||
|
||||
Then you can install it via:
|
||||
#### git
|
||||
#
|
||||
If the library is hosted at a git repository, e.g.
|
||||
https://github.com/{{#gitUserName}}{{.}}{{/gitUserName}}{{^gitUserName}}YOUR_USERNAME{{/gitUserName}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}{{projectName}}{{/gitRepoId}}
|
||||
then install it via:
|
||||
|
||||
```shell
|
||||
npm install YOUR_USERNAME/{{{projectName}}} --save
|
||||
npm install {{#gitUserName}}{{.}}{{/gitUserName}}{{^gitUserName}}YOUR_USERNAME{{/gitUserName}}/{{#gitRepoId}}{{.}}{{/gitRepoId}}{{^gitRepoId}}{{projectName}}{{/gitRepoId}} --save
|
||||
```
|
||||
|
||||
### Use in browser with [browserify](http://browserify.org/)
|
||||
### For browser
|
||||
|
||||
The client also works in browser environment via npm and browserify. After following
|
||||
The library also works in the browser environment via npm and [browserify](http://browserify.org/). After following
|
||||
the above steps with Node.js and installing browserify with `npm install -g browserify`,
|
||||
you can do this in your project (assuming *main.js* is your entry file):
|
||||
perform the following (assuming *main.js* is your entry file):
|
||||
|
||||
```shell
|
||||
browserify main.js > bundle.js
|
||||
```
|
||||
|
||||
The generated *bundle.js* can now be included in your HTML pages.
|
||||
Then include *bundle.js* in the HTML pages.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Please follow the [installation](#installation) instruction and execute the following JS code:
|
||||
|
||||
```javascript
|
||||
var {{{moduleName}}} = require('{{{projectName}}}');
|
||||
|
||||
{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}}{{#hasAuthMethods}}
|
||||
var defaultClient = {{{moduleName}}}.ApiClient.default;
|
||||
defaultClient.timeout = 10 * 1000;
|
||||
defaultClient.defaultHeaders['Test-Header'] = 'test_value';
|
||||
{{#authMethods}}{{#isBasic}}
|
||||
// Configure HTTP basic authorization: {{{name}}}
|
||||
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
|
||||
{{{name}}}.username = 'YOUR USERNAME'
|
||||
{{{name}}}.password = 'YOUR PASSWORD'{{/isBasic}}{{#isApiKey}}
|
||||
// Configure API key authorization: {{{name}}}
|
||||
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
|
||||
{{{name}}}.apiKey = "YOUR API KEY"
|
||||
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
|
||||
//{{{name}}}.apiKeyPrefix['{{{keyParamName}}}'] = "Token"{{/isApiKey}}{{#isOAuth}}
|
||||
// Configure OAuth2 access token for authorization: {{{name}}}
|
||||
var {{{name}}} = defaultClient.authentications['{{{name}}}'];
|
||||
{{{name}}}.accessToken = "YOUR ACCESS TOKEN"{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
// Assuming there's a `PetApi` containing a `getPetById` method
|
||||
// which returns a model object:
|
||||
var api = new {{{moduleName}}}.PetApi();
|
||||
api.getPetById(2, function(err, pet, resp) {
|
||||
console.log('HTTP status code: ' + resp.status);
|
||||
console.log('Response Content-Type: ' + resp.get('Content-Type'));
|
||||
if (err) {
|
||||
console.error(err);
|
||||
} else {
|
||||
console.log(pet);
|
||||
}
|
||||
var api = new {{{moduleName}}}.{{{classname}}}(){{#hasParams}}
|
||||
{{#vendorExtensions.x-codegen-hasRequiredParams}}{{#allParams}}{{#required}}
|
||||
var {{{paramName}}} = {{{example}}}; // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}}
|
||||
{{/required}}{{/allParams}}{{/vendorExtensions.x-codegen-hasRequiredParams}}{{#hasOptionalParams}}
|
||||
var opts = { {{#allParams}}{{^required}}
|
||||
'{{{paramName}}}': {{{example}}}{{#vendorExtensions.x-codegen-hasMoreOptional}},{{/vendorExtensions.x-codegen-hasMoreOptional}} // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}}{{/required}}{{/allParams}}
|
||||
};{{/hasOptionalParams}}{{/hasParams}}
|
||||
{{#usePromises}}
|
||||
api.{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}).then(function({{#returnType}}data{{/returnType}}) {
|
||||
{{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
|
||||
}, function(error) {
|
||||
console.error(error);
|
||||
});
|
||||
|
||||
{{/usePromises}}{{^usePromises}}
|
||||
var callback = function(error, data, response) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
} else {
|
||||
{{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
|
||||
}
|
||||
};
|
||||
api.{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}{{#hasParams}}, {{/hasParams}}callback);
|
||||
{{/usePromises}}{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}}
|
||||
```
|
||||
|
||||
## Documentation for API Endpoints
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
* <description></description>
|
||||
* @alias module:<#apiPackage><apiPackage>/</apiPackage><classname>
|
||||
* @class
|
||||
* @param {module:ApiClient} apiClient Optional API client implementation to use, defaulting to {@link module:ApiClient#instance}
|
||||
* @param {module:ApiClient} apiClient Optional API client implementation to use, default to {@link module:ApiClient#instance}
|
||||
* if unspecified.
|
||||
*/
|
||||
</emitJSDoc> var exports = function(apiClient) {
|
||||
@@ -46,7 +46,7 @@
|
||||
* <notes></notes><#allParams><#required>
|
||||
* @param <&vendorExtensions.x-jsdoc-type> <paramName> <description></required></allParams><#hasOptionalParams>
|
||||
* @param {Object} opts Optional parameters<#allParams><^required>
|
||||
* @param <&vendorExtensions.x-jsdoc-type> opts.<paramName> <description></required></allParams></hasOptionalParams><^usePromises>
|
||||
* @param <&vendorExtensions.x-jsdoc-type> opts.<paramName> <description><#defaultValue> (default to <.>)</defaultValue></required></allParams></hasOptionalParams><^usePromises>
|
||||
* @param {module:<#apiPackage><apiPackage>/</apiPackage><classname>~<nickname>Callback} callback The callback function, accepting three arguments: error, data, response</usePromises><#returnType>
|
||||
* data is of type: <&vendorExtensions.x-jsdoc-type></returnType>
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,7 @@ var {{{name}}} = defaultClient.authentications['{{{name}}}'];
|
||||
{{/authMethods}}
|
||||
{{/hasAuthMethods}}
|
||||
|
||||
var api = new {{{moduleName}}}.{{{classname}}}(){{#hasParams}}
|
||||
var apiInstance = new {{{moduleName}}}.{{{classname}}}(){{#hasParams}}
|
||||
{{#vendorExtensions.x-codegen-hasRequiredParams}}{{#allParams}}{{#required}}
|
||||
var {{{paramName}}} = {{{example}}}; // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}}
|
||||
{{/required}}{{/allParams}}{{/vendorExtensions.x-codegen-hasRequiredParams}}{{#hasOptionalParams}}
|
||||
@@ -47,7 +47,7 @@ var opts = { {{#allParams}}{{^required}}
|
||||
'{{{paramName}}}': {{{example}}}{{#vendorExtensions.x-codegen-hasMoreOptional}},{{/vendorExtensions.x-codegen-hasMoreOptional}} // {{=< >=}}{<&dataType>}<={{ }}=> {{{description}}}{{/required}}{{/allParams}}
|
||||
};{{/hasOptionalParams}}{{/hasParams}}
|
||||
{{#usePromises}}
|
||||
api.{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}).then(function({{#returnType}}data{{/returnType}}) {
|
||||
apiInstance.{{{operationId}}}({{#allParams}}{{#required}}{{{paramName}}}{{#vendorExtensions.x-codegen-hasMoreRequired}}, {{/vendorExtensions.x-codegen-hasMoreRequired}}{{/required}}{{/allParams}}{{#hasOptionalParams}}{{#vendorExtensions.x-codegen-hasRequiredParams}}, {{/vendorExtensions.x-codegen-hasRequiredParams}}opts{{/hasOptionalParams}}).then(function({{#returnType}}data{{/returnType}}) {
|
||||
{{#returnType}}console.log('API called successfully. Returned data: ' + data);{{/returnType}}{{^returnType}}console.log('API called successfully.');{{/returnType}}
|
||||
}, function(error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user