From 1825a467d837048cf47bbdd0bf747ffa7a6b8d76 Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Wed, 20 Apr 2016 11:10:29 +0200 Subject: [PATCH 1/5] Adding an index file and avoiding the use of the model.d.ts files because typescript doesn't compile it correctly. --- .../languages/TypeScriptAngular2ClientCodegen.java | 13 +++++++++++-- .../main/resources/typescript-angular2/api.mustache | 2 +- .../{model.d.mustache => apis.mustache} | 8 -------- .../resources/typescript-angular2/index.mustache | 2 ++ .../resources/typescript-angular2/model.mustache | 4 ++-- .../resources/typescript-angular2/models.mustache | 8 ++++++++ .../TypeScriptAngular2ModelTest.java | 10 +++++----- 7 files changed, 29 insertions(+), 18 deletions(-) rename modules/swagger-codegen/src/main/resources/typescript-angular2/{model.d.mustache => apis.mustache} (57%) create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java index e23f4482dfa..e6d774783d4 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java @@ -37,7 +37,15 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod public void processOpts() { super.processOpts(); supportingFiles.clear(); - supportingFiles.add(new SupportingFile("model.d.mustache", modelPackage().replace('.', File.separatorChar), "model.d.ts")); + + supportingFiles.add(new SupportingFile("models.mustache", modelPackage().replace('.', File.separatorChar), "models.ts")); + supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts")); + supportingFiles.add(new SupportingFile("index.mustache", getIndexDirectory(), "index.ts")); + } + + private String getIndexDirectory() { + String indexPackage = modelPackage.substring(0, Math.max(0, modelPackage.lastIndexOf('.'))); + return indexPackage.replace('.', File.separatorChar); } @Override @@ -69,7 +77,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod if (languageSpecificPrimitives.contains(type)) return type; } else - type = "model." + swaggerType; + type = "models." + swaggerType; return type; } @@ -78,4 +86,5 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod super.postProcessParameter(parameter); parameter.dataType = addModelPrefix(parameter.dataType); } + } diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index b5625698a3d..063393affc0 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -1,7 +1,7 @@ import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; import {Injectable} from 'angular2/core'; import {Observable} from 'rxjs/Observable'; -import * as model from "../model/model.d.ts" +import * as models from "../model/models.ts" /* tslint:disable:no-unused-variable member-ordering */ diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.d.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache similarity index 57% rename from modules/swagger-codegen/src/main/resources/typescript-angular2/model.d.mustache rename to modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache index 1da8b543fce..05b5c6ec2ea 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.d.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache @@ -1,11 +1,3 @@ -{{#models}} -{{#model}} -export * from './{{{ classname }}}'; -{{/model}} -{{/models}} - - - {{#apiInfo}} {{#apis}} {{#operations}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache new file mode 100644 index 00000000000..84fe5a636a0 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache @@ -0,0 +1,2 @@ +export * from './api/apis.ts'; +export * from './model/models.ts'; \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache index ff36a380e94..f32a4635621 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache @@ -1,14 +1,14 @@ {{#models}} {{#model}} 'use strict'; -import * as model from "./model.d.ts" +import * as models from "./models.ts" {{#description}} /** * {{{description}}} */ {{/description}} -export interface {{classname}} {{#parent}}extends model.{{{parent}}} {{/parent}}{ +export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{ {{#vars}} {{#description}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache new file mode 100644 index 00000000000..677b6b87328 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache @@ -0,0 +1,8 @@ +{{#models}} +{{#model}} +export * from './{{{ classname }}}'; +{{/model}} +{{/models}} + + + diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java index 8f696801202..3aa33df7da4 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java @@ -119,10 +119,10 @@ public class TypeScriptAngular2ModelTest { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "children"); - Assert.assertEquals(property1.datatype, "model.Children"); + Assert.assertEquals(property1.datatype, "models.Children"); Assert.assertEquals(property1.name, "children"); Assert.assertEquals(property1.defaultValue, "null"); - Assert.assertEquals(property1.baseType, "model.Children"); + Assert.assertEquals(property1.baseType, "models.Children"); Assert.assertNull(property1.required); Assert.assertTrue(property1.isNotContainer); } @@ -143,8 +143,8 @@ public class TypeScriptAngular2ModelTest { final CodegenProperty property1 = cm.vars.get(0); Assert.assertEquals(property1.baseName, "children"); - Assert.assertEquals(property1.complexType, "model.Children"); - Assert.assertEquals(property1.datatype, "Array"); + Assert.assertEquals(property1.complexType, "models.Children"); + Assert.assertEquals(property1.datatype, "Array"); Assert.assertEquals(property1.name, "children"); Assert.assertEquals(property1.baseType, "Array"); Assert.assertNull(property1.required); @@ -178,6 +178,6 @@ public class TypeScriptAngular2ModelTest { Assert.assertEquals(cm.description, "a map model"); Assert.assertEquals(cm.vars.size(), 0); Assert.assertEquals(cm.imports.size(), 1); - Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("model.Children")).size(), 1); + Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("models.Children")).size(), 1); } } From 26c8eb1068cb35b0cb602fff567f4c8b68142265 Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Wed, 20 Apr 2016 16:07:02 +0200 Subject: [PATCH 2/5] some small import fixes --- .../src/main/resources/typescript-angular2/api.mustache | 4 ++-- .../src/main/resources/typescript-angular2/index.mustache | 4 ++-- .../src/main/resources/typescript-angular2/model.mustache | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index 063393affc0..fd37bdd1194 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -1,7 +1,7 @@ import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; import {Injectable} from 'angular2/core'; import {Observable} from 'rxjs/Observable'; -import * as models from "../model/models.ts" +import * as models from '../model/models'; /* tslint:disable:no-unused-variable member-ordering */ @@ -79,7 +79,7 @@ export class {{classname}} { {{/hasFormParams}} return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } {{/operation}} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache index 84fe5a636a0..557365516ad 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/index.mustache @@ -1,2 +1,2 @@ -export * from './api/apis.ts'; -export * from './model/models.ts'; \ No newline at end of file +export * from './api/api'; +export * from './model/models'; \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache index f32a4635621..da832ad0ba2 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache @@ -1,7 +1,7 @@ {{#models}} {{#model}} 'use strict'; -import * as models from "./models.ts" +import * as models from './models.ts'; {{#description}} /** @@ -16,7 +16,6 @@ export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent} * {{{description}}} */ {{/description}} - {{name}}?: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} } From a75b0251c4248f34023ca3ddec096f57dd050b24 Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Thu, 21 Apr 2016 13:43:51 +0200 Subject: [PATCH 3/5] Starting addition of full npm package generation --- .../TypeScriptAngular2ClientCodegen.java | 64 ++++++++++++++++++- .../typescript-angular2/README.mustache | 33 ++++++++++ .../typescript-angular2/package.json | 41 ++++++++++++ .../typescript-angular2/tsconfig.json | 27 ++++++++ .../typescript-angular2/typings.json | 5 ++ ...peScriptAngular2ClientOptionsProvider.java | 8 +++ 6 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/package.json create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.json create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/typings.json diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java index e6d774783d4..be0e5ddb59b 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java @@ -1,15 +1,28 @@ package io.swagger.codegen.languages; import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import io.swagger.codegen.CliOption; import io.swagger.codegen.CodegenParameter; import io.swagger.codegen.SupportingFile; import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.BooleanProperty; import io.swagger.models.properties.FileProperty; import io.swagger.models.properties.MapProperty; import io.swagger.models.properties.Property; public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCodegen { + private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm"); + public static final String NMP_NAME = "nmpName"; + public static final String NMP_VERSION = "nmpVersion"; + public static final String NPM_REPOSITORY = "npmRepository"; + public static final String SNAPSHOT = "Snapshot"; + + private String npmName = null; + private String npmVersion = "1.0.0"; + private String npmRepository = null; public TypeScriptAngular2ClientCodegen() { super(); @@ -21,6 +34,12 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod typeMapping.put("Date","Date"); apiPackage = "api"; modelPackage = "model"; + + + this.cliOptions.add(new CliOption(NMP_NAME, "The name under which you want to publish generated npm package")); + this.cliOptions.add(new CliOption(NMP_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 @@ -36,11 +55,31 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod @Override public void processOpts() { super.processOpts(); - supportingFiles.clear(); supportingFiles.add(new SupportingFile("models.mustache", modelPackage().replace('.', File.separatorChar), "models.ts")); supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts")); supportingFiles.add(new SupportingFile("index.mustache", getIndexDirectory(), "index.ts")); + + if(additionalProperties.containsKey(NMP_NAME)) { + addNpmPackageGeneration(); + } + } + + private void addNpmPackageGeneration() { + if(additionalProperties.containsKey(NMP_NAME)) { + this.setNpmName(additionalProperties.get(NMP_NAME).toString()); + } + + if (additionalProperties.containsKey(NMP_VERSION)) { + this.setNpmVersion(additionalProperties.get(NMP_VERSION).toString()); + } + + if (additionalProperties.containsKey(SNAPSHOT) && Boolean.valueOf(additionalProperties.get(SNAPSHOT).toString())) { + this.setNpmVersion(npmVersion + "-SNAPSHOT." + SNAPSHOT_SUFFIX_FORMAT.format(new Date())); + } + additionalProperties.put(NMP_VERSION, npmVersion); + + supportingFiles.add(new SupportingFile("README.mustache", getIndexDirectory(), "README.md")); } private String getIndexDirectory() { @@ -87,4 +126,27 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod parameter.dataType = addModelPrefix(parameter.dataType); } + public String getNpmName() { + return npmName; + } + + public void setNpmName(String npmName) { + this.npmName = npmName; + } + + public String getNpmVersion() { + return npmVersion; + } + + public void setNpmVersion(String npmVersion) { + this.npmVersion = npmVersion; + } + + public String getNpmRepository() { + return npmRepository; + } + + public void setNpmRepository(String npmRepository) { + this.npmRepository = npmRepository; + } } diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache new file mode 100644 index 00000000000..345cd299a72 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache @@ -0,0 +1,33 @@ +## {{npmName}}@{{npmVersion}} + +### 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 +``` + +In your angular2 project: + +TODO: paste example. \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.json b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.json new file mode 100644 index 00000000000..9d24adc7165 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.json @@ -0,0 +1,41 @@ +{ + "name": "@restore/fxt-configurator-client", + "version": "1.${project.version}", + "description": "client to consume the fxt-configurator-api", + "keywords": [ + "swagger-client" + ], + "license": "MIT", + "bugs": { + "url": "https://github.com/swagger-api/swagger-codegen/issues" + }, + "files": [ + "lib" + ], + "main": "./lib/index.js", + "typings": "./lib/index.d.ts", + "scripts": { + "build": "typings install && tsc" + }, + "repository": { + "type": "git", + "url": "https://stash.flexpond.com/scm/flxp/flextract-service-module.git" + }, + "peerDependencies": { + "angular2": "^2.0.0-beta.15", + "rxjs": "^5.0.0-beta.2" + }, + "devDependencies": { + "typescript": "^1.8.10", + "typings": "^0.8.1", + "angular2": "^2.0.0-beta.15", + "es6-shim": "^0.35.0", + "es7-reflect-metadata": "^1.6.0", + "rxjs": "5.0.0-beta.2", + "zone.js": "^0.6.10" + }, + "private": true, + "publishConfig":{ + "registry":"http://my-internal-registry.local" + } +} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.json b/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.json new file mode 100644 index 00000000000..07fbdf7e1b1 --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./lib", + "noLib": false, + "declaration": true + }, + "exclude": [ + "node_modules", + "typings/main.d.ts", + "typings/main", + "lib" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts", + "typings/browser.d.ts" + ] +} diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/typings.json b/modules/swagger-codegen/src/main/resources/typescript-angular2/typings.json new file mode 100644 index 00000000000..32530eeb63d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/typings.json @@ -0,0 +1,5 @@ +{ + "ambientDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160317120654" + } +} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java index c7bddc9f663..97a2095c334 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java @@ -5,11 +5,15 @@ import com.google.common.collect.ImmutableMap; import java.util.Map; import io.swagger.codegen.CodegenConstants; +import io.swagger.codegen.languages.TypeScriptAngular2ClientCodegen; public class TypeScriptAngular2ClientOptionsProvider implements OptionsProvider { public static final String SORT_PARAMS_VALUE = "false"; public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true"; public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase"; + public static final String NMP_NAME = "npmName"; + private static final String NMP_VERSION = "1.1.2"; + private static final String NPM_REPOSITORY = "https://registry.npmjs.org"; @Override public String getLanguage() { @@ -22,6 +26,10 @@ public class TypeScriptAngular2ClientOptionsProvider implements OptionsProvider return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE) .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) .put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE) + .put(TypeScriptAngular2ClientCodegen.NMP_NAME, NMP_NAME) + .put(TypeScriptAngular2ClientCodegen.NMP_VERSION, NMP_VERSION) + .put(TypeScriptAngular2ClientCodegen.SNAPSHOT, Boolean.FALSE.toString()) + .put(TypeScriptAngular2ClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY) .build(); } From e118fddb47f5df5a43f0411b06528376c48374f3 Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Thu, 21 Apr 2016 15:43:53 +0200 Subject: [PATCH 4/5] generation of package.json and compilation files --- ...typescript-angular2-petstore-with-npm.json | 5 + bin/typescript-angular2-petstore-with-npm.sh | 31 +++ .../TypeScriptAngular2ClientCodegen.java | 40 +-- .../typescript-angular2/README.mustache | 2 +- .../typescript-angular2/model.mustache | 2 +- .../{package.json => package.mustache} | 19 +- .../{tsconfig.json => tsconfig.mustache} | 0 .../{typings.json => typings.mustache} | 0 ...peScriptAngular2ClientOptionsProvider.java | 4 +- .../typescript-angular2-with-npm/README.md | 33 +++ .../api/PetApi.ts | 236 ++++++++++++++++++ .../api/StoreApi.ts | 111 ++++++++ .../api/UserApi.ts | 209 ++++++++++++++++ .../typescript-angular2-with-npm/api/api.ts | 5 + .../typescript-angular2-with-npm/index.ts | 2 + .../model/Category.ts | 10 + .../model/Order.ts | 29 +++ .../typescript-angular2-with-npm/model/Pet.ts | 29 +++ .../typescript-angular2-with-npm/model/Tag.ts | 10 + .../model/User.ts | 25 ++ .../model/models.ts} | 5 - .../typescript-angular2-with-npm/package.json | 29 +++ .../tsconfig.json | 27 ++ .../typescript-angular2-with-npm/typings.json | 5 + .../typescript-angular2/api/PetApi.ts | 30 +-- .../typescript-angular2/api/StoreApi.ts | 14 +- .../typescript-angular2/api/UserApi.ts | 28 +-- .../petstore/typescript-angular2/api/api.ts | 5 + .../petstore/typescript-angular2/index.ts | 2 + .../typescript-angular2/model/Category.ts | 4 +- .../typescript-angular2/model/Order.ts | 8 +- .../petstore/typescript-angular2/model/Pet.ts | 12 +- .../petstore/typescript-angular2/model/Tag.ts | 4 +- .../typescript-angular2/model/User.ts | 10 +- .../typescript-angular2/model/models.ts | 8 + 35 files changed, 888 insertions(+), 105 deletions(-) create mode 100755 bin/typescript-angular2-petstore-with-npm.json create mode 100755 bin/typescript-angular2-petstore-with-npm.sh rename modules/swagger-codegen/src/main/resources/typescript-angular2/{package.json => package.mustache} (56%) rename modules/swagger-codegen/src/main/resources/typescript-angular2/{tsconfig.json => tsconfig.mustache} (100%) rename modules/swagger-codegen/src/main/resources/typescript-angular2/{typings.json => typings.mustache} (100%) create mode 100644 samples/client/petstore/typescript-angular2-with-npm/README.md create mode 100644 samples/client/petstore/typescript-angular2-with-npm/api/PetApi.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/api/StoreApi.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/api/UserApi.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/api/api.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/index.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/model/Category.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/model/Order.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/model/Pet.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/model/Tag.ts create mode 100644 samples/client/petstore/typescript-angular2-with-npm/model/User.ts rename samples/client/petstore/{typescript-angular2/model/model.d.ts => typescript-angular2-with-npm/model/models.ts} (56%) create mode 100644 samples/client/petstore/typescript-angular2-with-npm/package.json create mode 100644 samples/client/petstore/typescript-angular2-with-npm/tsconfig.json create mode 100644 samples/client/petstore/typescript-angular2-with-npm/typings.json create mode 100644 samples/client/petstore/typescript-angular2/api/api.ts create mode 100644 samples/client/petstore/typescript-angular2/index.ts create mode 100644 samples/client/petstore/typescript-angular2/model/models.ts diff --git a/bin/typescript-angular2-petstore-with-npm.json b/bin/typescript-angular2-petstore-with-npm.json new file mode 100755 index 00000000000..71ff9129dd7 --- /dev/null +++ b/bin/typescript-angular2-petstore-with-npm.json @@ -0,0 +1,5 @@ +{ + "npmName": "PetstoreSwagger", + "npmVersion": "0.0.1", + "snapshot" : true +} diff --git a/bin/typescript-angular2-petstore-with-npm.sh b/bin/typescript-angular2-petstore-with-npm.sh new file mode 100755 index 00000000000..9e455715b01 --- /dev/null +++ b/bin/typescript-angular2-petstore-with-npm.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +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 -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -c bin/typescript-angular2-petstore-with-npm.json -o samples/client/petstore/typescript-angular2-with-npm" + +java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java index be0e5ddb59b..a80e0f66ae0 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java @@ -15,14 +15,15 @@ import io.swagger.models.properties.Property; public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCodegen { private static final SimpleDateFormat SNAPSHOT_SUFFIX_FORMAT = new SimpleDateFormat("yyyyMMddHHmm"); - public static final String NMP_NAME = "nmpName"; - public static final String NMP_VERSION = "nmpVersion"; - public static final String NPM_REPOSITORY = "npmRepository"; - public static final String SNAPSHOT = "Snapshot"; - private String npmName = null; - private String npmVersion = "1.0.0"; - private String npmRepository = null; + 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 TypeScriptAngular2ClientCodegen() { super(); @@ -36,8 +37,8 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod modelPackage = "model"; - this.cliOptions.add(new CliOption(NMP_NAME, "The name under which you want to publish generated npm package")); - this.cliOptions.add(new CliOption(NMP_VERSION, "The version of your npm package")); + 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())); } @@ -55,31 +56,38 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod @Override public void processOpts() { super.processOpts(); - supportingFiles.add(new SupportingFile("models.mustache", modelPackage().replace('.', File.separatorChar), "models.ts")); supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts")); supportingFiles.add(new SupportingFile("index.mustache", getIndexDirectory(), "index.ts")); - if(additionalProperties.containsKey(NMP_NAME)) { + if(additionalProperties.containsKey(NPM_NAME)) { addNpmPackageGeneration(); } } private void addNpmPackageGeneration() { - if(additionalProperties.containsKey(NMP_NAME)) { - this.setNpmName(additionalProperties.get(NMP_NAME).toString()); + if(additionalProperties.containsKey(NPM_NAME)) { + this.setNpmName(additionalProperties.get(NPM_NAME).toString()); } - if (additionalProperties.containsKey(NMP_VERSION)) { - this.setNpmVersion(additionalProperties.get(NMP_VERSION).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(NMP_VERSION, npmVersion); + 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", getIndexDirectory(), "README.md")); + supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json")); + supportingFiles.add(new SupportingFile("typings.mustache", getIndexDirectory(), "typings.json")); + supportingFiles.add(new SupportingFile("tsconfig.mustache", getIndexDirectory(), "tsconfig.json")); } private String getIndexDirectory() { diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache index 345cd299a72..73736fefb0c 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/README.mustache @@ -30,4 +30,4 @@ npm install PATH_TO_GENERATED_PACKAGE --save In your angular2 project: -TODO: paste example. \ No newline at end of file +TODO: paste example. diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache index da832ad0ba2..4170b2d1594 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache @@ -1,7 +1,7 @@ {{#models}} {{#model}} 'use strict'; -import * as models from './models.ts'; +import * as models from './models'; {{#description}} /** diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.json b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache similarity index 56% rename from modules/swagger-codegen/src/main/resources/typescript-angular2/package.json rename to modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache index 9d24adc7165..0f214891a7c 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.json +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache @@ -1,14 +1,11 @@ { - "name": "@restore/fxt-configurator-client", - "version": "1.${project.version}", - "description": "client to consume the fxt-configurator-api", + "name": "{{npmName}}", + "version": "{{npmVersion}}", + "description": "swagger client for {{npmName}}", "keywords": [ "swagger-client" ], "license": "MIT", - "bugs": { - "url": "https://github.com/swagger-api/swagger-codegen/issues" - }, "files": [ "lib" ], @@ -17,10 +14,6 @@ "scripts": { "build": "typings install && tsc" }, - "repository": { - "type": "git", - "url": "https://stash.flexpond.com/scm/flxp/flextract-service-module.git" - }, "peerDependencies": { "angular2": "^2.0.0-beta.15", "rxjs": "^5.0.0-beta.2" @@ -33,9 +26,9 @@ "es7-reflect-metadata": "^1.6.0", "rxjs": "5.0.0-beta.2", "zone.js": "^0.6.10" - }, - "private": true, + }{{#npmRepository}}, "publishConfig":{ - "registry":"http://my-internal-registry.local" + "registry":"{{npmRepository}}" } +{{/npmRepository}} } diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.json b/modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.json rename to modules/swagger-codegen/src/main/resources/typescript-angular2/tsconfig.mustache diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/typings.json b/modules/swagger-codegen/src/main/resources/typescript-angular2/typings.mustache similarity index 100% rename from modules/swagger-codegen/src/main/resources/typescript-angular2/typings.json rename to modules/swagger-codegen/src/main/resources/typescript-angular2/typings.mustache diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java index 97a2095c334..a72d6b568c1 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java @@ -26,8 +26,8 @@ public class TypeScriptAngular2ClientOptionsProvider implements OptionsProvider return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE) .put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE) .put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE) - .put(TypeScriptAngular2ClientCodegen.NMP_NAME, NMP_NAME) - .put(TypeScriptAngular2ClientCodegen.NMP_VERSION, NMP_VERSION) + .put(TypeScriptAngular2ClientCodegen.NPM_NAME, NMP_NAME) + .put(TypeScriptAngular2ClientCodegen.NPM_VERSION, NMP_VERSION) .put(TypeScriptAngular2ClientCodegen.SNAPSHOT, Boolean.FALSE.toString()) .put(TypeScriptAngular2ClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY) .build(); diff --git a/samples/client/petstore/typescript-angular2-with-npm/README.md b/samples/client/petstore/typescript-angular2-with-npm/README.md new file mode 100644 index 00000000000..3ca4b0ce98e --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/README.md @@ -0,0 +1,33 @@ +## PetstoreSwagger@0.0.1-SNAPSHOT.201604211539 + +### 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 PetstoreSwagger@0.0.1-SNAPSHOT.201604211539 --save +``` + +_unPublished (not recommended):_ + +``` +npm install PATH_TO_GENERATED_PACKAGE --save +``` + +In your angular2 project: + +TODO: paste example. diff --git a/samples/client/petstore/typescript-angular2-with-npm/api/PetApi.ts b/samples/client/petstore/typescript-angular2-with-npm/api/PetApi.ts new file mode 100644 index 00000000000..e2121b52c0b --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/api/PetApi.ts @@ -0,0 +1,236 @@ +import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; +import {Injectable} from 'angular2/core'; +import {Observable} from 'rxjs/Observable'; +import * as models from '../model/models'; + +/* tslint:disable:no-unused-variable member-ordering */ + +'use strict'; + +@Injectable() +export class PetApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders : Headers = new Headers(); + + constructor(protected http: Http, basePath: string) { + if (basePath) { + this.basePath = basePath; + } + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPet (body?: models.Pet, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/pet'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + public deletePet (petId: number, apiKey?: string, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling deletePet'); + } + headerParams.set('api_key', apiKey); + + let requestOptions: RequestOptionsArgs = { + method: 'DELETE', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma seperated strings + * @param status Status values that need to be considered for filter + */ + public findPetsByStatus (status?: models.Array, extraHttpRequestParams?: any ) : Observable> { + const path = this.basePath + '/pet/findByStatus'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + if (status !== undefined) { + queryParameters['status'] = status; + } + + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Finds Pets by tags + * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + */ + public findPetsByTags (tags?: models.Array, extraHttpRequestParams?: any ) : Observable> { + const path = this.basePath + '/pet/findByTags'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + if (tags !== undefined) { + queryParameters['tags'] = tags; + } + + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + */ + public getPetById (petId: number, extraHttpRequestParams?: any ) : Observable { + const path = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling getPetById'); + } + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet (body?: models.Pet, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/pet'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'PUT', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + public updatePetWithForm (petId: string, name?: string, status?: string, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/pet/{petId}' + .replace('{' + 'petId' + '}', String(petId)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let formParams = new URLSearchParams(); + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling updatePetWithForm'); + } + headerParams.set('Content-Type', 'application/x-www-form-urlencoded'); + + formParams['name'] = name; + + formParams['status'] = status; + + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = formParams.toString(); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + public uploadFile (petId: number, additionalMetadata?: string, file?: models.any, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/pet/{petId}/uploadImage' + .replace('{' + 'petId' + '}', String(petId)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let formParams = new URLSearchParams(); + + // verify required parameter 'petId' is set + if (!petId) { + throw new Error('Missing required parameter petId when calling uploadFile'); + } + headerParams.set('Content-Type', 'application/x-www-form-urlencoded'); + + formParams['additionalMetadata'] = additionalMetadata; + + formParams['file'] = file; + + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = formParams.toString(); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + +} diff --git a/samples/client/petstore/typescript-angular2-with-npm/api/StoreApi.ts b/samples/client/petstore/typescript-angular2-with-npm/api/StoreApi.ts new file mode 100644 index 00000000000..618b0c23624 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/api/StoreApi.ts @@ -0,0 +1,111 @@ +import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; +import {Injectable} from 'angular2/core'; +import {Observable} from 'rxjs/Observable'; +import * as models from '../model/models'; + +/* tslint:disable:no-unused-variable member-ordering */ + +'use strict'; + +@Injectable() +export class StoreApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders : Headers = new Headers(); + + constructor(protected http: Http, basePath: string) { + if (basePath) { + this.basePath = basePath; + } + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrder (orderId: string, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling deleteOrder'); + } + let requestOptions: RequestOptionsArgs = { + method: 'DELETE', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventory (extraHttpRequestParams?: any ) : Observable<{ [key: string]: number; }> { + const path = this.basePath + '/store/inventory'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + */ + public getOrderById (orderId: string, extraHttpRequestParams?: any ) : Observable { + const path = this.basePath + '/store/order/{orderId}' + .replace('{' + 'orderId' + '}', String(orderId)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'orderId' is set + if (!orderId) { + throw new Error('Missing required parameter orderId when calling getOrderById'); + } + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder (body?: models.Order, extraHttpRequestParams?: any ) : Observable { + const path = this.basePath + '/store/order'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + +} diff --git a/samples/client/petstore/typescript-angular2-with-npm/api/UserApi.ts b/samples/client/petstore/typescript-angular2-with-npm/api/UserApi.ts new file mode 100644 index 00000000000..f52b407d126 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/api/UserApi.ts @@ -0,0 +1,209 @@ +import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; +import {Injectable} from 'angular2/core'; +import {Observable} from 'rxjs/Observable'; +import * as models from '../model/models'; + +/* tslint:disable:no-unused-variable member-ordering */ + +'use strict'; + +@Injectable() +export class UserApi { + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders : Headers = new Headers(); + + constructor(protected http: Http, basePath: string) { + if (basePath) { + this.basePath = basePath; + } + } + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUser (body?: models.User, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInput (body?: models.Array, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user/createWithArray'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInput (body?: models.Array, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user/createWithList'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + public deleteUser (username: string, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling deleteUser'); + } + let requestOptions: RequestOptionsArgs = { + method: 'DELETE', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByName (username: string, extraHttpRequestParams?: any ) : Observable { + const path = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling getUserByName'); + } + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUser (username?: string, password?: string, extraHttpRequestParams?: any ) : Observable { + const path = this.basePath + '/user/login'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + if (username !== undefined) { + queryParameters['username'] = username; + } + + if (password !== undefined) { + queryParameters['password'] = password; + } + + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Logs out current logged in user session + * + */ + public logoutUser (extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user/logout'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'GET', + headers: headerParams, + search: queryParameters + }; + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + */ + public updateUser (username: string, body?: models.User, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user/{username}' + .replace('{' + 'username' + '}', String(username)); + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + // verify required parameter 'username' is set + if (!username) { + throw new Error('Missing required parameter username when calling updateUser'); + } + let requestOptions: RequestOptionsArgs = { + method: 'PUT', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + +} diff --git a/samples/client/petstore/typescript-angular2-with-npm/api/api.ts b/samples/client/petstore/typescript-angular2-with-npm/api/api.ts new file mode 100644 index 00000000000..a7020497be6 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/api/api.ts @@ -0,0 +1,5 @@ +export * from '../api/PetApi'; +export * from '../api/StoreApi'; +export * from '../api/UserApi'; + + diff --git a/samples/client/petstore/typescript-angular2-with-npm/index.ts b/samples/client/petstore/typescript-angular2-with-npm/index.ts new file mode 100644 index 00000000000..557365516ad --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/index.ts @@ -0,0 +1,2 @@ +export * from './api/api'; +export * from './model/models'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2-with-npm/model/Category.ts b/samples/client/petstore/typescript-angular2-with-npm/model/Category.ts new file mode 100644 index 00000000000..3a9eb603184 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/model/Category.ts @@ -0,0 +1,10 @@ +'use strict'; +import * as models from './models'; + +export interface Category { + + id?: number; + + name?: string; +} + diff --git a/samples/client/petstore/typescript-angular2-with-npm/model/Order.ts b/samples/client/petstore/typescript-angular2-with-npm/model/Order.ts new file mode 100644 index 00000000000..ed557b454d4 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/model/Order.ts @@ -0,0 +1,29 @@ +'use strict'; +import * as models from './models'; + +export interface Order { + + id?: number; + + petId?: number; + + quantity?: number; + + shipDate?: Date; + + /** + * Order Status + */ + status?: Order.StatusEnum; + + complete?: boolean; +} + +export namespace Order { + + export enum StatusEnum { + placed = 'placed', + approved = 'approved', + delivered = 'delivered', + } +} diff --git a/samples/client/petstore/typescript-angular2-with-npm/model/Pet.ts b/samples/client/petstore/typescript-angular2-with-npm/model/Pet.ts new file mode 100644 index 00000000000..e1235c90052 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/model/Pet.ts @@ -0,0 +1,29 @@ +'use strict'; +import * as models from './models'; + +export interface Pet { + + id?: number; + + category?: models.Category; + + name?: string; + + photoUrls?: Array; + + tags?: Array; + + /** + * pet status in the store + */ + status?: Pet.StatusEnum; +} + +export namespace Pet { + + export enum StatusEnum { + available = 'available', + pending = 'pending', + sold = 'sold', + } +} diff --git a/samples/client/petstore/typescript-angular2-with-npm/model/Tag.ts b/samples/client/petstore/typescript-angular2-with-npm/model/Tag.ts new file mode 100644 index 00000000000..fba08175c1e --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/model/Tag.ts @@ -0,0 +1,10 @@ +'use strict'; +import * as models from './models'; + +export interface Tag { + + id?: number; + + name?: string; +} + diff --git a/samples/client/petstore/typescript-angular2-with-npm/model/User.ts b/samples/client/petstore/typescript-angular2-with-npm/model/User.ts new file mode 100644 index 00000000000..3f14a356307 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/model/User.ts @@ -0,0 +1,25 @@ +'use strict'; +import * as models from './models'; + +export interface User { + + id?: number; + + username?: string; + + firstName?: string; + + lastName?: string; + + email?: string; + + password?: string; + + phone?: string; + + /** + * User Status + */ + userStatus?: number; +} + diff --git a/samples/client/petstore/typescript-angular2/model/model.d.ts b/samples/client/petstore/typescript-angular2-with-npm/model/models.ts similarity index 56% rename from samples/client/petstore/typescript-angular2/model/model.d.ts rename to samples/client/petstore/typescript-angular2-with-npm/model/models.ts index cbdd34f8917..cd7700a649e 100644 --- a/samples/client/petstore/typescript-angular2/model/model.d.ts +++ b/samples/client/petstore/typescript-angular2-with-npm/model/models.ts @@ -6,8 +6,3 @@ export * from './User'; -export * from '../api/PetApi'; -export * from '../api/StoreApi'; -export * from '../api/UserApi'; - - diff --git a/samples/client/petstore/typescript-angular2-with-npm/package.json b/samples/client/petstore/typescript-angular2-with-npm/package.json new file mode 100644 index 00000000000..ff50fdae15a --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/package.json @@ -0,0 +1,29 @@ +{ + "name": "PetstoreSwagger", + "version": "0.0.1-SNAPSHOT.201604211539", + "description": "swagger client for PetstoreSwagger", + "keywords": [ + "swagger-client" + ], + "license": "MIT", + "files": [ + "lib" + ], + "main": "./lib/index.js", + "typings": "./lib/index.d.ts", + "scripts": { + "build": "typings install && tsc" + }, + "peerDependencies": { + "angular2": "^2.0.0-beta.15", + "rxjs": "^5.0.0-beta.2" + }, + "devDependencies": { + "typescript": "^1.8.10", + "typings": "^0.8.1", + "angular2": "^2.0.0-beta.15", + "es6-shim": "^0.35.0", + "es7-reflect-metadata": "^1.6.0", + "rxjs": "5.0.0-beta.2", + "zone.js": "^0.6.10" + }} diff --git a/samples/client/petstore/typescript-angular2-with-npm/tsconfig.json b/samples/client/petstore/typescript-angular2-with-npm/tsconfig.json new file mode 100644 index 00000000000..07fbdf7e1b1 --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./lib", + "noLib": false, + "declaration": true + }, + "exclude": [ + "node_modules", + "typings/main.d.ts", + "typings/main", + "lib" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts", + "typings/browser.d.ts" + ] +} diff --git a/samples/client/petstore/typescript-angular2-with-npm/typings.json b/samples/client/petstore/typescript-angular2-with-npm/typings.json new file mode 100644 index 00000000000..32530eeb63d --- /dev/null +++ b/samples/client/petstore/typescript-angular2-with-npm/typings.json @@ -0,0 +1,5 @@ +{ + "ambientDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160317120654" + } +} diff --git a/samples/client/petstore/typescript-angular2/api/PetApi.ts b/samples/client/petstore/typescript-angular2/api/PetApi.ts index dd949cfdbe1..e2121b52c0b 100644 --- a/samples/client/petstore/typescript-angular2/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular2/api/PetApi.ts @@ -1,7 +1,7 @@ import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; import {Injectable} from 'angular2/core'; import {Observable} from 'rxjs/Observable'; -import * as model from "../model/model.d.ts" +import * as models from '../model/models'; /* tslint:disable:no-unused-variable member-ordering */ @@ -23,7 +23,7 @@ export class PetApi { * * @param body Pet object that needs to be added to the store */ - public addPet (body?: model.Pet, extraHttpRequestParams?: any ) : Observable<{}> { + public addPet (body?: models.Pet, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/pet'; let queryParameters: any = ""; // This should probably be an object in the future @@ -36,7 +36,7 @@ export class PetApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -64,7 +64,7 @@ export class PetApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -72,7 +72,7 @@ export class PetApi { * Multiple status values can be provided with comma seperated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatus (status?: model.Array, extraHttpRequestParams?: any ) : Observable> { + public findPetsByStatus (status?: models.Array, extraHttpRequestParams?: any ) : Observable> { const path = this.basePath + '/pet/findByStatus'; let queryParameters: any = ""; // This should probably be an object in the future @@ -88,7 +88,7 @@ export class PetApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -96,7 +96,7 @@ export class PetApi { * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTags (tags?: model.Array, extraHttpRequestParams?: any ) : Observable> { + public findPetsByTags (tags?: models.Array, extraHttpRequestParams?: any ) : Observable> { const path = this.basePath + '/pet/findByTags'; let queryParameters: any = ""; // This should probably be an object in the future @@ -112,7 +112,7 @@ export class PetApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -120,7 +120,7 @@ export class PetApi { * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions * @param petId ID of pet that needs to be fetched */ - public getPetById (petId: number, extraHttpRequestParams?: any ) : Observable { + public getPetById (petId: number, extraHttpRequestParams?: any ) : Observable { const path = this.basePath + '/pet/{petId}' .replace('{' + 'petId' + '}', String(petId)); @@ -137,7 +137,7 @@ export class PetApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -145,7 +145,7 @@ export class PetApi { * * @param body Pet object that needs to be added to the store */ - public updatePet (body?: model.Pet, extraHttpRequestParams?: any ) : Observable<{}> { + public updatePet (body?: models.Pet, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/pet'; let queryParameters: any = ""; // This should probably be an object in the future @@ -158,7 +158,7 @@ export class PetApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -194,7 +194,7 @@ export class PetApi { requestOptions.body = formParams.toString(); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -204,7 +204,7 @@ export class PetApi { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile (petId: number, additionalMetadata?: string, file?: model.any, extraHttpRequestParams?: any ) : Observable<{}> { + public uploadFile (petId: number, additionalMetadata?: string, file?: models.any, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/pet/{petId}/uploadImage' .replace('{' + 'petId' + '}', String(petId)); @@ -230,7 +230,7 @@ export class PetApi { requestOptions.body = formParams.toString(); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } } diff --git a/samples/client/petstore/typescript-angular2/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/api/StoreApi.ts index 01b5469985d..618b0c23624 100644 --- a/samples/client/petstore/typescript-angular2/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular2/api/StoreApi.ts @@ -1,7 +1,7 @@ import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; import {Injectable} from 'angular2/core'; import {Observable} from 'rxjs/Observable'; -import * as model from "../model/model.d.ts" +import * as models from '../model/models'; /* tslint:disable:no-unused-variable member-ordering */ @@ -40,7 +40,7 @@ export class StoreApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -59,7 +59,7 @@ export class StoreApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -67,7 +67,7 @@ export class StoreApi { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderById (orderId: string, extraHttpRequestParams?: any ) : Observable { + public getOrderById (orderId: string, extraHttpRequestParams?: any ) : Observable { const path = this.basePath + '/store/order/{orderId}' .replace('{' + 'orderId' + '}', String(orderId)); @@ -84,7 +84,7 @@ export class StoreApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -92,7 +92,7 @@ export class StoreApi { * * @param body order placed for purchasing the pet */ - public placeOrder (body?: model.Order, extraHttpRequestParams?: any ) : Observable { + public placeOrder (body?: models.Order, extraHttpRequestParams?: any ) : Observable { const path = this.basePath + '/store/order'; let queryParameters: any = ""; // This should probably be an object in the future @@ -105,7 +105,7 @@ export class StoreApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } } diff --git a/samples/client/petstore/typescript-angular2/api/UserApi.ts b/samples/client/petstore/typescript-angular2/api/UserApi.ts index 424c9d404be..f52b407d126 100644 --- a/samples/client/petstore/typescript-angular2/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular2/api/UserApi.ts @@ -1,7 +1,7 @@ import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from 'angular2/http'; import {Injectable} from 'angular2/core'; import {Observable} from 'rxjs/Observable'; -import * as model from "../model/model.d.ts" +import * as models from '../model/models'; /* tslint:disable:no-unused-variable member-ordering */ @@ -23,7 +23,7 @@ export class UserApi { * This can only be done by the logged in user. * @param body Created user object */ - public createUser (body?: model.User, extraHttpRequestParams?: any ) : Observable<{}> { + public createUser (body?: models.User, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/user'; let queryParameters: any = ""; // This should probably be an object in the future @@ -36,7 +36,7 @@ export class UserApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -44,7 +44,7 @@ export class UserApi { * * @param body List of user object */ - public createUsersWithArrayInput (body?: model.Array, extraHttpRequestParams?: any ) : Observable<{}> { + public createUsersWithArrayInput (body?: models.Array, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/user/createWithArray'; let queryParameters: any = ""; // This should probably be an object in the future @@ -57,7 +57,7 @@ export class UserApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -65,7 +65,7 @@ export class UserApi { * * @param body List of user object */ - public createUsersWithListInput (body?: model.Array, extraHttpRequestParams?: any ) : Observable<{}> { + public createUsersWithListInput (body?: models.Array, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/user/createWithList'; let queryParameters: any = ""; // This should probably be an object in the future @@ -78,7 +78,7 @@ export class UserApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -103,7 +103,7 @@ export class UserApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -111,7 +111,7 @@ export class UserApi { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName (username: string, extraHttpRequestParams?: any ) : Observable { + public getUserByName (username: string, extraHttpRequestParams?: any ) : Observable { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -128,7 +128,7 @@ export class UserApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -157,7 +157,7 @@ export class UserApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -176,7 +176,7 @@ export class UserApi { }; return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } /** @@ -185,7 +185,7 @@ export class UserApi { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser (username: string, body?: model.User, extraHttpRequestParams?: any ) : Observable<{}> { + public updateUser (username: string, body?: models.User, extraHttpRequestParams?: any ) : Observable<{}> { const path = this.basePath + '/user/{username}' .replace('{' + 'username' + '}', String(username)); @@ -203,7 +203,7 @@ export class UserApi { requestOptions.body = JSON.stringify(body); return this.http.request(path, requestOptions) - .map(response => response.json()); + .map((response: Response) => response.json()); } } diff --git a/samples/client/petstore/typescript-angular2/api/api.ts b/samples/client/petstore/typescript-angular2/api/api.ts new file mode 100644 index 00000000000..a7020497be6 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/api/api.ts @@ -0,0 +1,5 @@ +export * from '../api/PetApi'; +export * from '../api/StoreApi'; +export * from '../api/UserApi'; + + diff --git a/samples/client/petstore/typescript-angular2/index.ts b/samples/client/petstore/typescript-angular2/index.ts new file mode 100644 index 00000000000..557365516ad --- /dev/null +++ b/samples/client/petstore/typescript-angular2/index.ts @@ -0,0 +1,2 @@ +export * from './api/api'; +export * from './model/models'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/model/Category.ts b/samples/client/petstore/typescript-angular2/model/Category.ts index d68c9c746a1..3a9eb603184 100644 --- a/samples/client/petstore/typescript-angular2/model/Category.ts +++ b/samples/client/petstore/typescript-angular2/model/Category.ts @@ -1,12 +1,10 @@ 'use strict'; -import * as model from "./model.d.ts" +import * as models from './models'; export interface Category { - id?: number; - name?: string; } diff --git a/samples/client/petstore/typescript-angular2/model/Order.ts b/samples/client/petstore/typescript-angular2/model/Order.ts index 70fbf0c7117..ed557b454d4 100644 --- a/samples/client/petstore/typescript-angular2/model/Order.ts +++ b/samples/client/petstore/typescript-angular2/model/Order.ts @@ -1,27 +1,21 @@ 'use strict'; -import * as model from "./model.d.ts" +import * as models from './models'; export interface Order { - id?: number; - petId?: number; - quantity?: number; - shipDate?: Date; /** * Order Status */ - status?: Order.StatusEnum; - complete?: boolean; } diff --git a/samples/client/petstore/typescript-angular2/model/Pet.ts b/samples/client/petstore/typescript-angular2/model/Pet.ts index bcf39e551d3..e1235c90052 100644 --- a/samples/client/petstore/typescript-angular2/model/Pet.ts +++ b/samples/client/petstore/typescript-angular2/model/Pet.ts @@ -1,27 +1,21 @@ 'use strict'; -import * as model from "./model.d.ts" +import * as models from './models'; export interface Pet { - id?: number; - - category?: model.Category; - + category?: models.Category; name?: string; - photoUrls?: Array; - - tags?: Array; + tags?: Array; /** * pet status in the store */ - status?: Pet.StatusEnum; } diff --git a/samples/client/petstore/typescript-angular2/model/Tag.ts b/samples/client/petstore/typescript-angular2/model/Tag.ts index 3e708ce1eda..fba08175c1e 100644 --- a/samples/client/petstore/typescript-angular2/model/Tag.ts +++ b/samples/client/petstore/typescript-angular2/model/Tag.ts @@ -1,12 +1,10 @@ 'use strict'; -import * as model from "./model.d.ts" +import * as models from './models'; export interface Tag { - id?: number; - name?: string; } diff --git a/samples/client/petstore/typescript-angular2/model/User.ts b/samples/client/petstore/typescript-angular2/model/User.ts index a5513a6ee6f..3f14a356307 100644 --- a/samples/client/petstore/typescript-angular2/model/User.ts +++ b/samples/client/petstore/typescript-angular2/model/User.ts @@ -1,33 +1,25 @@ 'use strict'; -import * as model from "./model.d.ts" +import * as models from './models'; export interface User { - id?: number; - username?: string; - firstName?: string; - lastName?: string; - email?: string; - password?: string; - phone?: string; /** * User Status */ - userStatus?: number; } diff --git a/samples/client/petstore/typescript-angular2/model/models.ts b/samples/client/petstore/typescript-angular2/model/models.ts new file mode 100644 index 00000000000..cd7700a649e --- /dev/null +++ b/samples/client/petstore/typescript-angular2/model/models.ts @@ -0,0 +1,8 @@ +export * from './Category'; +export * from './Order'; +export * from './Pet'; +export * from './Tag'; +export * from './User'; + + + From 9195e920239c2353bea81b98e68cf82696e7c6d3 Mon Sep 17 00:00:00 2001 From: Kristof Vrolijkx Date: Thu, 21 Apr 2016 15:52:43 +0200 Subject: [PATCH 5/5] using all config properties and adding extra space to package.mustache. --- bin/typescript-angular2-petstore-with-npm.json | 3 ++- .../resources/typescript-angular2/package.mustache | 1 + .../petstore/typescript-angular2-with-npm/README.md | 4 ++-- .../typescript-angular2-with-npm/package.json | 13 +++++++++---- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/bin/typescript-angular2-petstore-with-npm.json b/bin/typescript-angular2-petstore-with-npm.json index 71ff9129dd7..1eb3264f596 100755 --- a/bin/typescript-angular2-petstore-with-npm.json +++ b/bin/typescript-angular2-petstore-with-npm.json @@ -1,5 +1,6 @@ { - "npmName": "PetstoreSwagger", + "npmName": "@swagger/angular2-typescript-petstore", "npmVersion": "0.0.1", + "npmRepository" : "https://skimdb.npmjs.com/registry", "snapshot" : true } diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache index 0f214891a7c..18b375097c1 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache @@ -31,4 +31,5 @@ "registry":"{{npmRepository}}" } {{/npmRepository}} + } diff --git a/samples/client/petstore/typescript-angular2-with-npm/README.md b/samples/client/petstore/typescript-angular2-with-npm/README.md index 3ca4b0ce98e..5c393dc4906 100644 --- a/samples/client/petstore/typescript-angular2-with-npm/README.md +++ b/samples/client/petstore/typescript-angular2-with-npm/README.md @@ -1,4 +1,4 @@ -## PetstoreSwagger@0.0.1-SNAPSHOT.201604211539 +## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201604211551 ### Building @@ -19,7 +19,7 @@ navigate to the folder of your consuming project and run one of next commando's. _published:_ ``` -npm install PetstoreSwagger@0.0.1-SNAPSHOT.201604211539 --save +npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201604211551 --save ``` _unPublished (not recommended):_ diff --git a/samples/client/petstore/typescript-angular2-with-npm/package.json b/samples/client/petstore/typescript-angular2-with-npm/package.json index ff50fdae15a..f88c08d4df0 100644 --- a/samples/client/petstore/typescript-angular2-with-npm/package.json +++ b/samples/client/petstore/typescript-angular2-with-npm/package.json @@ -1,7 +1,7 @@ { - "name": "PetstoreSwagger", - "version": "0.0.1-SNAPSHOT.201604211539", - "description": "swagger client for PetstoreSwagger", + "name": "@swagger/angular2-typescript-petstore", + "version": "0.0.1-SNAPSHOT.201604211551", + "description": "swagger client for @swagger/angular2-typescript-petstore", "keywords": [ "swagger-client" ], @@ -26,4 +26,9 @@ "es7-reflect-metadata": "^1.6.0", "rxjs": "5.0.0-beta.2", "zone.js": "^0.6.10" - }} + }, + "publishConfig":{ + "registry":"https://skimdb.npmjs.com/registry" + } + +}