Skip to content

Commit ba7adcc

Browse files
macjohnnywing328
authored andcommitted
[TypeScript][Angular] fix date path parameters (#7476, #7302) (#7479)
* #7476, #7302: [TypeScript][Angular] fix date path parameters, fix path parameters with :.+ in it * #7476, #7302: [TypeScript][Angular] fix date path parameters, fix path parameters with :.+ in it * #7476, #7302: [TypeScript][Angular] fix date path parameters, fix path parameters with :.+ in it * #7476: generate samples * code cleanup * #7476: improve variable description * #7302: revert character skipping, since it will now have the same parameter name in the method signature and in the api path * #7302: generate samples
1 parent 77fd35f commit ba7adcc

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,20 @@ public Map<String, Object> postProcessOperations(Map<String, Object> operations)
291291
insideCurly--;
292292

293293
// Add the more complicated component instead of just the brace.
294+
CodegenParameter parameter = findPathParameterByName(op, parameterName.toString());
294295
pathBuffer.append(toVarName(parameterName.toString()));
296+
if (parameter != null && parameter.isDateTime) {
297+
pathBuffer.append(".toISOString()");
298+
}
295299
pathBuffer.append("))}");
296300
parameterName.setLength(0);
297301
break;
298302
default:
303+
char nextChar = op.path.charAt(i);
299304
if (insideCurly > 0) {
300-
parameterName.append(op.path.charAt(i));
305+
parameterName.append(nextChar);
301306
} else {
302-
pathBuffer.append(op.path.charAt(i));
307+
pathBuffer.append(nextChar);
303308
}
304309
break;
305310
}
@@ -319,6 +324,21 @@ public Map<String, Object> postProcessOperations(Map<String, Object> operations)
319324
return operations;
320325
}
321326

327+
/**
328+
* Finds and returns a path parameter of an operation by its name
329+
* @param operation
330+
* @param parameterName
331+
* @return
332+
*/
333+
private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) {
334+
for(CodegenParameter param : operation.pathParams) {
335+
if (param.baseName.equals(parameterName)) {
336+
return param;
337+
}
338+
}
339+
return null;
340+
}
341+
322342
@Override
323343
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
324344
Map<String, Object> result = super.postProcessModels(objs);

samples/client/petstore/typescript-angular-v2/with-interfaces/README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## @
1+
## @swagger/angular2-typescript-petstore@0.0.1
22

33
### Building
44

@@ -19,7 +19,7 @@ Navigate to the folder of your consuming project and run one of next commands.
1919
_published:_
2020

2121
```
22-
npm install @ --save
22+
npm install @swagger/[email protected] --save
2323
```
2424

2525
_without publishing (not recommended):_
@@ -37,7 +37,7 @@ npm link
3737

3838
In your project:
3939
```
40-
npm link
40+
npm link @swagger/[email protected]
4141
```
4242

4343
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
@@ -52,7 +52,7 @@ In your Angular project:
5252

5353
```
5454
// without configuring providers
55-
import { ApiModule } from '';
55+
import { ApiModule } from '@swagger/angular2-typescript-petstore';
5656
5757
import { HttpModule } from '@angular/http';
5858
@@ -70,7 +70,7 @@ export class AppModule {}
7070

7171
```
7272
// configuring providers
73-
import { ApiModule, Configuration, ConfigurationParameters } from '';
73+
import { ApiModule, Configuration, ConfigurationParameters } from '@swagger/angular2-typescript-petstore';
7474
7575
export function apiConfigFactory (): Configuration => {
7676
const params: ConfigurationParameters = {
@@ -89,7 +89,7 @@ export class AppModule {}
8989
```
9090

9191
```
92-
import { DefaultApi } from '';
92+
import { DefaultApi } from '@swagger/angular2-typescript-petstore';
9393
9494
export class AppComponent {
9595
constructor(private apiGateway: DefaultApi) { }
@@ -126,7 +126,7 @@ export class AppModule {
126126
If different than the generated base path, during app bootstrap, you can provide the base path to your service.
127127

128128
```
129-
import { BASE_PATH } from '';
129+
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
130130
131131
bootstrap(AppComponent, [
132132
{ provide: BASE_PATH, useValue: 'https://your-web-service.com' },
@@ -135,7 +135,7 @@ bootstrap(AppComponent, [
135135
or
136136

137137
```
138-
import { BASE_PATH } from '';
138+
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
139139
140140
@NgModule({
141141
imports: [],
@@ -159,7 +159,7 @@ export const environment = {
159159

160160
In the src/app/app.module.ts:
161161
```
162-
import { BASE_PATH } from '';
162+
import { BASE_PATH } from '@swagger/angular2-typescript-petstore';
163163
import { environment } from '../environments/environment';
164164
165165
@NgModule({

0 commit comments

Comments
 (0)