[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_VERSION = "npmVersion";
public static final String NPM_REPOSITORY = "npmRepository"; public static final String NPM_REPOSITORY = "npmRepository";
public static final String SNAPSHOT = "snapshot"; 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 npmName = null;
protected String npmVersion = "1.0.0"; protected String npmVersion = "1.0.0";
protected String npmRepository = null; protected String npmRepository = null;
protected String injectionToken = "InjectionToken<string>";
public TypeScriptAngular2ClientCodegen() { public TypeScriptAngular2ClientCodegen() {
super(); 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_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(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(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 @Override
@ -79,6 +83,11 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
if(additionalProperties.containsKey(NPM_NAME)) { if(additionalProperties.containsKey(NPM_NAME)) {
addNpmPackageGeneration(); 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() { private void addNpmPackageGeneration() {
@ -234,4 +243,8 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod
public void setNpmRepository(String npmRepository) { public void setNpmRepository(String npmRepository) {
this.npmRepository = 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 = { export const COLLECTION_FORMATS = {
'csv': ',', 'csv': ',',
'tsv': ' ', 'tsv': ' ',

View File

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

View File

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

View File

@ -3,4 +3,5 @@ export class Configuration {
username: string; username: string;
password: string; password: string;
accessToken: string | (() => 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 = { export const COLLECTION_FORMATS = {
'csv': ',', 'csv': ',',
'tsv': ' ', 'tsv': ' ',

View File

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

View File

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

View File

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

View File

@ -1,6 +1,6 @@
{ {
"name": "@swagger/angular2-typescript-petstore", "name": "@swagger/angular2-typescript-petstore",
"version": "0.0.1-SNAPSHOT.201704272137", "version": "0.0.1",
"description": "swagger client for @swagger/angular2-typescript-petstore", "description": "swagger client for @swagger/angular2-typescript-petstore",
"author": "Swagger Codegen Contributors", "author": "Swagger Codegen Contributors",
"keywords": [ "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 = { export const COLLECTION_FORMATS = {
'csv': ',', 'csv': ',',
'tsv': ' ', 'tsv': ' ',