From d056df6250db421602c35e99e748635f8712dbc5 Mon Sep 17 00:00:00 2001 From: Vincent Devos <46601673+karismann@users.noreply.github.com> Date: Fri, 29 Mar 2019 11:07:30 +0100 Subject: [PATCH] [TypeScript Client] fix install Aurelia + fix use deprecated function (#2514) * [TypeScript Client] fix install Aurelia + fix use deprecated function in typescript client codegen * [TypeScript Client] Aurelia - update typescript version * [TypeScript Client] Aurelia - update typescript version --- bin/utils/ensure-up-to-date | 1 + .../TypeScriptAngularClientCodegen.java | 3 ++- .../TypeScriptAureliaClientCodegen.java | 3 ++- .../TypeScriptInversifyClientCodegen.java | 3 ++- .../TypeScriptNodeClientCodegen.java | 3 ++- .../resources/typescript-aurelia/README.md | 10 +++++---- .../typescript-aurelia/package.json.mustache | 22 ++++++++++--------- .../typescript-aurelia/tsconfig.json.mustache | 7 +++++- .../typescript-aurelia/default/README.md | 10 +++++---- .../typescript-aurelia/default/package.json | 22 ++++++++++--------- .../typescript-aurelia/default/tsconfig.json | 10 ++++++++- 11 files changed, 60 insertions(+), 34 deletions(-) diff --git a/bin/utils/ensure-up-to-date b/bin/utils/ensure-up-to-date index 41dc4b9cd1a..bb2bf5a6606 100755 --- a/bin/utils/ensure-up-to-date +++ b/bin/utils/ensure-up-to-date @@ -36,6 +36,7 @@ declare -a scripts=( "./bin/php-ze-ph-petstore-server.sh" "./bin/openapi3/php-petstore.sh" "./bin/typescript-angular-petstore-all.sh" +"./bin/typescript-aurelia-petstore.sh" "./bin/typescript-axios-petstore-all.sh" "./bin/typescript-fetch-petstore-all.sh" "./bin/typescript-node-petstore-all.sh" diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java index a926369c1b4..64ab80cb594 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java @@ -22,6 +22,7 @@ import io.swagger.v3.parser.util.SchemaTypeUtil; import org.openapitools.codegen.*; import org.openapitools.codegen.utils.ModelUtils; import org.openapitools.codegen.utils.SemVer; +import org.openapitools.codegen.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -512,7 +513,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode if (name.length() == 0) { return "DefaultService"; } - return initialCaps(name) + serviceSuffix; + return StringUtils.camelize(name) + serviceSuffix; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAureliaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAureliaClientCodegen.java index 85842606983..70dc269ec89 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAureliaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAureliaClientCodegen.java @@ -18,6 +18,7 @@ package org.openapitools.codegen.languages; import org.openapitools.codegen.*; +import org.openapitools.codegen.utils.StringUtils; import java.util.*; @@ -104,7 +105,7 @@ public class TypeScriptAureliaClientCodegen extends AbstractTypeScriptClientCode List operationList = (List) operations.get("operation"); for (CodegenOperation op : operationList) { // Aurelia uses "asGet", "asPost", ... methods; change the method format - op.httpMethod = initialCaps(op.httpMethod.toLowerCase(Locale.ROOT)); + op.httpMethod = StringUtils.camelize(op.httpMethod.toLowerCase(Locale.ROOT)); // Collect models to be imported for (CodegenParameter param : op.allParams) { diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java index 77d30502052..bc8bc0dc270 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptInversifyClientCodegen.java @@ -23,6 +23,7 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.parser.util.SchemaTypeUtil; import org.openapitools.codegen.*; import org.openapitools.codegen.utils.ModelUtils; +import org.openapitools.codegen.utils.StringUtils; import java.io.File; import java.text.SimpleDateFormat; @@ -321,7 +322,7 @@ public class TypeScriptInversifyClientCodegen extends AbstractTypeScriptClientCo if (name.length() == 0) { return "DefaultService"; } - return initialCaps(name) + "Service"; + return StringUtils.camelize(name) + "Service"; } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java index bdd007d41bb..a794c5a7abc 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptNodeClientCodegen.java @@ -21,6 +21,7 @@ import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.parser.util.SchemaTypeUtil; import org.openapitools.codegen.*; import org.openapitools.codegen.utils.ModelUtils; +import org.openapitools.codegen.utils.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,7 +99,7 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen if (name.length() == 0) { return "Default" + apiSuffix; } - return initialCaps(name) + apiSuffix; + return StringUtils.camelize(name) + apiSuffix; } @Override diff --git a/modules/openapi-generator/src/main/resources/typescript-aurelia/README.md b/modules/openapi-generator/src/main/resources/typescript-aurelia/README.md index ac1da15ab05..39a6c22b2e2 100644 --- a/modules/openapi-generator/src/main/resources/typescript-aurelia/README.md +++ b/modules/openapi-generator/src/main/resources/typescript-aurelia/README.md @@ -18,11 +18,13 @@ 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 #### -`openapi-generator` 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`. +To build and compile the typescript sources to javascript use: +``` +npm install +npm run build +``` #### 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). diff --git a/modules/openapi-generator/src/main/resources/typescript-aurelia/package.json.mustache b/modules/openapi-generator/src/main/resources/typescript-aurelia/package.json.mustache index 05aec69d7ec..ff7515308fe 100644 --- a/modules/openapi-generator/src/main/resources/typescript-aurelia/package.json.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-aurelia/package.json.mustache @@ -1,21 +1,23 @@ { - "name": "{{#npmName}}{{{npmName}}}{{/npmName}}{{^npmName}}typescript-fetch-api{{/npmName}}", + "name": "{{#npmName}}{{{npmName}}}{{/npmName}}{{^npmName}}typescript-aurelia-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", + "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" + {{/supportsES6}}"isomorphic-fetch": "^2.2.1", + "aurelia-framework": "^1.3.1", + "aurelia-http-client": "^1.3.0" }, - "scripts" : { - "prepublish" : "typings install && tsc", - "test": "tslint api.ts" + "scripts": { + "build": "tsc --outDir dist/", + "prepare": "npm run build", + "test": "tslint Api.ts" }, "devDependencies": { "tslint": "^3.15.1", - "typescript": "^1.8.10", - "typings": "^1.0.4" + "typescript": "^2.4 || ^3.0" } } diff --git a/modules/openapi-generator/src/main/resources/typescript-aurelia/tsconfig.json.mustache b/modules/openapi-generator/src/main/resources/typescript-aurelia/tsconfig.json.mustache index f835df82f1e..e70bfe9e377 100644 --- a/modules/openapi-generator/src/main/resources/typescript-aurelia/tsconfig.json.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-aurelia/tsconfig.json.mustache @@ -6,9 +6,14 @@ "noImplicitAny": true, "outDir": "dist", "rootDir": ".", + "lib": [ + "es6", + "dom" + ], "typeRoots": [ "node_modules/@types" - ] + ], + "experimentalDecorators": true }, "exclude": [ "dist", diff --git a/samples/client/petstore/typescript-aurelia/default/README.md b/samples/client/petstore/typescript-aurelia/default/README.md index ac1da15ab05..39a6c22b2e2 100644 --- a/samples/client/petstore/typescript-aurelia/default/README.md +++ b/samples/client/petstore/typescript-aurelia/default/README.md @@ -18,11 +18,13 @@ 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 #### -`openapi-generator` 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`. +To build and compile the typescript sources to javascript use: +``` +npm install +npm run build +``` #### 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). diff --git a/samples/client/petstore/typescript-aurelia/default/package.json b/samples/client/petstore/typescript-aurelia/default/package.json index 0204e3c39c9..74fcdb9b884 100644 --- a/samples/client/petstore/typescript-aurelia/default/package.json +++ b/samples/client/petstore/typescript-aurelia/default/package.json @@ -1,21 +1,23 @@ { - "name": "typescript-fetch-api", + "name": "typescript-aurelia-api", "version": "0.0.0", "license": "Unlicense", - "main": "./dist/api.js", - "browser": "./dist/api.js", - "typings": "./dist/api.d.ts", + "main": "./dist/Api.js", + "browser": "./dist/Api.js", + "typings": "./dist/Api.d.ts", "dependencies": { "core-js": "^2.4.0", - "isomorphic-fetch": "^2.2.1" + "isomorphic-fetch": "^2.2.1", + "aurelia-framework": "^1.3.1", + "aurelia-http-client": "^1.3.0" }, - "scripts" : { - "prepublish" : "typings install && tsc", - "test": "tslint api.ts" + "scripts": { + "build": "tsc --outDir dist/", + "prepare": "npm run build", + "test": "tslint Api.ts" }, "devDependencies": { "tslint": "^3.15.1", - "typescript": "^1.8.10", - "typings": "^1.0.4" + "typescript": "^2.4 || ^3.0" } } diff --git a/samples/client/petstore/typescript-aurelia/default/tsconfig.json b/samples/client/petstore/typescript-aurelia/default/tsconfig.json index 1a36def5fe7..d8ad15e7115 100644 --- a/samples/client/petstore/typescript-aurelia/default/tsconfig.json +++ b/samples/client/petstore/typescript-aurelia/default/tsconfig.json @@ -5,7 +5,15 @@ "module": "commonjs", "noImplicitAny": true, "outDir": "dist", - "rootDir": "." + "rootDir": ".", + "lib": [ + "es6", + "dom" + ], + "typeRoots": [ + "node_modules/@types" + ], + "experimentalDecorators": true }, "exclude": [ "dist",