[typescript-angular2] change OpaqueToken to InjectionToken<string> (Issue #5565) (#5569)

* change OpaqueToken to InjectionToken<string> and add useOpaqueToken option for typescript-angular2 (#5565)

* run security shell
This commit is contained in:
Takuro Wada 2017-05-08 19:08:54 +09:00 committed by wing328
parent adb213bc00
commit a81cff0ed0
12 changed files with 38 additions and 23 deletions

View File

@ -26,10 +26,13 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
public static final String NPM_VERSION = "npmVersion";
public static final String NPM_REPOSITORY = "npmRepository";
public static final String SNAPSHOT = "snapshot";
public static final String USE_OPAQUE_TOKEN = "useOpaqueToken";
public static final String INJECTION_TOKEN = "injectionToken";
protected String npmName = null;
protected String npmVersion = "1.0.0";
protected String npmRepository = null;
protected String injectionToken = "InjectionToken<string>";
public TypeScriptAngular2ClientCodegen() {
super();
@ -47,6 +50,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
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()));
this.cliOptions.add(new CliOption(USE_OPAQUE_TOKEN, "When setting this property to true, OpaqueToken is used instead of InjectionToken", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString()));
}
@Override
@ -79,6 +83,11 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
if(additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration();
}
if(additionalProperties.containsKey(USE_OPAQUE_TOKEN) && Boolean.valueOf(additionalProperties.get(USE_OPAQUE_TOKEN).toString())) {
this.setOpaqueToken();
}
additionalProperties.put(INJECTION_TOKEN, this.injectionToken);
}
private void addNpmPackageGeneration() {
@ -234,4 +243,8 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
public void setNpmRepository(String npmRepository) {
this.npmRepository = npmRepository;
}
public void setOpaqueToken() {
this.injectionToken = "OpaqueToken";
}
}

View File

@ -1,6 +1,6 @@
import { OpaqueToken } from '@angular/core';
import { {{{injectionToken}}} } from '@angular/core';
export const BASE_PATH = new OpaqueToken('basePath');
export const BASE_PATH = new {{{injectionToken}}}('basePath');
export const COLLECTION_FORMATS = {
'csv': ',',
'tsv': ' ',

View File

@ -35,6 +35,7 @@ public class TypeScriptAngular2ClientOptionsProvider implements OptionsProvider
.put(TypeScriptAngular2ClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
.put(TypeScriptAngular2ClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
.put(TypeScriptAngular2ClientCodegen.USE_OPAQUE_TOKEN, Boolean.FALSE.toString())
.build();
}

View File

@ -91,9 +91,9 @@ export class FakeApi {
method: RequestMethod.Put,
headers: headers,
body: formParams.toString(),
search: queryParameters
search: queryParameters,
withCredentials:this.configuration.withCredentials
});
// https://github.com/swagger-api/swagger-codegen/issues/4037
if (extraHttpRequestParams) {
requestOptions = (<any>Object).assign(requestOptions, extraHttpRequestParams);

View File

@ -3,4 +3,5 @@ export class Configuration {
username: string;
password: string;
accessToken: string | (() => string);
withCredentials: boolean;
}

View File

@ -1,6 +1,6 @@
import { OpaqueToken } from '@angular/core';
import { InjectionToken<string> } from '@angular/core';
export const BASE_PATH = new OpaqueToken('basePath');
export const BASE_PATH = new InjectionToken<string>('basePath');
export const COLLECTION_FORMATS = {
'csv': ',',
'tsv': ' ',

View File

@ -396,6 +396,11 @@ export class PetApi {
'application/xml'
];
// authentication (api_key) required
if (this.configuration.apiKey) {
headers.set('api_key', this.configuration.apiKey);
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@ -405,11 +410,6 @@ export class PetApi {
headers.set('Authorization', 'Bearer ' + accessToken);
}
// authentication (api_key) required
if (this.configuration.apiKey) {
headers.set('api_key', this.configuration.apiKey);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,

View File

@ -1,6 +1,6 @@
import { OpaqueToken } from '@angular/core';
import { InjectionToken<string> } from '@angular/core';
export const BASE_PATH = new OpaqueToken('basePath');
export const BASE_PATH = new InjectionToken<string>('basePath');
export const COLLECTION_FORMATS = {
'csv': ',',
'tsv': ' ',

View File

@ -1,4 +1,4 @@
## @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201704272137
## @swagger/angular2-typescript-petstore@0.0.1
### Building
@ -19,7 +19,7 @@ navigate to the folder of your consuming project and run one of next commando's.
_published:_
```
npm install @swagger/angular2-typescript-petstore@0.0.1-SNAPSHOT.201704272137 --save
npm install @swagger/angular2-typescript-petstore@0.0.1 --save
```
_unPublished (not recommended):_

View File

@ -396,6 +396,11 @@ export class PetApi {
'application/xml'
];
// authentication (api_key) required
if (this.configuration.apiKey) {
headers.set('api_key', this.configuration.apiKey);
}
// authentication (petstore_auth) required
// oauth required
if (this.configuration.accessToken) {
@ -405,11 +410,6 @@ export class PetApi {
headers.set('Authorization', 'Bearer ' + accessToken);
}
// authentication (api_key) required
if (this.configuration.apiKey) {
headers.set('api_key', this.configuration.apiKey);
}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: RequestMethod.Get,
headers: headers,

View File

@ -1,6 +1,6 @@
{
"name": "@swagger/angular2-typescript-petstore",
"version": "0.0.1-SNAPSHOT.201704272137",
"version": "0.0.1",
"description": "swagger client for @swagger/angular2-typescript-petstore",
"author": "Swagger Codegen Contributors",
"keywords": [

View File

@ -1,6 +1,6 @@
import { OpaqueToken } from '@angular/core';
import { InjectionToken<string> } from '@angular/core';
export const BASE_PATH = new OpaqueToken('basePath');
export const BASE_PATH = new InjectionToken<string>('basePath');
export const COLLECTION_FORMATS = {
'csv': ',',
'tsv': ' ',