diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index cab99599846..fefbf143b0c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -1,6 +1,7 @@ package io.swagger.codegen.languages; import java.io.File; +import java.lang.StringBuffer; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; @@ -82,7 +83,7 @@ public void processOpts() { supportingFiles.add(new SupportingFile("apis.mustache", apiPackage().replace('.', File.separatorChar), "api.ts")); supportingFiles.add(new SupportingFile("index.mustache", getIndexDirectory(), "index.ts")); supportingFiles.add(new SupportingFile("api.module.mustache", getIndexDirectory(), "api.module.ts")); - supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts")); + supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts")); supportingFiles.add(new SupportingFile("configuration.mustache", getIndexDirectory(), "configuration.ts")); supportingFiles.add(new SupportingFile("variables.mustache", getIndexDirectory(), "variables.ts")); supportingFiles.add(new SupportingFile("encoder.mustache", getIndexDirectory(), "encoder.ts")); @@ -149,7 +150,7 @@ private String getIndexDirectory() { public boolean isDataTypeFile(final String dataType) { return dataType != null && dataType.equals("Blob"); } - + @Override public String getTypeDeclaration(Property p) { Property inner; @@ -247,8 +248,54 @@ public Map postProcessOperations(Map operations) } } - // Convert path to TypeScript template string, applying URI encoding - op.path = op.path.replaceAll("\\{(.*?)\\}", "\\$\\{encodeURIComponent(String($1))\\}"); + // Prep a string buffer where we're going to set up our new version of the string. + StringBuffer pathBuffer = new StringBuffer(); + + // Set up other variables for tracking the current state of the string. + int insideCurly = 0; + boolean foundUnderscore = false; + + // Iterate through existing string, one character at a time. + for(int i = 0; i < op.path.length(); i++) { + switch(op.path.charAt(i)) { + case '{': + // We entered curly braces, so track that. + insideCurly++; + + // Add the more complicated component instead of just the brace. + pathBuffer.append("${encodeURIComponent(String("); + break; + case '}': + // We exited curly braces, so track that. + insideCurly--; + + // Add the more complicated component instead of just the brace. + pathBuffer.append("))}"); + break; + case '_': + // If we're inside the curly brace, the following character will need to be uppercase. + // Otherwise, just add the character. + if (insideCurly > 0) { + foundUnderscore = true; + } else { + pathBuffer.append(op.path.charAt(i)); + } + break; + default: + // If we previously found an underscore, we need an uppercase letter. + // Otherwise, just add the character. + if (foundUnderscore) { + pathBuffer.append(Character.toUpperCase(op.path.charAt(i))); + foundUnderscore = false; + } else { + pathBuffer.append(op.path.charAt(i)); + } + break; + } + } + + // Overwrite path to TypeScript template string, after applying everything we just did. + op.path = pathBuffer.toString(); } // Add additional filename information for model imports in the services @@ -272,7 +319,7 @@ public Map postProcessModels(Map objs) { CodegenModel cm = (CodegenModel) mo.get("model"); mo.put("tsImports", toTsImports(cm,cm.imports)); } - + return result; } diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts index 3af781cf580..e79fabe8c8c 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts @@ -23,3 +23,5 @@ export interface ApiResponse { message?: string; } + + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts index d09f8d7b265..56608731f95 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts @@ -21,3 +21,5 @@ export interface Category { name?: string; } + + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts index 402a86689c8..84b59f1b09a 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts @@ -33,9 +33,7 @@ export interface Order { } export namespace Order { - export enum StatusEnum { - Placed = 'placed', - Approved = 'approved', - Delivered = 'delivered' - } + export type StatusEnum = 'placed' | 'approved' | 'delivered'; } + + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts index 0d6137d02cf..c0fc942934c 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts @@ -35,9 +35,7 @@ export interface Pet { } export namespace Pet { - export enum StatusEnum { - Available = 'available', - Pending = 'pending', - Sold = 'sold' - } + export type StatusEnum = 'available' | 'pending' | 'sold'; } + + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts index 3ed1eeff8f3..dbfa473f538 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts @@ -21,3 +21,5 @@ export interface Tag { name?: string; } + + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts index f4914ae2608..4dfad607c51 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts @@ -36,3 +36,5 @@ export interface User { userStatus?: number; } + +