forked from loafle/openapi-generator-original
[Typescript-Fetch] Support additionalproperties, Enum, Auth and more. (#6130)
* Support additionalproperties and more. - Upgrade to TypeScript 2 - Use type definition from npm instead of typings, typings is deprecation - Use Enum instead of String Literal Types - Use typescript es6 lib for target es5 - Support additionalproperties - Support JSDoc - Add snapshot and npmRepository option - Update typescript-fetch run script for linux - Create typescript-fetch run script for windows * Update and fix - Fix circle run script - Fix duplicate query parameter * Rename typescript-fetch folder to lowercase * Fix for review and update new line end of file * Fix end of file * rename script to {lang}-petstore-all.sh and fix test * Fix override query string https://stackoverflow.com/a/7517673/1077943
This commit is contained in:
parent
d4b8658e07
commit
3ecc374682
@ -26,6 +26,6 @@ fi
|
||||
|
||||
# if you've executed sbt assembly previously it will use that instead.
|
||||
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/TypeScript-Fetch -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l typescript-fetch -o samples/client/petstore-security-test/typescript-fetch"
|
||||
ags="$@ generate -t modules/swagger-codegen/src/main/resources/typescript-fetch -i modules/swagger-codegen/src/test/resources/2_0/petstore-security-test.yaml -l typescript-fetch -o samples/client/petstore-security-test/typescript-fetch"
|
||||
|
||||
java $JAVA_OPTS -jar $executable $ags
|
@ -1,3 +1,7 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-fetch-petstore",
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false,
|
||||
"supportsES6": true
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
{
|
||||
"npmName": "@swagger/typescript-fetch-petstore",
|
||||
"npmVersion": "0.0.1"
|
||||
"npmVersion": "1.0.0",
|
||||
"npmRepository" : "https://skimdb.npmjs.com/registry",
|
||||
"snapshot" : false
|
||||
}
|
||||
|
5
bin/windows/typescript-fetch-petstore-all.bat
Normal file
5
bin/windows/typescript-fetch-petstore-all.bat
Normal file
@ -0,0 +1,5 @@
|
||||
@ECHO OFF
|
||||
|
||||
call bin\windows\typescript-fetch-petstore.bat
|
||||
call bin\windows\typescript-fetch-petstore-target-es6.bat
|
||||
call bin\windows\typescript-fetch-petstore-with-npm-version.bat
|
12
bin/windows/typescript-fetch-petstore-target-es6.bat
Normal file
12
bin/windows/typescript-fetch-petstore-target-es6.bat
Normal file
@ -0,0 +1,12 @@
|
||||
@ECHO OFF
|
||||
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -c bin\typescript-fetch-petstore-target-es6.json -o samples\client\petstore\typescript-fetch\builds\es6-target
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
12
bin/windows/typescript-fetch-petstore-with-npm-version.bat
Normal file
12
bin/windows/typescript-fetch-petstore-with-npm-version.bat
Normal file
@ -0,0 +1,12 @@
|
||||
@ECHO OFF
|
||||
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
mvn clean package
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -c bin\typescript-fetch-petstore-with-npm-version.json -o samples\client\petstore\typescript-fetch\builds\with-npm-version
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
6
bin/windows/typescript-fetch.bat → bin/windows/typescript-fetch-petstore.bat
Executable file → Normal file
6
bin/windows/typescript-fetch.bat → bin/windows/typescript-fetch-petstore.bat
Executable file → Normal file
@ -1,3 +1,5 @@
|
||||
@ECHO OFF
|
||||
|
||||
set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar
|
||||
|
||||
If Not Exist %executable% (
|
||||
@ -5,6 +7,8 @@ If Not Exist %executable% (
|
||||
)
|
||||
|
||||
REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
|
||||
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -o samples\client\petstore\typescript-fetch
|
||||
|
||||
echo
|
||||
set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -l typescript-fetch -o samples\client\petstore\typescript-fetch\builds\default
|
||||
|
||||
java %JAVA_OPTS% -jar %executable% %ags%
|
@ -4,19 +4,24 @@ import io.swagger.codegen.CliOption;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.ModelImpl;
|
||||
import io.swagger.models.properties.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeSet;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodegen {
|
||||
private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
|
||||
|
||||
public static final String NPM_NAME = "npmName";
|
||||
public static final String NPM_VERSION = "npmVersion";
|
||||
public static final String NPM_REPOSITORY = "npmRepository";
|
||||
public static final String SNAPSHOT = "snapshot";
|
||||
|
||||
protected String npmName = null;
|
||||
protected String npmVersion = "1.0.0";
|
||||
protected String npmRepository = null;
|
||||
|
||||
public TypeScriptFetchClientCodegen() {
|
||||
super();
|
||||
@ -26,31 +31,74 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
importMapping.clear();
|
||||
|
||||
outputFolder = "generated-code/typescript-fetch";
|
||||
embeddedTemplateDir = templateDir = "TypeScript-Fetch";
|
||||
embeddedTemplateDir = templateDir = "typescript-fetch";
|
||||
|
||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json"));
|
||||
this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) {
|
||||
codegenModel.additionalPropertiesType = getTypeDeclaration(swaggerModel.getAdditionalProperties());
|
||||
addImport(codegenModel, codegenModel.additionalPropertiesType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
supportingFiles.add(new SupportingFile("index.mustache", "", "index.ts"));
|
||||
supportingFiles.add(new SupportingFile("api.mustache", "", "api.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("README.md", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("package.json.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("typings.json.mustache", "", "typings.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.json.mustache", "", "tsconfig.json"));
|
||||
supportingFiles.add(new SupportingFile("tslint.json.mustache", "", "tslint.json"));
|
||||
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", "", "configuration.ts"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
supportingFiles.add(new SupportingFile("gitignore", "", ".gitignore"));
|
||||
|
||||
if(additionalProperties.containsKey(NPM_NAME)) {
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
addNpmPackageGeneration();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeDeclaration(Property p) {
|
||||
Property inner;
|
||||
if(p instanceof ArrayProperty) {
|
||||
ArrayProperty mp1 = (ArrayProperty)p;
|
||||
inner = mp1.getItems();
|
||||
return this.getSwaggerType(p) + "<" + this.getTypeDeclaration(inner) + ">";
|
||||
} else if(p instanceof MapProperty) {
|
||||
MapProperty mp = (MapProperty)p;
|
||||
inner = mp.getAdditionalProperties();
|
||||
return "{ [key: string]: " + this.getTypeDeclaration(inner) + "; }";
|
||||
} else if(p instanceof FileProperty || p instanceof ObjectProperty) {
|
||||
return "any";
|
||||
} else {
|
||||
return super.getTypeDeclaration(p);
|
||||
}
|
||||
}
|
||||
|
||||
private void addNpmPackageGeneration() {
|
||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(NPM_VERSION)) {
|
||||
this.setNpmVersion(additionalProperties.get(NPM_VERSION).toString());
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) {
|
||||
this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date()));
|
||||
}
|
||||
additionalProperties.put(NPM_VERSION, npmVersion);
|
||||
|
||||
if (additionalProperties.containsKey(NPM_REPOSITORY)) {
|
||||
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
|
||||
}
|
||||
|
||||
//Files for building our lib
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||
supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -79,24 +127,12 @@ public class TypeScriptFetchClientCodegen extends AbstractTypeScriptClientCodege
|
||||
this.npmVersion = npmVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// process enum in models
|
||||
List<Object> models = (List<Object>) postProcessModelsEnum(objs).get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
cm.imports = new TreeSet(cm.imports);
|
||||
for (CodegenProperty var : cm.vars) {
|
||||
// name enum with model name, e.g. StatuEnum => PetStatusEnum
|
||||
if (Boolean.TRUE.equals(var.isEnum)) {
|
||||
var.datatypeWithEnum = var.datatypeWithEnum.replace(var.enumName, cm.classname + var.enumName);
|
||||
var.enumName = cm.classname + var.enumName;
|
||||
}
|
||||
}
|
||||
public String getNpmRepository() {
|
||||
return npmRepository;
|
||||
}
|
||||
|
||||
return objs;
|
||||
public void setNpmRepository(String npmRepository) {
|
||||
this.npmRepository = npmRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,54 +0,0 @@
|
||||
# TypeScript-Fetch
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
Environment
|
||||
* Node.js
|
||||
* Webpack
|
||||
* Browserify
|
||||
|
||||
Language level
|
||||
* ES5 - you must have a Promises/A+ library installed
|
||||
* ES6
|
||||
|
||||
Module system
|
||||
* CommonJS
|
||||
* ES6 module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||
|
||||
### Installation ###
|
||||
|
||||
`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`.
|
||||
|
||||
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`.
|
||||
|
||||
#### NPM ####
|
||||
You may publish the module to NPM. In this case, you would be able to install the module as any other NPM module. It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
|
||||
|
||||
You can also use `npm link` to link the module. However, this would not modify `package.json` of the installing project, as such you would need to relink every time you deploy that project.
|
||||
|
||||
You can also directly install the module using `npm install file_path`. If you do `npm install file_path --save`, NPM will save relative path to `package.json`. In this case, `npm install` and `npm shrinkwrap` may misbehave. You would need to manually edit `package.json` and replace it with absolute path.
|
||||
|
||||
Regardless of which method you deployed your NPM module, the ES6 module syntaxes are as follows:
|
||||
```
|
||||
import * as localName from 'npmName';
|
||||
import {operationId} from 'npmName';
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('npmName');
|
||||
```
|
||||
|
||||
#### Direct copy/symlink ####
|
||||
You may also simply copy or symlink the generated module into a directory under your project. The syntax of this is as follows:
|
||||
|
||||
With ES6 module syntax, the following syntaxes are supported:
|
||||
```
|
||||
import * as localName from './symlinkDir';
|
||||
import {operationId} from './symlinkDir';
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('./symlinkDir')';
|
||||
```
|
@ -1,255 +0,0 @@
|
||||
{{>licenseInfo}}
|
||||
import * as querystring from "querystring";
|
||||
import * as url from "url";
|
||||
|
||||
import * as isomorphicFetch from "isomorphic-fetch";
|
||||
{{^supportsES6}}
|
||||
import * as assign from "core-js/library/fn/object/assign";
|
||||
{{/supportsES6}}
|
||||
|
||||
import { Configuration } from "./configuration";
|
||||
|
||||
interface Dictionary<T> { [index: string]: T; }
|
||||
export interface FetchAPI { (url: string, init?: any): Promise<any>; }
|
||||
|
||||
const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
|
||||
|
||||
export interface FetchArgs {
|
||||
url: string;
|
||||
options: any;
|
||||
}
|
||||
|
||||
export class BaseAPI {
|
||||
basePath: string;
|
||||
fetch: FetchAPI;
|
||||
public configuration: Configuration;
|
||||
|
||||
constructor(fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH, configuration: Configuration = new Configuration()) {
|
||||
this.basePath = basePath;
|
||||
this.fetch = fetch;
|
||||
this.configuration = configuration;
|
||||
}
|
||||
};
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
{{^isEnum}}
|
||||
export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
||||
{{/isEnum}}
|
||||
{{#isEnum}}
|
||||
export type {{{classname}}} = {{#allowableValues}}{{#values}}"{{{.}}}"{{^-last}} | {{/-last}}{{/values}}{{/allowableValues}};
|
||||
{{/isEnum}}
|
||||
{{#vars}}
|
||||
{{#description}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
*/
|
||||
{{/description}}
|
||||
"{{name}}"{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
||||
{{/vars}}
|
||||
{{^isEnum}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
|
||||
{{#hasEnums}}
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
export type {{{enumName}}} = {{#allowableValues}}{{#values}}"{{{.}}}"{{^-last}} | {{/-last}}{{/values}}{{/allowableValues}};
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
{{/hasEnums}}
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
|
||||
/**
|
||||
* {{classname}} - fetch parameter creator{{#description}}
|
||||
* {{&description}}{{/description}}
|
||||
*/
|
||||
export const {{classname}}FetchParamCreator = {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
*/
|
||||
{{nickname}}({{#hasParams}}params: { {{#allParams}} {{paramName}}{{^required}}?{{/required}}: {{{dataType}}};{{/allParams}} }, {{/hasParams}}{{#hasAuthMethods}}configuration: Configuration, {{/hasAuthMethods}}options: any = {}): FetchArgs {
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
// verify required parameter "{{paramName}}" is set
|
||||
if (params["{{paramName}}"] == null) {
|
||||
throw new Error("Missing required parameter {{paramName}} when calling {{nickname}}");
|
||||
}
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
const baseUrl = `{{{path}}}`{{#pathParams}}
|
||||
.replace(`{${"{{baseName}}"}}`, `${ params["{{paramName}}"] }`){{/pathParams}};
|
||||
let urlObj = url.parse(baseUrl, true);
|
||||
{{#hasQueryParams}}
|
||||
urlObj.query = {{#supportsES6}}Object.{{/supportsES6}}assign({}, urlObj.query);
|
||||
{{#queryParams}}
|
||||
if (params["{{paramName}}"] !== undefined) {
|
||||
urlObj.query["{{baseName}}"] = params["{{paramName}}"];
|
||||
}
|
||||
{{/queryParams}}
|
||||
{{/hasQueryParams}}
|
||||
let fetchOptions: RequestInit = {{#supportsES6}}Object.{{/supportsES6}}assign({}, { method: "{{httpMethod}}" }, options);
|
||||
|
||||
let contentTypeHeader: Dictionary<string> = {};
|
||||
{{#hasFormParams}}
|
||||
contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" };
|
||||
fetchOptions.body = querystring.stringify({
|
||||
{{#formParams}}
|
||||
"{{baseName}}": params["{{paramName}}"],
|
||||
{{/formParams}}
|
||||
});
|
||||
{{/hasFormParams}}
|
||||
{{#hasBodyParam}}
|
||||
contentTypeHeader = { "Content-Type": "application/json" };{{#bodyParam}}
|
||||
if (params["{{paramName}}"]) {
|
||||
fetchOptions.body = JSON.stringify(params["{{paramName}}"] || {});
|
||||
}{{/bodyParam}}
|
||||
{{/hasBodyParam}}
|
||||
{{#hasHeaderParams}}
|
||||
fetchOptions.headers = {{#supportsES6}}Object.{{/supportsES6}}assign({
|
||||
{{#headerParams}}"{{baseName}}": params["{{paramName}}"],{{/headerParams}}
|
||||
}, contentTypeHeader, fetchOptions.headers);
|
||||
{{/hasHeaderParams}}
|
||||
{{^hasHeaderParams}}
|
||||
if (contentTypeHeader) {
|
||||
fetchOptions.headers = {{#supportsES6}}Object.{{/supportsES6}}assign({}, contentTypeHeader, fetchOptions.headers);
|
||||
}
|
||||
{{/hasHeaderParams}}
|
||||
{{#authMethods}}
|
||||
// authentication ({{name}}) required
|
||||
{{#isApiKey}}
|
||||
{{#isKeyInHeader}}
|
||||
if (configuration.apiKey && configuration.apiKey.{{keyParamName}}) {
|
||||
fetchOptions.headers = {{#supportsES6}}Object.{{/supportsES6}}assign({
|
||||
"{{keyParamName}}": configuration.apiKey.{{keyParamName}},
|
||||
}, contentTypeHeader);
|
||||
}
|
||||
{{/isKeyInHeader}}
|
||||
{{#isKeyInQuery}}
|
||||
if (configuration.apiKey && configuration.apiKey.{{keyParamName}}) {
|
||||
urlObj.query = {{#supportsES6}}Object.{{/supportsES6}}assign({}, urlObj.query, {
|
||||
"{{keyParamName}}": configuration.apiKey.{{keyParamName}},
|
||||
});
|
||||
}
|
||||
{{/isKeyInQuery}}
|
||||
{{/isApiKey}}
|
||||
{{#isBasic}}
|
||||
// http basic authentication required
|
||||
if (configuration.username || configuration.password) {
|
||||
fetchOptions.headers = {{#supportsES6}}Object.{{/supportsES6}}assign({
|
||||
"Authorization": "Basic " + btoa(configuration.username + ":" + configuration.password),
|
||||
}, contentTypeHeader);
|
||||
}
|
||||
{{/isBasic}}
|
||||
{{#isOAuth}}
|
||||
// oauth required
|
||||
if (configuration.accessToken) {
|
||||
fetchOptions.headers = {{#supportsES6}}Object.{{/supportsES6}}assign({
|
||||
"Authorization": "Bearer " + configuration.accessToken,
|
||||
}, contentTypeHeader);
|
||||
}
|
||||
{{/isOAuth}}
|
||||
{{/authMethods}}
|
||||
|
||||
return {
|
||||
url: url.format(urlObj),
|
||||
options: fetchOptions,
|
||||
};
|
||||
},
|
||||
{{/operation}}
|
||||
};
|
||||
|
||||
/**
|
||||
* {{classname}} - functional programming interface{{#description}}
|
||||
* {{&description}}{{/description}}
|
||||
*/
|
||||
export const {{classname}}Fp = {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
*/
|
||||
{{nickname}}({{#hasParams}}params: { {{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}; {{/allParams}} }, {{/hasParams}}{{#hasAuthMethods}}configuration: Configuration, {{/hasAuthMethods}}options: any = {}): (fetch: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}> {
|
||||
const fetchArgs = {{classname}}FetchParamCreator.{{nickname}}({{#hasParams}}params, {{/hasParams}}{{#hasAuthMethods}}configuration, {{/hasAuthMethods}}options);
|
||||
return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => {
|
||||
return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response{{#returnType}}.json(){{/returnType}};
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
});
|
||||
};
|
||||
},
|
||||
{{/operation}}
|
||||
};
|
||||
|
||||
/**
|
||||
* {{classname}} - object-oriented interface{{#description}}
|
||||
* {{&description}}{{/description}}
|
||||
*/
|
||||
export class {{classname}} extends BaseAPI {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
*/
|
||||
{{nickname}}({{#hasParams}}params: { {{#allParams}} {{paramName}}{{^required}}?{{/required}}: {{{dataType}}};{{/allParams}} }, {{/hasParams}}options: any = {}) {
|
||||
return {{classname}}Fp.{{nickname}}({{#hasParams}}params, {{/hasParams}}{{#hasAuthMethods}}this.configuration, {{/hasAuthMethods}}options)(this.fetch, this.basePath);
|
||||
}
|
||||
{{/operation}}
|
||||
};
|
||||
|
||||
/**
|
||||
* {{classname}} - factory interface{{#description}}
|
||||
* {{&description}}{{/description}}
|
||||
*/
|
||||
export const {{classname}}Factory = function (fetch?: FetchAPI, basePath?: string) {
|
||||
return {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{paramName}} {{description}}
|
||||
{{/allParams}}
|
||||
*/
|
||||
{{nickname}}({{#hasParams}}params: { {{#allParams}} {{paramName}}{{^required}}?{{/required}}: {{{dataType}}};{{/allParams}} }, {{/hasParams}}{{#hasAuthMethods}}configuration: Configuration, {{/hasAuthMethods}}options: any = {}) {
|
||||
return {{classname}}Fp.{{nickname}}({{#hasParams}}params, {{/hasParams}}{{#hasAuthMethods}}configuration, {{/hasAuthMethods}}options)(fetch, basePath);
|
||||
},
|
||||
{{/operation}}
|
||||
};
|
||||
};
|
||||
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
@ -1,12 +0,0 @@
|
||||
export class Configuration {
|
||||
apiKey: {
|
||||
{{#authMethods}}
|
||||
{{#isApiKey}}
|
||||
{{keyParamName}}: string;
|
||||
{{/isApiKey}}
|
||||
{{/authMethods}}
|
||||
};
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string;
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "{{#npmName}}{{{npmName}}}{{/npmName}}{{^npmName}}typescript-fetch-api{{/npmName}}",
|
||||
"version": "{{#npmVersion}}{{{npmVersion}}}{{/npmVersion}}{{^npmVersion}}0.0.0{{/npmVersion}}",
|
||||
"license": "Unlicense",
|
||||
"main": "./dist/api.js",
|
||||
"browser": "./dist/api.js",
|
||||
"typings": "./dist/api.d.ts",
|
||||
"dependencies": {
|
||||
{{^supportsES6}}"core-js": "^2.4.0",
|
||||
{{/supportsES6}}"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"scripts" : {
|
||||
"prepublish" : "typings install && tsc",
|
||||
"test": "tslint api.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tslint": "^3.15.1",
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^1.0.4"
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
{
|
||||
"jsRules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-eval": true,
|
||||
"no-internal-module": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"no-var-keyword": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"version": false,
|
||||
"dependencies": {},
|
||||
"globalDependencies": { {{^supportsES6}}
|
||||
"core-js": "registry:dt/core-js#0.0.0+20160317120654",{{/supportsES6}}
|
||||
"node": "registry:dt/node#4.0.0+20160423143914",
|
||||
"isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
## {{npmName}}@{{npmVersion}}
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
Environment
|
||||
* Node.js
|
||||
* Webpack
|
||||
* Browserify
|
||||
|
||||
Language level
|
||||
* ES5 - you must have a Promises/A+ library installed
|
||||
* ES6
|
||||
|
||||
Module system
|
||||
* CommonJS
|
||||
* ES6 module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||
|
||||
### Building
|
||||
|
||||
To build an compile the typescript sources to javascript use:
|
||||
```
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Publishing
|
||||
|
||||
First build the package than run ```npm publish```
|
||||
|
||||
### Consuming
|
||||
|
||||
navigate to the folder of your consuming project and run one of next commando's.
|
||||
|
||||
_published:_
|
||||
|
||||
```
|
||||
npm install {{npmName}}@{{npmVersion}} --save
|
||||
```
|
||||
|
||||
_unPublished (not recommended):_
|
||||
|
||||
```
|
||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
@ -0,0 +1,325 @@
|
||||
// tslint:disable
|
||||
{{>licenseInfo}}
|
||||
|
||||
import * as url from "url";
|
||||
import * as isomorphicFetch from "isomorphic-fetch";
|
||||
import { Configuration } from "./configuration";
|
||||
|
||||
const BASE_PATH = "{{{basePath}}}".replace(/\/+$/, "");
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
*/
|
||||
export const COLLECTION_FORMATS = {
|
||||
csv: ",",
|
||||
ssv: " ",
|
||||
tsv: "\t",
|
||||
pipes: "|",
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface FetchAPI
|
||||
*/
|
||||
export interface FetchAPI {
|
||||
(url: string, init?: any): Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface FetchArgs
|
||||
*/
|
||||
export interface FetchArgs {
|
||||
url: string;
|
||||
options: any;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class BaseAPI
|
||||
*/
|
||||
export class BaseAPI {
|
||||
protected configuration: Configuration;
|
||||
|
||||
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected fetch: FetchAPI = isomorphicFetch) {
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
this.basePath = configuration.basePath || this.basePath;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class RequiredError
|
||||
* @extends {Error}
|
||||
*/
|
||||
export class RequiredError extends Error {
|
||||
name: "RequiredError"
|
||||
constructor(public field: string, msg?: string) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
{{#models}}
|
||||
{{#model}}{{#isEnum}}{{>modelEnum}}{{/isEnum}}{{^isEnum}}{{>modelGeneric}}{{/isEnum}}{{/model}}
|
||||
{{/models}}
|
||||
{{#apiInfo}}{{#apis}}{{#operations}}
|
||||
/**
|
||||
* {{classname}} - fetch parameter creator{{#description}}
|
||||
* {{&description}}{{/description}}
|
||||
* @export
|
||||
*/
|
||||
export const {{classname}}FetchParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
|
||||
{{/allParams}}
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options: any = {}): FetchArgs {
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
// verify required parameter '{{paramName}}' is not null or undefined
|
||||
if ({{paramName}} === null || {{paramName}} === undefined) {
|
||||
throw new RequiredError('{{paramName}}','Required parameter {{paramName}} was null or undefined when calling {{nickname}}.');
|
||||
}
|
||||
{{/required}}
|
||||
{{/allParams}}
|
||||
const path = `{{{path}}}`{{#pathParams}}
|
||||
.replace(`{${"{{baseName}}"}}`, String({{paramName}})){{/pathParams}};
|
||||
const urlObj = url.parse(path, true);
|
||||
const requestOptions = Object.assign({ method: '{{httpMethod}}' }, options);
|
||||
const headerParameter = {} as any;
|
||||
const queryParameter = {} as any;
|
||||
{{#hasFormParams}}
|
||||
const formParams = new url.URLSearchParams();
|
||||
{{/hasFormParams}}
|
||||
|
||||
{{#authMethods}}
|
||||
// authentication {{name}} required
|
||||
{{#isApiKey}}
|
||||
{{#isKeyInHeader}}
|
||||
if (configuration && configuration.apiKey) {
|
||||
const apiKeyValue = typeof configuration.apiKey === 'function'
|
||||
? configuration.apiKey("{{keyParamName}}")
|
||||
: configuration.apiKey;
|
||||
headerParameter["{{keyParamName}}"] = apiKeyValue;
|
||||
}
|
||||
{{/isKeyInHeader}}
|
||||
{{#isKeyInQuery}}
|
||||
if (configuration && configuration.apiKey) {
|
||||
const apiKeyValue = typeof configuration.apiKey === 'function'
|
||||
? configuration.apiKey("{{keyParamName}}")
|
||||
: configuration.apiKey;
|
||||
queryParameter["{{keyParamName}}"] = apiKeyValue;
|
||||
}
|
||||
{{/isKeyInQuery}}
|
||||
{{/isApiKey}}
|
||||
{{#isBasic}}
|
||||
// http basic authentication required
|
||||
if (configuration && (configuration.username || configuration.password)) {
|
||||
headerParameter["Authorization"] = "Basic " + btoa(configuration.username + ":" + configuration.password);
|
||||
}
|
||||
{{/isBasic}}
|
||||
{{#isOAuth}}
|
||||
// oauth required
|
||||
if (configuration && configuration.accessToken) {
|
||||
const accessTokenValue = typeof configuration.accessToken === 'function'
|
||||
? configuration.accessToken("{{name}}", [{{#scopes}}"{{{scope}}}"{{^-last}}, {{/-last}}{{/scopes}}])
|
||||
: configuration.accessToken;
|
||||
headerParameter["Authorization"] = "Bearer " + accessTokenValue;
|
||||
}
|
||||
{{/isOAuth}}
|
||||
|
||||
{{/authMethods}}
|
||||
{{#queryParams}}
|
||||
{{#isListContainer}}
|
||||
if ({{paramName}}) {
|
||||
{{#isCollectionFormatMulti}}
|
||||
queryParameter['{{baseName}}'] = {{paramName}};
|
||||
{{/isCollectionFormatMulti}}
|
||||
{{^isCollectionFormatMulti}}
|
||||
queryParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
|
||||
{{/isCollectionFormatMulti}}
|
||||
}
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
if ({{paramName}} !== undefined) {
|
||||
{{#isDateTime}}
|
||||
queryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
|
||||
{{/isDateTime}}
|
||||
{{^isDateTime}}
|
||||
{{#isDate}}
|
||||
queryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
|
||||
{{/isDate}}
|
||||
{{^isDate}}
|
||||
queryParameter['{{baseName}}'] = {{paramName}};
|
||||
{{/isDate}}
|
||||
{{/isDateTime}}
|
||||
}
|
||||
{{/isListContainer}}
|
||||
|
||||
{{/queryParams}}
|
||||
{{#headerParams}}
|
||||
{{#isListContainer}}
|
||||
if ({{paramName}}) {
|
||||
headerParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
|
||||
}
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
if ({{paramName}} !== undefined && {{paramName}} !== null) {
|
||||
headerParameter['{{baseName}}'] = String({{paramName}});
|
||||
}
|
||||
{{/isListContainer}}
|
||||
|
||||
{{/headerParams}}
|
||||
{{#formParams}}
|
||||
{{#isListContainer}}
|
||||
if ({{paramName}}) {
|
||||
{{#isCollectionFormatMulti}}
|
||||
{{paramName}}.forEach((element) => {
|
||||
formParams.append('{{baseName}}', element as any);
|
||||
})
|
||||
{{/isCollectionFormatMulti}}
|
||||
{{^isCollectionFormatMulti}}
|
||||
formParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]));
|
||||
{{/isCollectionFormatMulti}}
|
||||
}
|
||||
{{/isListContainer}}
|
||||
{{^isListContainer}}
|
||||
if ({{paramName}} !== undefined) {
|
||||
formParams.set('{{baseName}}', {{paramName}} as any);
|
||||
}
|
||||
{{/isListContainer}}
|
||||
|
||||
{{/formParams}}
|
||||
{{#hasFormParams}}
|
||||
headerParameter['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
{{/hasFormParams}}
|
||||
{{#bodyParam}}
|
||||
headerParameter['Content-Type'] = 'application/json';
|
||||
|
||||
{{/bodyParam}}
|
||||
urlObj.query = Object.assign({}, urlObj.query, queryParameter, options.query);
|
||||
// fix override query string Detail: https://stackoverflow.com/a/7517673/1077943
|
||||
delete urlObj.search;
|
||||
requestOptions.headers = Object.assign({}, headerParameter, options.headers);
|
||||
{{#hasFormParams}}
|
||||
requestOptions.body = formParams.toString();
|
||||
{{/hasFormParams}}
|
||||
{{#bodyParam}}
|
||||
requestOptions.body = JSON.stringify({{paramName}} || {});
|
||||
{{/bodyParam}}
|
||||
|
||||
return {
|
||||
url: url.format(urlObj),
|
||||
options: requestOptions,
|
||||
};
|
||||
},
|
||||
{{/operation}}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* {{classname}} - functional programming interface{{#description}}
|
||||
* {{{description}}}{{/description}}
|
||||
* @export
|
||||
*/
|
||||
export const {{classname}}Fp = function(configuration?: Configuration) {
|
||||
return {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
|
||||
{{/allParams}}
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}any{{/returnType}}> {
|
||||
const fetchArgs = {{classname}}FetchParamCreator(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options);
|
||||
return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => {
|
||||
return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
return response{{#returnType}}.json(){{/returnType}};
|
||||
} else {
|
||||
throw response;
|
||||
}
|
||||
});
|
||||
};
|
||||
},
|
||||
{{/operation}}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* {{classname}} - factory interface{{#description}}
|
||||
* {{&description}}{{/description}}
|
||||
* @export
|
||||
*/
|
||||
export const {{classname}}Factory = function (configuration?: Configuration, fetch?: FetchAPI, basePath?: string) {
|
||||
return {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{=<% %>=}}{<%dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
|
||||
{{/allParams}}
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
|
||||
return {{classname}}Fp(configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(fetch, basePath);
|
||||
},
|
||||
{{/operation}}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* {{classname}} - object-oriented interface{{#description}}
|
||||
* {{{description}}}{{/description}}
|
||||
* @export
|
||||
* @class {{classname}}
|
||||
* @extends {BaseAPI}
|
||||
*/
|
||||
export class {{classname}} extends BaseAPI {
|
||||
{{#operation}}
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
* @summary {{&summary}}
|
||||
{{/summary}}
|
||||
{{#allParams}}
|
||||
* @param {{=<% %>=}}{<%%dataType%%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
|
||||
{{/allParams}}
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof {{classname}}
|
||||
*/
|
||||
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}options?: any) {
|
||||
return {{classname}}Fp(this.configuration).{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}}options)(this.fetch, this.basePath);
|
||||
}
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
{{/operations}}{{/apis}}{{/apiInfo}}
|
@ -0,0 +1,55 @@
|
||||
// tslint:disable
|
||||
{{>licenseInfo}}
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | ((name: string) => string);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
basePath?: string;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | ((name: string) => string);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
}
|
||||
}
|
@ -49,4 +49,3 @@ git pull origin master
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
@ -0,0 +1,5 @@
|
||||
// tslint:disable
|
||||
{{>licenseInfo}}
|
||||
|
||||
export * from "./api";
|
||||
export * from "./configuration";
|
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* {{{description}}}
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum {{classname}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
/**
|
||||
* {{{description}}}
|
||||
* @export
|
||||
* @interface {{classname}}
|
||||
*/
|
||||
export interface {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
|
||||
{{#additionalPropertiesType}}
|
||||
[key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}};
|
||||
|
||||
{{/additionalPropertiesType}}
|
||||
{{#vars}}
|
||||
/**
|
||||
* {{{description}}}
|
||||
* @type {{=<% %>=}}{<%datatype%>}<%={{ }}=%>
|
||||
* @memberof {{classname}}
|
||||
*/
|
||||
{{name}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
|
||||
{{/vars}}
|
||||
}{{#hasEnums}}
|
||||
|
||||
/**
|
||||
* @export
|
||||
* @namespace {{classname}}
|
||||
*/
|
||||
export namespace {{classname}} {
|
||||
{{#vars}}
|
||||
{{#isEnum}}
|
||||
/**
|
||||
* @export
|
||||
* @enum {string}
|
||||
*/
|
||||
export enum {{enumName}} {
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{{name}}} = <any> {{{value}}}{{^-last}},{{/-last}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
}
|
||||
{{/isEnum}}
|
||||
{{/vars}}
|
||||
}{{/hasEnums}}
|
@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "{{npmName}}",
|
||||
"version": "{{npmVersion}}",
|
||||
"description": "swagger client for {{npmName}}",
|
||||
"author": "Swagger Codegen Contributors",
|
||||
"keywords": [
|
||||
"fetch",
|
||||
"typescript",
|
||||
"swagger-client",
|
||||
"{{npmName}}"
|
||||
],
|
||||
"license": "Unlicense",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc --outDir dist/",
|
||||
"postinstall": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
"@types/node": "^8.0.9",
|
||||
"typescript": "^2.0"
|
||||
}{{#npmRepository}},{{/npmRepository}}
|
||||
{{#npmRepository}}
|
||||
"publishConfig":{
|
||||
"registry":"{{npmRepository}}"
|
||||
}
|
||||
{{/npmRepository}}
|
||||
}
|
@ -5,13 +5,15 @@
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "."
|
||||
"rootDir": "."{{^supportsES6}},
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
]
|
||||
{{/supportsES6}}
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
"node_modules"
|
||||
]
|
||||
}
|
@ -13,6 +13,7 @@ public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
|
||||
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||
private static final String NMP_NAME = "npmName";
|
||||
private static final String NMP_VERSION = "1.0.0";
|
||||
private static final String NPM_REPOSITORY = "https://registry.npmjs.org";
|
||||
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||
|
||||
|
||||
@ -30,6 +31,8 @@ public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.SUPPORTS_ES6, String.valueOf(SUPPORTS_ES6_VALUE))
|
||||
.put(TypeScriptFetchClientCodegen.NPM_NAME, NMP_NAME)
|
||||
.put(TypeScriptFetchClientCodegen.NPM_VERSION, NMP_VERSION)
|
||||
.put(TypeScriptFetchClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
|
||||
.put(TypeScriptFetchClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
|
||||
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||
.build();
|
||||
}
|
||||
|
@ -0,0 +1 @@
|
||||
2.3.0-SNAPSHOT
|
@ -1,3 +1,4 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
|
||||
@ -10,87 +11,137 @@
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
import * as querystring from "querystring";
|
||||
|
||||
import * as url from "url";
|
||||
|
||||
import * as isomorphicFetch from "isomorphic-fetch";
|
||||
import * as assign from "core-js/library/fn/object/assign";
|
||||
|
||||
import { Configuration } from "./configuration";
|
||||
|
||||
interface Dictionary<T> { [index: string]: T; }
|
||||
export interface FetchAPI { (url: string, init?: any): Promise<any>; }
|
||||
|
||||
const BASE_PATH = "https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r".replace(/\/+$/, "");
|
||||
|
||||
const COLLECTION_FORMATS = {
|
||||
csv: ",",
|
||||
ssv: " ",
|
||||
tsv: "\t",
|
||||
pipes: "|",
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface FetchAPI
|
||||
*/
|
||||
export interface FetchAPI {
|
||||
(url: string, init?: any): Promise<any>;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @interface FetchArgs
|
||||
*/
|
||||
export interface FetchArgs {
|
||||
url: string;
|
||||
options: any;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class BaseAPI
|
||||
*/
|
||||
export class BaseAPI {
|
||||
basePath: string;
|
||||
fetch: FetchAPI;
|
||||
public configuration: Configuration;
|
||||
protected configuration: Configuration;
|
||||
|
||||
constructor(fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH, configuration: Configuration = new Configuration()) {
|
||||
this.basePath = basePath;
|
||||
this.fetch = fetch;
|
||||
constructor(configuration?: Configuration, protected basePath: string = BASE_PATH, protected fetch: FetchAPI = isomorphicFetch) {
|
||||
if (configuration) {
|
||||
this.configuration = configuration;
|
||||
this.basePath = configuration.basePath || this.basePath;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @export
|
||||
* @class RequiredError
|
||||
* @extends {Error}
|
||||
*/
|
||||
export class RequiredError extends Error {
|
||||
name: "RequiredError"
|
||||
constructor(public field: string, msg?: string) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Model for testing reserved words *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @export
|
||||
* @interface ModelReturn
|
||||
*/
|
||||
export interface ModelReturn {
|
||||
/**
|
||||
* property description *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @type {number}
|
||||
* @memberof ModelReturn
|
||||
*/
|
||||
"return"?: number;
|
||||
return?: number;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* FakeApi - fetch parameter creator
|
||||
* @export
|
||||
*/
|
||||
export const FakeApiFetchParamCreator = {
|
||||
export const FakeApiFetchParamCreator = function (configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
*
|
||||
* @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {string} [test code inject * ' " =end rn n r] To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
testCodeInjectEndRnNR(params: { test code inject * ' " =end rn n r?: string; }, options: any = {}): FetchArgs {
|
||||
const baseUrl = `/fake`;
|
||||
let urlObj = url.parse(baseUrl, true);
|
||||
let fetchOptions: RequestInit = assign({}, { method: "PUT" }, options);
|
||||
testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, options: any = {}): FetchArgs {
|
||||
const path = `/fake`;
|
||||
const urlObj = url.parse(path, true);
|
||||
const requestOptions = Object.assign({ method: 'PUT' }, options);
|
||||
const headerParameter = {} as any;
|
||||
const queryParameter = {} as any;
|
||||
const formParams = new url.URLSearchParams();
|
||||
|
||||
let contentTypeHeader: Dictionary<string> = {};
|
||||
contentTypeHeader = { "Content-Type": "application/x-www-form-urlencoded" };
|
||||
fetchOptions.body = querystring.stringify({
|
||||
"test code inject */ ' " =end -- \r\n \n \r": params["test code inject * ' " =end rn n r"],
|
||||
});
|
||||
if (contentTypeHeader) {
|
||||
fetchOptions.headers = assign({}, contentTypeHeader, fetchOptions.headers);
|
||||
if (test code inject * ' " =end rn n r !== undefined) {
|
||||
formParams.set('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r as any);
|
||||
}
|
||||
|
||||
headerParameter['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
|
||||
urlObj.query = Object.assign({}, urlObj.query, queryParameter, options.query);
|
||||
requestOptions.headers = Object.assign({}, headerParameter, options.headers);
|
||||
requestOptions.body = formParams.toString();
|
||||
|
||||
return {
|
||||
url: url.format(urlObj),
|
||||
options: fetchOptions,
|
||||
options: requestOptions,
|
||||
};
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* FakeApi - functional programming interface
|
||||
* @export
|
||||
*/
|
||||
export const FakeApiFp = {
|
||||
export const FakeApiFp = function(configuration?: Configuration) {
|
||||
return {
|
||||
/**
|
||||
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
*
|
||||
* @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {string} [test code inject * ' " =end rn n r] To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
testCodeInjectEndRnNR(params: { test code inject * ' " =end rn n r?: string; }, options: any = {}): (fetch: FetchAPI, basePath?: string) => Promise<any> {
|
||||
const fetchArgs = FakeApiFetchParamCreator.testCodeInjectEndRnNR(params, options);
|
||||
testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, options?: any): (fetch?: FetchAPI, basePath?: string) => Promise<any> {
|
||||
const fetchArgs = FakeApiFetchParamCreator(configuration).testCodeInjectEndRnNR(test code inject * ' " =end rn n r, options);
|
||||
return (fetch: FetchAPI = isomorphicFetch, basePath: string = BASE_PATH) => {
|
||||
return fetch(basePath + fetchArgs.url, fetchArgs.options).then((response) => {
|
||||
if (response.status >= 200 && response.status < 300) {
|
||||
@ -101,33 +152,46 @@ export const FakeApiFp = {
|
||||
});
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* FakeApi - object-oriented interface
|
||||
*/
|
||||
export class FakeApi extends BaseAPI {
|
||||
/**
|
||||
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
*/
|
||||
testCodeInjectEndRnNR(params: { test code inject * ' " =end rn n r?: string; }, options: any = {}) {
|
||||
return FakeApiFp.testCodeInjectEndRnNR(params, options)(this.fetch, this.basePath);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* FakeApi - factory interface
|
||||
* @export
|
||||
*/
|
||||
export const FakeApiFactory = function (fetch?: FetchAPI, basePath?: string) {
|
||||
export const FakeApiFactory = function (configuration?: Configuration, fetch?: FetchAPI, basePath?: string) {
|
||||
return {
|
||||
/**
|
||||
* To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
*
|
||||
* @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {string} [test code inject * ' " =end rn n r] To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
*/
|
||||
testCodeInjectEndRnNR(params: { test code inject * ' " =end rn n r?: string; }, options: any = {}) {
|
||||
return FakeApiFp.testCodeInjectEndRnNR(params, options)(fetch, basePath);
|
||||
testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, options?: any) {
|
||||
return FakeApiFp(configuration).testCodeInjectEndRnNR(test code inject * ' " =end rn n r, options)(fetch, basePath);
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* FakeApi - object-oriented interface
|
||||
* @export
|
||||
* @class FakeApi
|
||||
* @extends {BaseAPI}
|
||||
*/
|
||||
export class FakeApi extends BaseAPI {
|
||||
/**
|
||||
*
|
||||
* @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {} [test code inject * ' " =end rn n r] To test code injection *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* @param {*} [options] Override http request option.
|
||||
* @throws {RequiredError}
|
||||
* @memberof FakeApi
|
||||
*/
|
||||
public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, options?: any) {
|
||||
return FakeApiFp(this.configuration).testCodeInjectEndRnNR(test code inject * ' " =end rn n r, options)(this.fetch, this.basePath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,66 @@
|
||||
export class Configuration {
|
||||
apiKey: {
|
||||
api_key */ ' " =end -- \r\n \n \r: string;
|
||||
};
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string;
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | ((name: string) => string);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
basePath?: string;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | ((name: string) => string);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
}
|
||||
}
|
@ -49,4 +49,3 @@ git pull origin master
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\ *_/ ' \" =end --
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0 *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
* Contact: apiteam@swagger.io *_/ ' \" =end -- \\r\\n \\n \\r
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export * from "./api";
|
||||
export * from "./configuration";
|
@ -1,54 +0,0 @@
|
||||
# TypeScript-Fetch
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
Environment
|
||||
* Node.js
|
||||
* Webpack
|
||||
* Browserify
|
||||
|
||||
Language level
|
||||
* ES5 - you must have a Promises/A+ library installed
|
||||
* ES6
|
||||
|
||||
Module system
|
||||
* CommonJS
|
||||
* ES6 module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||
|
||||
### Installation ###
|
||||
|
||||
`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`.
|
||||
|
||||
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`.
|
||||
|
||||
#### NPM ####
|
||||
You may publish the module to NPM. In this case, you would be able to install the module as any other NPM module. It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
|
||||
|
||||
You can also use `npm link` to link the module. However, this would not modify `package.json` of the installing project, as such you would need to relink every time you deploy that project.
|
||||
|
||||
You can also directly install the module using `npm install file_path`. If you do `npm install file_path --save`, NPM will save relative path to `package.json`. In this case, `npm install` and `npm shrinkwrap` may misbehave. You would need to manually edit `package.json` and replace it with absolute path.
|
||||
|
||||
Regardless of which method you deployed your NPM module, the ES6 module syntaxes are as follows:
|
||||
```
|
||||
import * as localName from 'npmName';
|
||||
import {operationId} from 'npmName';
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('npmName');
|
||||
```
|
||||
|
||||
#### Direct copy/symlink ####
|
||||
You may also simply copy or symlink the generated module into a directory under your project. The syntax of this is as follows:
|
||||
|
||||
With ES6 module syntax, the following syntaxes are supported:
|
||||
```
|
||||
import * as localName from './symlinkDir';
|
||||
import {operationId} from './symlinkDir';
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('./symlinkDir')';
|
||||
```
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,66 @@
|
||||
export class Configuration {
|
||||
apiKey: {
|
||||
api_key: string;
|
||||
};
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string;
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | ((name: string) => string);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
basePath?: string;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | ((name: string) => string);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
}
|
||||
}
|
@ -49,4 +49,3 @@ git pull origin master
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export * from "./api";
|
||||
export * from "./configuration";
|
@ -1,21 +0,0 @@
|
||||
{
|
||||
"name": "typescript-fetch-api",
|
||||
"version": "0.0.0",
|
||||
"license": "Unlicense",
|
||||
"main": "./dist/api.js",
|
||||
"browser": "./dist/api.js",
|
||||
"typings": "./dist/api.d.ts",
|
||||
"dependencies": {
|
||||
"core-js": "^2.4.0",
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"scripts" : {
|
||||
"prepublish" : "typings install && tsc",
|
||||
"test": "tslint api.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tslint": "^3.15.1",
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^1.0.4"
|
||||
}
|
||||
}
|
@ -21,39 +21,6 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>npm-install</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>install</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>npm-test</id>
|
||||
<phase>integration-test</phase>
|
||||
<goals>
|
||||
<goal>exec</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<executable>npm</executable>
|
||||
<arguments>
|
||||
<argument>test</argument>
|
||||
</arguments>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@ -1,17 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "."
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
]
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
{
|
||||
"jsRules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-eval": true,
|
||||
"no-internal-module": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"no-var-keyword": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"version": false,
|
||||
"dependencies": {},
|
||||
"globalDependencies": {
|
||||
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
|
||||
"node": "registry:dt/node#4.0.0+20160423143914",
|
||||
"isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
# TypeScript-Fetch
|
||||
## @swagger/typescript-fetch-petstore@1.0.0
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
@ -17,38 +17,29 @@ Module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||
|
||||
### Installation ###
|
||||
### Building
|
||||
|
||||
`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`.
|
||||
|
||||
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`.
|
||||
|
||||
#### NPM ####
|
||||
You may publish the module to NPM. In this case, you would be able to install the module as any other NPM module. It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
|
||||
|
||||
You can also use `npm link` to link the module. However, this would not modify `package.json` of the installing project, as such you would need to relink every time you deploy that project.
|
||||
|
||||
You can also directly install the module using `npm install file_path`. If you do `npm install file_path --save`, NPM will save relative path to `package.json`. In this case, `npm install` and `npm shrinkwrap` may misbehave. You would need to manually edit `package.json` and replace it with absolute path.
|
||||
|
||||
Regardless of which method you deployed your NPM module, the ES6 module syntaxes are as follows:
|
||||
To build an compile the typescript sources to javascript use:
|
||||
```
|
||||
import * as localName from 'npmName';
|
||||
import {operationId} from 'npmName';
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('npmName');
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
#### Direct copy/symlink ####
|
||||
You may also simply copy or symlink the generated module into a directory under your project. The syntax of this is as follows:
|
||||
### Publishing
|
||||
|
||||
First build the package than run ```npm publish```
|
||||
|
||||
### Consuming
|
||||
|
||||
navigate to the folder of your consuming project and run one of next commando's.
|
||||
|
||||
_published:_
|
||||
|
||||
With ES6 module syntax, the following syntaxes are supported:
|
||||
```
|
||||
import * as localName from './symlinkDir';
|
||||
import {operationId} from './symlinkDir';
|
||||
npm install @swagger/typescript-fetch-petstore@1.0.0 --save
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('./symlinkDir')';
|
||||
|
||||
_unPublished (not recommended):_
|
||||
|
||||
```
|
||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,66 @@
|
||||
export class Configuration {
|
||||
apiKey: {
|
||||
api_key: string;
|
||||
};
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string;
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | ((name: string) => string);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
basePath?: string;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | ((name: string) => string);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
}
|
||||
}
|
@ -49,4 +49,3 @@ git pull origin master
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export * from "./api";
|
||||
export * from "./configuration";
|
@ -1,20 +1,30 @@
|
||||
{
|
||||
"name": "typescript-fetch-api",
|
||||
"version": "0.0.0",
|
||||
"name": "@swagger/typescript-fetch-petstore",
|
||||
"version": "1.0.0",
|
||||
"description": "swagger client for @swagger/typescript-fetch-petstore",
|
||||
"author": "Swagger Codegen Contributors",
|
||||
"keywords": [
|
||||
"fetch",
|
||||
"typescript",
|
||||
"swagger-client",
|
||||
"@swagger/typescript-fetch-petstore"
|
||||
],
|
||||
"license": "Unlicense",
|
||||
"main": "./dist/api.js",
|
||||
"browser": "./dist/api.js",
|
||||
"typings": "./dist/api.d.ts",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc --outDir dist/",
|
||||
"postinstall": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"scripts" : {
|
||||
"prepublish" : "typings install && tsc",
|
||||
"test": "tslint api.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tslint": "^3.15.1",
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^1.0.4"
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
"@types/node": "^8.0.9",
|
||||
"typescript": "^2.0"
|
||||
},
|
||||
"publishConfig":{
|
||||
"registry":"https://skimdb.npmjs.com/registry"
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,9 @@
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "."
|
||||
},
|
||||
"rootDir": "." },
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
@ -1,101 +0,0 @@
|
||||
{
|
||||
"jsRules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-eval": true,
|
||||
"no-internal-module": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"no-var-keyword": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"version": false,
|
||||
"dependencies": {},
|
||||
"globalDependencies": {
|
||||
"node": "registry:dt/node#4.0.0+20160423143914",
|
||||
"isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
# TypeScript-Fetch
|
||||
## @swagger/typescript-fetch-petstore@1.0.0
|
||||
|
||||
This generator creates TypeScript/JavaScript client that utilizes [Fetch API](https://fetch.spec.whatwg.org/). The generated Node module can be used in the following environments:
|
||||
|
||||
@ -17,38 +17,29 @@ Module system
|
||||
|
||||
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
|
||||
|
||||
### Installation ###
|
||||
### Building
|
||||
|
||||
`swagger-codegen` does not generate JavaScript directly. The generated Node module comes with `package.json` that bundles `typescript` and `typings` so it can self-compile during `prepublish` stage. The should be run automatically during `npm install` or `npm publish`.
|
||||
|
||||
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`.
|
||||
|
||||
#### NPM ####
|
||||
You may publish the module to NPM. In this case, you would be able to install the module as any other NPM module. It maybe useful to use [scoped packages](https://docs.npmjs.com/misc/scope).
|
||||
|
||||
You can also use `npm link` to link the module. However, this would not modify `package.json` of the installing project, as such you would need to relink every time you deploy that project.
|
||||
|
||||
You can also directly install the module using `npm install file_path`. If you do `npm install file_path --save`, NPM will save relative path to `package.json`. In this case, `npm install` and `npm shrinkwrap` may misbehave. You would need to manually edit `package.json` and replace it with absolute path.
|
||||
|
||||
Regardless of which method you deployed your NPM module, the ES6 module syntaxes are as follows:
|
||||
To build an compile the typescript sources to javascript use:
|
||||
```
|
||||
import * as localName from 'npmName';
|
||||
import {operationId} from 'npmName';
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('npmName');
|
||||
npm install
|
||||
npm run build
|
||||
```
|
||||
|
||||
#### Direct copy/symlink ####
|
||||
You may also simply copy or symlink the generated module into a directory under your project. The syntax of this is as follows:
|
||||
### Publishing
|
||||
|
||||
First build the package than run ```npm publish```
|
||||
|
||||
### Consuming
|
||||
|
||||
navigate to the folder of your consuming project and run one of next commando's.
|
||||
|
||||
_published:_
|
||||
|
||||
With ES6 module syntax, the following syntaxes are supported:
|
||||
```
|
||||
import * as localName from './symlinkDir';
|
||||
import {operationId} from './symlinkDir';
|
||||
npm install @swagger/typescript-fetch-petstore@1.0.0 --save
|
||||
```
|
||||
The CommonJS syntax is as follows:
|
||||
```
|
||||
import localName = require('./symlinkDir')';
|
||||
|
||||
_unPublished (not recommended):_
|
||||
|
||||
```
|
||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,66 @@
|
||||
export class Configuration {
|
||||
apiKey: {
|
||||
api_key: string;
|
||||
};
|
||||
username: string;
|
||||
password: string;
|
||||
accessToken: string;
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export interface ConfigurationParameters {
|
||||
apiKey?: string | ((name: string) => string);
|
||||
username?: string;
|
||||
password?: string;
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
basePath?: string;
|
||||
}
|
||||
|
||||
export class Configuration {
|
||||
/**
|
||||
* parameter for apiKey security
|
||||
* @param name security name
|
||||
* @memberof Configuration
|
||||
*/
|
||||
apiKey?: string | ((name: string) => string);
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
username?: string;
|
||||
/**
|
||||
* parameter for basic security
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
password?: string;
|
||||
/**
|
||||
* parameter for oauth2 security
|
||||
* @param name security name
|
||||
* @param scopes oauth2 scope
|
||||
* @memberof Configuration
|
||||
*/
|
||||
accessToken?: string | ((name: string, scopes?: string[]) => string);
|
||||
/**
|
||||
* override base path
|
||||
*
|
||||
* @type {string}
|
||||
* @memberof Configuration
|
||||
*/
|
||||
basePath?: string;
|
||||
|
||||
constructor(param: ConfigurationParameters = {}) {
|
||||
this.apiKey = param.apiKey;
|
||||
this.username = param.username;
|
||||
this.password = param.password;
|
||||
this.accessToken = param.accessToken;
|
||||
this.basePath = param.basePath;
|
||||
}
|
||||
}
|
@ -49,4 +49,3 @@ git pull origin master
|
||||
# Pushes (Forces) the changes in the local repository up to the remote repository
|
||||
echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git"
|
||||
git push origin master 2>&1 | grep -v 'To https'
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
// tslint:disable
|
||||
/**
|
||||
* Swagger Petstore
|
||||
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* Contact: apiteam@swagger.io
|
||||
*
|
||||
* NOTE: This class is auto generated by the swagger code generator program.
|
||||
* https://github.com/swagger-api/swagger-codegen.git
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
export * from "./api";
|
||||
export * from "./configuration";
|
@ -1,21 +1,30 @@
|
||||
{
|
||||
"name": "@swagger/typescript-fetch-petstore",
|
||||
"version": "0.0.1",
|
||||
"version": "1.0.0",
|
||||
"description": "swagger client for @swagger/typescript-fetch-petstore",
|
||||
"author": "Swagger Codegen Contributors",
|
||||
"keywords": [
|
||||
"fetch",
|
||||
"typescript",
|
||||
"swagger-client",
|
||||
"@swagger/typescript-fetch-petstore"
|
||||
],
|
||||
"license": "Unlicense",
|
||||
"main": "./dist/api.js",
|
||||
"browser": "./dist/api.js",
|
||||
"typings": "./dist/api.d.ts",
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"scripts" : {
|
||||
"build": "tsc --outDir dist/",
|
||||
"postinstall": "npm run build"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^2.4.0",
|
||||
"isomorphic-fetch": "^2.2.1"
|
||||
},
|
||||
"scripts" : {
|
||||
"prepublish" : "typings install && tsc",
|
||||
"test": "tslint api.ts"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tslint": "^3.15.1",
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^1.0.4"
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
"@types/node": "^8.0.9",
|
||||
"typescript": "^2.0"
|
||||
},
|
||||
"publishConfig":{
|
||||
"registry":"https://skimdb.npmjs.com/registry"
|
||||
}
|
||||
}
|
||||
|
@ -5,13 +5,14 @@
|
||||
"module": "commonjs",
|
||||
"noImplicitAny": true,
|
||||
"outDir": "dist",
|
||||
"rootDir": "."
|
||||
"rootDir": ".",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"dist",
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
|
@ -1,101 +0,0 @@
|
||||
{
|
||||
"jsRules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-duplicate-variable": true,
|
||||
"no-eval": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
},
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"comment-format": [
|
||||
true,
|
||||
"check-space"
|
||||
],
|
||||
"indent": [
|
||||
true,
|
||||
"spaces"
|
||||
],
|
||||
"no-eval": true,
|
||||
"no-internal-module": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unsafe-finally": true,
|
||||
"no-var-keyword": true,
|
||||
"one-line": [
|
||||
true,
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
],
|
||||
"quotemark": [
|
||||
true,
|
||||
"double"
|
||||
],
|
||||
"semicolon": [
|
||||
true,
|
||||
"always"
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typedef-whitespace": [
|
||||
true,
|
||||
{
|
||||
"call-signature": "nospace",
|
||||
"index-signature": "nospace",
|
||||
"parameter": "nospace",
|
||||
"property-declaration": "nospace",
|
||||
"variable-declaration": "nospace"
|
||||
}
|
||||
],
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords"
|
||||
],
|
||||
"whitespace": [
|
||||
true,
|
||||
"check-branch",
|
||||
"check-decl",
|
||||
"check-operator",
|
||||
"check-separator",
|
||||
"check-type"
|
||||
]
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"version": false,
|
||||
"dependencies": {},
|
||||
"globalDependencies": {
|
||||
"core-js": "registry:dt/core-js#0.0.0+20160317120654",
|
||||
"node": "registry:dt/node#4.0.0+20160423143914",
|
||||
"isomorphic-fetch": "registry:dt/isomorphic-fetch#0.0.0+20160505171433"
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
|
||||
|
||||
"@types/isomorphic-fetch@0.0.34":
|
||||
version "0.0.34"
|
||||
resolved "https://registry.yarnpkg.com/@types/isomorphic-fetch/-/isomorphic-fetch-0.0.34.tgz#3c3483e606c041378438e951464f00e4e60706d6"
|
||||
|
||||
"@types/node@^8.0.9":
|
||||
version "8.0.17"
|
||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.0.17.tgz#677bc8c118cfb76013febb62ede1f31d2c7222a1"
|
||||
|
||||
encoding@^0.1.11:
|
||||
version "0.1.12"
|
||||
resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb"
|
||||
dependencies:
|
||||
iconv-lite "~0.4.13"
|
||||
|
||||
iconv-lite@~0.4.13:
|
||||
version "0.4.18"
|
||||
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.18.tgz#23d8656b16aae6742ac29732ea8f0336a4789cf2"
|
||||
|
||||
is-stream@^1.0.1:
|
||||
version "1.1.0"
|
||||
resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44"
|
||||
|
||||
isomorphic-fetch@^2.2.1:
|
||||
version "2.2.1"
|
||||
resolved "https://registry.yarnpkg.com/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz#611ae1acf14f5e81f729507472819fe9733558a9"
|
||||
dependencies:
|
||||
node-fetch "^1.0.1"
|
||||
whatwg-fetch ">=0.10.0"
|
||||
|
||||
node-fetch@^1.0.1:
|
||||
version "1.7.1"
|
||||
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.1.tgz#899cb3d0a3c92f952c47f1b876f4c8aeabd400d5"
|
||||
dependencies:
|
||||
encoding "^0.1.11"
|
||||
is-stream "^1.0.1"
|
||||
|
||||
typescript@^2.0:
|
||||
version "2.4.2"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844"
|
||||
|
||||
whatwg-fetch@>=0.10.0:
|
||||
version "2.0.3"
|
||||
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz#9c84ec2dcf68187ff00bc64e1274b442176e1c84"
|
3762
samples/client/petstore/typescript-fetch/tests/default/package-lock.json
generated
Normal file
3762
samples/client/petstore/typescript-fetch/tests/default/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,20 +1,29 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"chai": "^3.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^13.0.1",
|
||||
"ts-loader": "^0.8.2",
|
||||
"tsify": "^0.16.0",
|
||||
"typescript": "^1.8.10",
|
||||
"typings": "^1.0.4",
|
||||
"webpack": "^1.13.0"
|
||||
"@swagger/typescript-fetch-petstore": "file:../../builds/with-npm-version",
|
||||
"chai": "^4.1.0",
|
||||
"ts-node": "^3.3.0"
|
||||
},
|
||||
"scripts": {
|
||||
"prepublish": "./scripts/prepublish.sh",
|
||||
"pretest": "npm install mocha",
|
||||
"test": "mocha"
|
||||
"prepublish": "npm install ../../builds/with-npm-version && npm run build && npm run webpack && npm run browserify",
|
||||
"test": "mocha test/*.ts --compilers ts:ts-node/register --timeout 10000",
|
||||
"build": "tsc",
|
||||
"webpack": "webpack",
|
||||
"browserify": "browserify test -p [ tsify ] > ./dist/test.browserify-bundle.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.0.1",
|
||||
"@types/isomorphic-fetch": "0.0.34",
|
||||
"@types/mocha": "^2.2.41",
|
||||
"@types/node": "^8.0.14",
|
||||
"browserify": "^14.4.0",
|
||||
"mocha": "^3.4.2",
|
||||
"ts-loader": "^2.3.0",
|
||||
"tsify": "^3.0.1",
|
||||
"typescript": "^2.4.1",
|
||||
"typings": "^2.1.1",
|
||||
"webpack": "^1.13.0"
|
||||
},
|
||||
"name": "typescript-fetch-test",
|
||||
"version": "1.0.0",
|
||||
|
@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
npm install ../../builds/default
|
||||
typings install
|
||||
|
||||
# Build Node.js
|
||||
tsc
|
||||
|
||||
# Build Webpack
|
||||
webpack
|
||||
|
||||
# Build browserify
|
||||
browserify test -p [ tsify ] > ./dist/test.browserify-bundle.js
|
@ -1,5 +1,5 @@
|
||||
import {expect} from 'chai';
|
||||
import {PetApi, Pet, Category} from 'typescript-fetch-api';
|
||||
import { expect } from 'chai';
|
||||
import { PetApi, Pet, Category } from '@swagger/typescript-fetch-petstore';
|
||||
|
||||
describe('PetApi', () => {
|
||||
|
||||
@ -15,21 +15,21 @@ describe('PetApi', () => {
|
||||
});
|
||||
|
||||
it('should add and delete Pet', () => {
|
||||
return api.addPet({ body: fixture }, requestOptions).then(() => {
|
||||
return api.addPet(fixture, requestOptions).then(() => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get Pet by ID', () => {
|
||||
return api.getPetById({ petId: fixture.id }, requestOptions).then((result: Pet) => {
|
||||
return api.getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
return expect(result).to.deep.equal(fixture);
|
||||
});
|
||||
});
|
||||
|
||||
it('should update Pet by ID', () => {
|
||||
return api.getPetById({ petId: fixture.id }, requestOptions).then( (result: Pet) => {
|
||||
return api.getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
result.name = 'newname';
|
||||
return api.updatePet({ body: result }, requestOptions).then(() => {
|
||||
return api.getPetById({ petId: fixture.id }, requestOptions).then( (result: Pet) => {
|
||||
return api.updatePet(result, requestOptions).then(() => {
|
||||
return api.getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
return expect(result.name).to.deep.equal('newname');
|
||||
});
|
||||
});
|
||||
@ -37,11 +37,11 @@ describe('PetApi', () => {
|
||||
});
|
||||
|
||||
it('should delete Pet', () => {
|
||||
return api.deletePet({ petId: fixture.id }, requestOptions);
|
||||
return api.deletePet(fixture.id, requestOptions);
|
||||
});
|
||||
|
||||
it('should not contain deleted Pet', () => {
|
||||
return api.getPetById({ petId: fixture.id }, requestOptions).then((result: Pet) => {
|
||||
return api.getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
return expect(result).to.not.exist;
|
||||
}, (err: any) => {
|
||||
return expect(err).to.exist;
|
||||
@ -71,7 +71,7 @@ function createTestFixture(ts = Date.now()) {
|
||||
'name': `pet${ts}`,
|
||||
'category': category,
|
||||
'photoUrls': ['http://foo.bar.com/1', 'http://foo.bar.com/2'],
|
||||
'status': 'available',
|
||||
'status': Pet.StatusEnum.Available,
|
||||
'tags': []
|
||||
};
|
||||
|
||||
|
@ -1,14 +1,18 @@
|
||||
import {expect} from 'chai';
|
||||
import {PetApiFactory, Pet, Category} from 'typescript-fetch-api';
|
||||
import {Configuration} from 'typescript-fetch-api/dist/configuration';
|
||||
import { expect } from 'chai';
|
||||
import { PetApiFactory, Pet, Category } from '@swagger/typescript-fetch-petstore';
|
||||
import { Configuration } from '@swagger/typescript-fetch-petstore';
|
||||
|
||||
let config: Configuration;
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
config = new Configuration();
|
||||
config.accessToken = "foobar";
|
||||
config.apiKey = {
|
||||
api_key: "foobar"
|
||||
config.apiKey = (securityName: string) => {
|
||||
// for multiple apiKey security
|
||||
if (securityName === "api_key") {
|
||||
return "foobar";
|
||||
}
|
||||
return;
|
||||
};
|
||||
config.username = "foo";
|
||||
config.password = "bar";
|
||||
@ -24,21 +28,21 @@ describe('PetApiFactory', () => {
|
||||
const fixture: Pet = createTestFixture();
|
||||
|
||||
it('should add and delete Pet', () => {
|
||||
return PetApiFactory().addPet({ body: fixture }, config, requestOptions).then(() => {
|
||||
return PetApiFactory(config).addPet(fixture, requestOptions).then(() => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should get Pet by ID', () => {
|
||||
return PetApiFactory().getPetById({ petId: fixture.id }, config, requestOptions).then((result: Pet) => {
|
||||
return PetApiFactory(config).getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
return expect(result).to.deep.equal(fixture);
|
||||
});
|
||||
});
|
||||
|
||||
it('should update Pet by ID', () => {
|
||||
return PetApiFactory().getPetById({ petId: fixture.id }, config, requestOptions).then( (result: Pet) => {
|
||||
return PetApiFactory(config).getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
result.name = 'newname';
|
||||
return PetApiFactory().updatePet({ body: result }, config, requestOptions).then(() => {
|
||||
return PetApiFactory().getPetById({ petId: fixture.id }, config, requestOptions).then( (result: Pet) => {
|
||||
return PetApiFactory(config).updatePet(result, requestOptions).then(() => {
|
||||
return PetApiFactory(config).getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
return expect(result.name).to.deep.equal('newname');
|
||||
});
|
||||
});
|
||||
@ -46,11 +50,11 @@ describe('PetApiFactory', () => {
|
||||
});
|
||||
|
||||
it('should delete Pet', () => {
|
||||
return PetApiFactory().deletePet({ petId: fixture.id }, config, requestOptions);
|
||||
return PetApiFactory(config).deletePet(fixture.id, requestOptions);
|
||||
});
|
||||
|
||||
it('should not contain deleted Pet', () => {
|
||||
return PetApiFactory().getPetById({ petId: fixture.id }, config, requestOptions).then((result: Pet) => {
|
||||
return PetApiFactory(config).getPetById(fixture.id, requestOptions).then((result: Pet) => {
|
||||
return expect(result).to.not.exist;
|
||||
}, (err: any) => {
|
||||
return expect(err).to.exist;
|
||||
@ -79,7 +83,7 @@ function createTestFixture(ts = Date.now()) {
|
||||
'name': `pet${ts}`,
|
||||
'category': category,
|
||||
'photoUrls': ['http://foo.bar.com/1', 'http://foo.bar.com/2'],
|
||||
'status': 'available',
|
||||
'status': Pet.StatusEnum.Available,
|
||||
'tags': []
|
||||
};
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
import {expect} from 'chai';
|
||||
import {StoreApi} from 'typescript-fetch-api';
|
||||
import { expect } from 'chai';
|
||||
import { StoreApi } from '@swagger/typescript-fetch-petstore';
|
||||
|
||||
describe('StoreApi', function() {
|
||||
describe('StoreApi', function () {
|
||||
|
||||
function runSuite(description: string, requestOptions?: any): void {
|
||||
|
||||
describe(description, () => {
|
||||
let api: StoreApi;
|
||||
|
||||
beforeEach(function() {
|
||||
beforeEach(function () {
|
||||
api = new StoreApi();
|
||||
});
|
||||
|
||||
it('should get inventory', function() {
|
||||
it('should get inventory', function () {
|
||||
return api.getInventory(requestOptions).then((result: { [key: string]: number }) => {
|
||||
expect(Object.keys(result)).to.not.be.empty;
|
||||
});
|
||||
|
@ -1,26 +1,30 @@
|
||||
import {expect} from 'chai';
|
||||
import {StoreApiFactory} from 'typescript-fetch-api';
|
||||
import {Configuration} from 'typescript-fetch-api/dist/configuration';
|
||||
import { expect } from 'chai';
|
||||
import { StoreApiFactory } from '@swagger/typescript-fetch-petstore';
|
||||
import { Configuration } from '@swagger/typescript-fetch-petstore';
|
||||
|
||||
let config: Configuration;
|
||||
|
||||
before(function() {
|
||||
before(function () {
|
||||
config = new Configuration();
|
||||
config.accessToken = "foobar";
|
||||
config.apiKey = {
|
||||
api_key: "foobar"
|
||||
config.apiKey = (securityName: string) => {
|
||||
// for multiple apiKey security
|
||||
if (securityName === "api_key") {
|
||||
return "foobar";
|
||||
}
|
||||
return;
|
||||
};
|
||||
config.username = "foo";
|
||||
config.password = "bar";
|
||||
});
|
||||
|
||||
describe('StoreApiFactory', function() {
|
||||
describe('StoreApiFactory', function () {
|
||||
function runSuite(description: string, requestOptions?: any): void {
|
||||
|
||||
describe(description, () => {
|
||||
|
||||
it('should get inventory', function() {
|
||||
return StoreApiFactory().getInventory(config, requestOptions).then((result: { [key: string]: number }) => {
|
||||
it('should get inventory', function () {
|
||||
return StoreApiFactory(config).getInventory(requestOptions).then((result: { [key: string]: number }) => {
|
||||
expect(Object.keys(result)).to.not.be.empty;
|
||||
});
|
||||
});
|
||||
|
@ -1 +0,0 @@
|
||||
--timeout 10000 dist/test
|
@ -5,12 +5,15 @@
|
||||
"noImplicitAny": true,
|
||||
"sourceMap": false,
|
||||
"outDir": "dist",
|
||||
"rootDir": "."
|
||||
"types": [
|
||||
"mocha"
|
||||
],
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"typings/browser",
|
||||
"typings/main",
|
||||
"typings/main.d.ts"
|
||||
"node_modules"
|
||||
]
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
{
|
||||
"name": "typescript-fetch-test",
|
||||
"version": false,
|
||||
"globalDependencies": {
|
||||
"chai": "registry:dt/chai#3.4.0+20160317120654",
|
||||
"es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
|
||||
"mocha": "registry:dt/mocha#2.2.5+20160317120654"
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ module.exports = {
|
||||
app: './test/index.ts',
|
||||
vendor: [
|
||||
// libraries
|
||||
'typescript-fetch-api'
|
||||
'@swagger/typescript-fetch-petstore'
|
||||
],
|
||||
},
|
||||
output: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user